public void Given_SyncActionIsCalled_When_HeightNotOnChain_Then_ABadRequestErrorIsReturned() { // Set up var chain = new Mock <ChainIndexer>(); chain.Setup(c => c.GetHeader(15)).Returns((ChainedHeader)null); ConsensusManager consensusManager = ConsensusManagerHelper.CreateConsensusManager(this.network); var loggerFactory = new Mock <LoggerFactory>(); var signals = new Signals.Signals(loggerFactory.Object, null); var nodeLifetime = new NodeLifetime(); var asyncProvider = new AsyncProvider(loggerFactory.Object, signals, nodeLifetime); var blockNotification = new Mock <BlockNotification>(this.LoggerFactory.Object, chain.Object, consensusManager, signals, asyncProvider, nodeLifetime); // Act var notificationController = new NotificationsController(blockNotification.Object, chain.Object); // Assert IActionResult result = notificationController.SyncFrom("15"); var errorResult = Assert.IsType <ErrorResult>(result); var errorResponse = Assert.IsType <ErrorResponse>(errorResult.Value); Assert.Single(errorResponse.Errors); ErrorModel error = errorResponse.Errors[0]; Assert.Equal(400, error.Status); }
public BlockStoreFeature( ConcurrentChain chain, IConnectionManager connectionManager, Signals.Signals signals, IBlockRepository blockRepository, IBlockStoreCache blockStoreCache, StoreBlockPuller blockPuller, BlockStoreLoop blockStoreLoop, BlockStoreManager blockStoreManager, BlockStoreSignaled blockStoreSignaled, INodeLifetime nodeLifetime, NodeSettings nodeSettings, ILoggerFactory loggerFactory, StoreSettings storeSettings, string name = "BlockStore") { this.name = name; this.chain = chain; this.signals = signals; this.blockRepository = blockRepository; this.blockStoreCache = blockStoreCache; this.blockPuller = blockPuller; this.blockStoreLoop = blockStoreLoop; this.blockStoreManager = blockStoreManager; this.blockStoreSignaled = blockStoreSignaled; this.nodeLifetime = nodeLifetime; this.connectionManager = connectionManager; this.nodeSettings = nodeSettings; this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.loggerFactory = loggerFactory; storeSettings.Load(nodeSettings); this.storeSettings = storeSettings; }
/// <summary> /// Initializes a new instance of the <see cref="WalletFeature"/> class. /// </summary> /// <param name="walletSyncManager">The synchronization manager for the wallet, tasked with keeping the wallet synced with the network.</param> /// <param name="walletManager">The wallet manager.</param> /// <param name="addressBookManager">The address book manager.</param> /// <param name="signals">The signals responsible for receiving blocks and transactions from the network.</param> /// <param name="chain">The chain of blocks.</param> /// <param name="connectionManager">The connection manager.</param> /// <param name="broadcasterBehavior">The broadcaster behavior.</param> /// <param name="nodeSettings">The settings for the node.</param> /// <param name="walletSettings">The settings for the wallet.</param> public WalletFeature( IWalletSyncManager walletSyncManager, IWalletManager walletManager, IAddressBookManager addressBookManager, Signals.Signals signals, ConcurrentChain chain, IConnectionManager connectionManager, BroadcasterBehavior broadcasterBehavior, NodeSettings nodeSettings, WalletSettings walletSettings, INodeStats nodeStats) { this.walletSyncManager = walletSyncManager; this.walletManager = walletManager; this.addressBookManager = addressBookManager; this.signals = signals; this.chain = chain; this.connectionManager = connectionManager; this.broadcasterBehavior = broadcasterBehavior; this.nodeSettings = nodeSettings; this.walletSettings = walletSettings; nodeStats.RegisterStats(this.AddComponentStats, StatsType.Component); nodeStats.RegisterStats(this.AddInlineStats, StatsType.Inline, 800); }
public void Given_SyncActionIsCalled_When_ABlockHashIsSpecified_Then_TheChainIsSyncedFromTheHash() { // Set up int heightLocation = 480946; var header = this.network.Consensus.ConsensusFactory.CreateBlockHeader(); uint256 hash = header.GetHash(); string hashLocation = hash.ToString(); var chainedHeader = new ChainedHeader(this.network.Consensus.ConsensusFactory.CreateBlockHeader(), hash, null); var chain = new Mock <ChainIndexer>(); chain.Setup(c => c.GetHeader(uint256.Parse(hashLocation))).Returns(chainedHeader); ConsensusManager consensusManager = ConsensusManagerHelper.CreateConsensusManager(this.network); var loggerFactory = new Mock <LoggerFactory>(); var signals = new Signals.Signals(loggerFactory.Object, null); var nodeLifetime = new NodeLifetime(); var asyncProvider = new AsyncProvider(loggerFactory.Object, signals, nodeLifetime); var blockNotification = new Mock <BlockNotification>(this.LoggerFactory.Object, chain.Object, consensusManager, signals, asyncProvider, nodeLifetime); // Act var notificationController = new NotificationsController(blockNotification.Object, chain.Object); IActionResult result = notificationController.SyncFrom(hashLocation); // Assert chain.Verify(c => c.GetHeader(heightLocation), Times.Never); blockNotification.Verify(b => b.SyncFrom(hash), Times.Once); }
public ConsensusFeature( DBreezeCoinView dBreezeCoinView, Network network, PowConsensusValidator consensusValidator, ConcurrentChain chain, LookaheadBlockPuller blockPuller, CoinView coinView, ChainState chainState, IConnectionManager connectionManager, INodeLifetime nodeLifetime, Signals.Signals signals, ConsensusLoop consensusLoop, NodeSettings nodeSettings, NodeDeployments nodeDeployments, ILoggerFactory loggerFactory, StakeChainStore stakeChain = null) { this.dBreezeCoinView = dBreezeCoinView; this.consensusValidator = consensusValidator; this.chain = chain; this.blockPuller = blockPuller; this.coinView = coinView; this.chainState = chainState; this.connectionManager = connectionManager; this.nodeLifetime = nodeLifetime; this.signals = signals; this.network = network; this.consensusLoop = consensusLoop; this.nodeSettings = nodeSettings; this.nodeDeployments = nodeDeployments; this.stakeChain = stakeChain; this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.loggerFactory = loggerFactory; }
/// <summary> /// Constructs a memory pool orphan manager object. /// </summary> /// <param name="mempoolLock">A lock for managing asynchronous access to memory pool.</param> /// <param name="memPool">Transaction memory pool for managing transactions in the memory pool.</param> /// <param name="chain">Chain of block headers.</param> /// <param name="signals">Node notifications available to subscribe to.</param> /// <param name="validator">Memory pool validator for validating transactions.</param> /// <param name="consensusValidator">Proof of work consensus validator used for validating orphan transactions.</param> /// <param name="coinView">Coin view of the memory pool.</param> /// <param name="dateTimeProvider">Date and time information provider.</param> /// <param name="mempoolSettings">Settings from the memory pool.</param> /// <param name="loggerFactory">Factory for creating instance logger for this object.</param> public MempoolOrphans( MempoolAsyncLock mempoolLock, TxMempool memPool, ConcurrentChain chain, Signals.Signals signals, IMempoolValidator validator, PowConsensusValidator consensusValidator, CoinView coinView, IDateTimeProvider dateTimeProvider, MempoolSettings mempoolSettings, ILoggerFactory loggerFactory) { this.MempoolLock = mempoolLock; this.memPool = memPool; this.chain = chain; this.signals = signals; this.consensusValidator = consensusValidator; this.coinView = coinView; this.dateTimeProvider = dateTimeProvider; this.mempoolSettings = mempoolSettings; this.Validator = validator; this.mapOrphanTransactions = new Dictionary <uint256, OrphanTx>(); this.mapOrphanTransactionsByPrev = new Dictionary <OutPoint, List <OrphanTx> >(); // OutPoint already correctly implements equality compare this.recentRejects = new Dictionary <uint256, uint256>(); this.hashRecentRejectsChainTip = uint256.Zero; this.mempoolLogger = loggerFactory.CreateLogger(this.GetType().FullName); }
public MempoolBehavior( IMempoolValidator validator, MempoolManager mempoolManager, MempoolOrphans orphans, IConnectionManager connectionManager, IInitialBlockDownloadState initialBlockDownloadState, Signals.Signals signals, ILoggerFactory loggerFactory, Network network) { this.validator = validator; this.mempoolManager = mempoolManager; this.orphans = orphans; this.connectionManager = connectionManager; this.initialBlockDownloadState = initialBlockDownloadState; this.signals = signals; this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.loggerFactory = loggerFactory; this.network = network; this.lockObject = new object(); this.inventoryTxToSend = new HashSet <uint256>(); this.filterInventoryKnown = new HashSet <uint256>(); this.isPeerWhitelistedForRelay = false; this.isBlocksOnlyMode = false; }
public void OnNextCore_WhenTransactionsMissingInLongestChain_ReturnsThemToTheMempool() { var mempoolValidatorMock = new Mock <IMempoolValidator>(); var mempoolMock = new Mock <ITxMempool>(); var loggerFactoryMock = new Mock <ILoggerFactory>(); loggerFactoryMock.Setup(i => i.CreateLogger(It.IsAny <string>())).Returns(new Mock <ILogger>().Object); Signals.Signals signals = new Signals.Signals(loggerFactoryMock.Object, null); var subject = new BlocksDisconnectedSignaled(mempoolMock.Object, mempoolValidatorMock.Object, new MempoolSchedulerLock(), loggerFactoryMock.Object, signals); subject.Initialize(); var block = new Block(); var genesisChainedHeaderBlock = new ChainedHeaderBlock(block, ChainedHeadersHelper.CreateGenesisChainedHeader()); var transaction1 = new Transaction(); var transaction2 = new Transaction(); block.Transactions = new List <Transaction> { transaction1, transaction2 }; signals.Publish(new BlockDisconnected(genesisChainedHeaderBlock)); mempoolValidatorMock.Verify(x => x.AcceptToMemoryPool(It.IsAny <MempoolValidationState>(), transaction1)); mempoolValidatorMock.Verify(x => x.AcceptToMemoryPool(It.IsAny <MempoolValidationState>(), transaction2)); }
public PowMining( ConsensusLoop consensusLoop, ConcurrentChain chain, Network network, IDateTimeProvider dateTimeProvider, AssemblerFactory blockAssemblerFactory, IBlockRepository blockRepository, ChainState chainState, Signals.Signals signals, INodeLifetime nodeLifetime, IAsyncLoopFactory asyncLoopFactory, ILoggerFactory loggerFactory) { this.consensusLoop = consensusLoop; this.chain = chain; this.network = network; this.dateTimeProvider = dateTimeProvider; this.blockAssemblerFactory = blockAssemblerFactory; this.blockRepository = blockRepository; this.chainState = chainState; this.signals = signals; this.nodeLifetime = nodeLifetime; this.asyncLoopFactory = asyncLoopFactory; this.logger = loggerFactory.CreateLogger(this.GetType().FullName); }
public MempoolOrphans( ConcurrentChain chain, Signals.Signals signals, IMempoolValidator validator, ICoinView coinView, IDateTimeProvider dateTimeProvider, MempoolSettings mempoolSettings, ILoggerFactory loggerFactory, MempoolManager mempoolManager) { this.chain = chain; this.signals = signals; this.coinView = coinView; this.dateTimeProvider = dateTimeProvider; this.mempoolSettings = mempoolSettings; this.mempoolManager = mempoolManager; this.Validator = validator; this.mapOrphanTransactions = new Dictionary <uint256, OrphanTx>(); this.mapOrphanTransactionsByPrev = new Dictionary <OutPoint, List <OrphanTx> >(); // OutPoint already correctly implements equality compare this.recentRejects = new Dictionary <uint256, uint256>(); this.hashRecentRejectsChainTip = uint256.Zero; this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.lockObject = new object(); }
public ConsensusFeature( DBreezeCoinView dBreezeCoinView, Network network, LookaheadBlockPuller blockPuller, CoinView coinView, ChainState chainState, IConnectionManager connectionManager, Signals.Signals signals, ConsensusLoop consensusLoop, NodeDeployments nodeDeployments, ILoggerFactory loggerFactory, ConsensusStats consensusStats, ConsensusSettings consensusSettings, IRuleRegistration ruleRegistration, IConsensusRules consensusRules, StakeChainStore stakeChain = null) { this.dBreezeCoinView = dBreezeCoinView; this.blockPuller = blockPuller; this.coinView = coinView; this.chainState = chainState; this.connectionManager = connectionManager; this.signals = signals; this.network = network; this.consensusLoop = consensusLoop; this.nodeDeployments = nodeDeployments; this.stakeChain = stakeChain; this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.loggerFactory = loggerFactory; this.consensusStats = consensusStats; this.ruleRegistration = ruleRegistration; this.consensusRules = consensusRules; this.chainState.MaxReorgLength = this.network.Consensus.Option <PowConsensusOptions>().MaxReorgLength; }
public void Given_SyncActionIsCalled_When_ANonExistingBlockHashIsSpecified_Then_ABadRequestErrorIsReturned() { // Set up string hashLocation = "000000000000000000c03dbe6ee5fedb25877a12e32aa95bc1d3bd480d7a93f9"; var chain = new Mock <ChainIndexer>(); chain.Setup(c => c.GetHeader(uint256.Parse(hashLocation))).Returns((ChainedHeader)null); ConsensusManager consensusManager = ConsensusManagerHelper.CreateConsensusManager(this.network); var loggerFactory = new Mock <LoggerFactory>(); var signals = new Signals.Signals(loggerFactory.Object, null); var nodeLifetime = new NodeLifetime(); var asyncProvider = new AsyncProvider(loggerFactory.Object, signals, nodeLifetime); var blockNotification = new Mock <BlockNotification>(this.LoggerFactory.Object, chain.Object, consensusManager, signals, asyncProvider, nodeLifetime); // Act var notificationController = new NotificationsController(blockNotification.Object, chain.Object); // Assert IActionResult result = notificationController.SyncFrom(hashLocation); var errorResult = Assert.IsType <ErrorResult>(result); var errorResponse = Assert.IsType <ErrorResponse>(errorResult.Value); Assert.Single(errorResponse.Errors); ErrorModel error = errorResponse.Errors[0]; Assert.Equal(400, error.Status); }
public PosConsensusFeature( Network network, IChainState chainState, IConnectionManager connectionManager, IConsensusManager consensusManager, NodeDeployments nodeDeployments, ConcurrentChain chain, IInitialBlockDownloadState initialBlockDownloadState, IPeerBanning peerBanning, Signals.Signals signals, ILoggerFactory loggerFactory, ICheckpoints checkpoints, IProvenBlockHeaderStore provenBlockHeaderStore, ConnectionManagerSettings connectionManagerSettings) : base(network, chainState, connectionManager, signals, consensusManager, nodeDeployments) { this.network = network; this.chainState = chainState; this.connectionManager = connectionManager; this.consensusManager = consensusManager; this.nodeDeployments = nodeDeployments; this.chain = chain; this.initialBlockDownloadState = initialBlockDownloadState; this.peerBanning = peerBanning; this.loggerFactory = loggerFactory; this.checkpoints = checkpoints; this.provenBlockHeaderStore = provenBlockHeaderStore; this.connectionManagerSettings = connectionManagerSettings; this.chainState.MaxReorgLength = network.Consensus.MaxReorgLength; }
public GenerateCoinsFastDateTimeProvider(Signals.Signals signals) { this.adjustedTimeOffset = TimeSpan.Zero; this.startFrom = new DateTime(2018, 1, 1); signals.SubscribeForBlocks(this); }
/// <summary> /// Initializes a new instance of the <see cref="ColdStakingFeature"/> class. /// </summary> /// <param name="walletSyncManager">The synchronization manager for the wallet, tasked with keeping the wallet synced with the network.</param> /// <param name="walletManager">The wallet manager.</param> /// <param name="addressBookManager">The address book manager.</param> /// <param name="signals">The signals responsible for receiving blocks and transactions from the network.</param> /// <param name="chain">The chain of blocks.</param> /// <param name="connectionManager">The connection manager.</param> /// <param name="broadcasterBehavior">The broadcaster behavior.</param> /// <param name="nodeSettings">The settings for the node.</param> /// <param name="walletSettings">The settings for the wallet.</param> /// <param name="loggerFactory">The factory used to create instance loggers.</param> /// <param name="nodeStats">The node stats object used to register node stats.</param> public ColdStakingFeature( IWalletSyncManager walletSyncManager, IWalletManager walletManager, IAddressBookManager addressBookManager, Signals.Signals signals, ConcurrentChain chain, IConnectionManager connectionManager, BroadcasterBehavior broadcasterBehavior, NodeSettings nodeSettings, WalletSettings walletSettings, ILoggerFactory loggerFactory, INodeStats nodeStats) { Guard.NotNull(walletManager, nameof(walletManager)); Guard.NotNull(loggerFactory, nameof(loggerFactory)); this.coldStakingManager = walletManager as ColdStakingManager; Guard.NotNull(this.coldStakingManager, nameof(this.coldStakingManager)); this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.loggerFactory = loggerFactory; this.walletSyncManager = walletSyncManager; this.addressBookManager = addressBookManager; this.signals = signals; this.chain = chain; this.connectionManager = connectionManager; this.broadcasterBehavior = broadcasterBehavior; this.nodeSettings = nodeSettings; this.walletSettings = walletSettings; nodeStats.RegisterStats(this.AddComponentStats, StatsType.Component); nodeStats.RegisterStats(this.AddInlineStats, StatsType.Inline, 800); }
public BlockStoreFeature( Network network, ConcurrentChain chain, IConnectionManager connectionManager, Signals.Signals signals, BlockStoreSignaled blockStoreSignaled, ILoggerFactory loggerFactory, StoreSettings storeSettings, IChainState chainState, IBlockStoreQueue blockStoreQueue, INodeStats nodeStats, IConsensusManager consensusManager, ICheckpoints checkpoints) { this.network = network; this.chain = chain; this.blockStoreQueue = blockStoreQueue; this.signals = signals; this.blockStoreSignaled = blockStoreSignaled; this.connectionManager = connectionManager; this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.loggerFactory = loggerFactory; this.storeSettings = storeSettings; this.chainState = chainState; this.consensusManager = consensusManager; this.checkpoints = checkpoints; nodeStats.RegisterStats(this.AddInlineStats, StatsType.Inline, 900); }
public WalletFeature(IWalletSyncManager walletSyncManager, IWalletManager walletManager, Signals.Signals signals, ConcurrentChain chain) { this.walletSyncManager = walletSyncManager; this.walletManager = walletManager; this.signals = signals; this.chain = chain; }
/// <summary> /// Initialize a new instance of <see cref="ConsensusLoop"/>. /// </summary> /// <param name="asyncLoopFactory">The async loop we need to wait upon before we can shut down this feature.</param> /// <param name="validator">The validation logic for the consensus rules.</param> /// <param name="nodeLifetime">Contain information about the life time of the node, its used on startup and shutdown.</param> /// <param name="chain">A chain of headers all the way to genesis.</param> /// <param name="utxoSet">The consensus db, containing all unspent UTXO in the chain.</param> /// <param name="puller">A puller that can pull blocks from peers on demand.</param> /// <param name="nodeDeployments">Contain information about deployment and activation of features in the chain.</param> /// <param name="loggerFactory">A factory to provide logger instances.</param> /// <param name="chainState">Holds state related to the block chain.</param> /// <param name="connectionManager">Connection manager of all the currently connected peers.</param> /// <param name="dateTimeProvider">Provider of time functions.</param> /// <param name="signals">A signaler that used to signal messages between features.</param> /// <param name="checkpoints">Provider of block header hash checkpoints.</param> /// <param name="consensusSettings">Consensus settings for the full node.</param> /// <param name="nodeSettings">Settings for the full node.</param> /// <param name="peerBanning">Handles the banning of peers.</param> /// <param name="consensusRules">The consensus rules to validate.</param> /// <param name="stakeChain">Information holding POS data chained.</param> public ConsensusLoop( IAsyncLoopFactory asyncLoopFactory, PowConsensusValidator validator, INodeLifetime nodeLifetime, ConcurrentChain chain, CoinView utxoSet, LookaheadBlockPuller puller, NodeDeployments nodeDeployments, ILoggerFactory loggerFactory, ChainState chainState, IConnectionManager connectionManager, IDateTimeProvider dateTimeProvider, Signals.Signals signals, ICheckpoints checkpoints, ConsensusSettings consensusSettings, NodeSettings nodeSettings, IPeerBanning peerBanning, IConsensusRules consensusRules, StakeChain stakeChain = null) { Guard.NotNull(asyncLoopFactory, nameof(asyncLoopFactory)); Guard.NotNull(validator, nameof(validator)); Guard.NotNull(nodeLifetime, nameof(nodeLifetime)); Guard.NotNull(chain, nameof(chain)); Guard.NotNull(utxoSet, nameof(utxoSet)); Guard.NotNull(puller, nameof(puller)); Guard.NotNull(nodeDeployments, nameof(nodeDeployments)); Guard.NotNull(connectionManager, nameof(connectionManager)); Guard.NotNull(chainState, nameof(chainState)); Guard.NotNull(signals, nameof(signals)); Guard.NotNull(consensusSettings, nameof(consensusSettings)); Guard.NotNull(nodeSettings, nameof(nodeSettings)); Guard.NotNull(peerBanning, nameof(peerBanning)); Guard.NotNull(consensusRules, nameof(consensusRules)); this.consensusLock = new AsyncLock(); this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.asyncLoopFactory = asyncLoopFactory; this.Validator = validator; this.nodeLifetime = nodeLifetime; this.chainState = chainState; this.connectionManager = connectionManager; this.signals = signals; this.Chain = chain; this.UTXOSet = utxoSet; this.Puller = puller; this.NodeDeployments = nodeDeployments; this.checkpoints = checkpoints; this.dateTimeProvider = dateTimeProvider; this.consensusSettings = consensusSettings; this.nodeSettings = nodeSettings; this.peerBanning = peerBanning; this.consensusRules = consensusRules; // chain of stake info can be null if POS is not enabled this.StakeChain = stakeChain; }
protected IAsyncProvider CreateAsyncProvider() { var loggerFactory = new ExtendedLoggerFactory(); var signals = new Signals.Signals(loggerFactory, null); var nodeLifetime = new NodeLifetime(); var asyncProvider = new AsyncProvider(loggerFactory, signals, nodeLifetime); return(asyncProvider); }
/// <summary> /// Constructs and instance of memory pool behavior. /// Constructs a logger instance for memory pool behavior object. /// </summary> /// <param name="validator">Memory pool validator for validating transactions.</param> /// <param name="manager">Memory pool manager for managing the memory pool.</param> /// <param name="orphans">Memory pool orphans for managing orphan transactions.</param> /// <param name="connectionManager">Connection manager for managing node connections.</param> /// <param name="chainState">Current block chain state.</param> /// <param name="signals">Node notifications available to subscribe to.</param> /// <param name="loggerFactory">Logger factory for creating logger.</param> public MempoolBehavior( IMempoolValidator validator, MempoolManager manager, MempoolOrphans orphans, IConnectionManager connectionManager, ChainState chainState, Signals.Signals signals, ILoggerFactory loggerFactory) : this(validator, manager, orphans, connectionManager, chainState, signals, loggerFactory.CreateLogger(typeof(MempoolBehavior).FullName)) { }
/// <summary> /// Constructs and instance of memory pool behavior. /// Constructs a logger instance for memory pool behavior object. /// </summary> /// <param name="validator">Memory pool validator for validating transactions.</param> /// <param name="manager">Memory pool manager for managing the memory pool.</param> /// <param name="orphans">Memory pool orphans for managing orphan transactions.</param> /// <param name="connectionManager">Connection manager for managing peer connections.</param> /// <param name="initialBlockDownloadState">Provider of IBD state.</param> /// <param name="signals">Peer notifications available to subscribe to.</param> /// <param name="loggerFactory">Logger factory for creating logger.</param> public MempoolBehavior( IMempoolValidator validator, MempoolManager manager, MempoolOrphans orphans, IConnectionManager connectionManager, IInitialBlockDownloadState initialBlockDownloadState, Signals.Signals signals, ILoggerFactory loggerFactory) : this(validator, manager, orphans, connectionManager, initialBlockDownloadState, signals, loggerFactory.CreateLogger(typeof(MempoolBehavior).FullName)) { }
/// <summary> /// Sets up the system under test. /// </summary> /// <param name="dateTimeProvider">The datetime provider injected to the constructor of the system under test.</param> /// <returns>The system under test.</returns> private TimeSyncBehaviorState CreateTimeSyncBehaviorState(IDateTimeProvider dateTimeProvider) { var lifetime = new NodeLifetime(); var loggerFactory = new LoggerFactory(); var signals = new Signals.Signals(loggerFactory, null); var asyncProvider = new AsyncProvider(loggerFactory, signals, lifetime); var state = new TimeSyncBehaviorState(dateTimeProvider, lifetime, asyncProvider, loggerFactory, KnownNetworks.Main); return(state); }
/// <summary> /// Initializes a new instance of the <see cref="WalletFeature"/> class. /// </summary> /// <param name="walletSyncManager">The synchronization manager for the wallet, tasked with keeping the wallet synced with the network.</param> /// <param name="walletManager">The wallet manager.</param> /// <param name="signals">The signals responsible for receiving blocks and transactions from the network.</param> /// <param name="chain">The chain of blocks.</param> /// <param name="connectionManager">The connection manager.</param> /// <param name="broadcasterBehavior">The broadcaster behavior.</param> public WalletFeature( IWalletSyncManager walletSyncManager, IWalletManager walletManager, Signals.Signals signals, ConcurrentChain chain, IConnectionManager connectionManager, BroadcasterBehavior broadcasterBehavior) { this.walletSyncManager = walletSyncManager; this.walletManager = walletManager; this.signals = signals; this.chain = chain; this.connectionManager = connectionManager; this.broadcasterBehavior = broadcasterBehavior; }
/// <summary> /// Constructs a memory pool feature. /// </summary> /// <param name="connectionManager">Connection manager for managing node connections.</param> /// <param name="signals">Node notifications available to subscribe to.</param> /// <param name="mempoolSignaled">Observes block signal notifications from signals.</param> /// <param name="mempoolBehavior">Memory pool node behavior for managing attached node messages.</param> /// <param name="mempoolManager">Memory pool manager for managing external access to memory pool.</param> /// <param name="loggerFactory">Logger factory for creating instance logger.</param> public MempoolFeature( IConnectionManager connectionManager, Signals.Signals signals, MempoolSignaled mempoolSignaled, MempoolBehavior mempoolBehavior, MempoolManager mempoolManager, ILoggerFactory loggerFactory) { this.signals = signals; this.connectionManager = connectionManager; this.mempoolSignaled = mempoolSignaled; this.mempoolBehavior = mempoolBehavior; this.mempoolManager = mempoolManager; this.mempoolLogger = loggerFactory.CreateLogger(this.GetType().FullName); }
public ConsensusManager( Network network, ILoggerFactory loggerFactory, IChainState chainState, IHeaderValidator headerValidator, IIntegrityValidator integrityValidator, IPartialValidation partialValidation, ICheckpoints checkpoints, ConsensusSettings consensusSettings, IConsensusRules consensusRules, IFinalizedBlockHeight finalizedBlockHeight, Signals.Signals signals, IPeerBanning peerBanning, NodeSettings nodeSettings, IDateTimeProvider dateTimeProvider, IInitialBlockDownloadState ibdState, ConcurrentChain chain, IBlockStore blockStore = null) { this.network = network; this.chainState = chainState; this.partialValidation = partialValidation; this.consensusSettings = consensusSettings; this.consensusRules = consensusRules; this.signals = signals; this.peerBanning = peerBanning; this.blockStore = blockStore; this.finalizedBlockHeight = finalizedBlockHeight; this.chain = chain; this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.chainedHeaderTree = new ChainedHeaderTree(network, loggerFactory, headerValidator, integrityValidator, checkpoints, chainState, finalizedBlockHeight, consensusSettings, signals); this.peerLock = new object(); this.reorgLock = new AsyncLock(); this.blockRequestedLock = new object(); this.expectedBlockDataBytes = 0; this.expectedBlockSizes = new Dictionary <uint256, long>(); this.callbacksByBlocksRequestedHash = new Dictionary <uint256, List <OnBlockDownloadedCallback> >(); this.peersByPeerId = new Dictionary <int, INetworkPeer>(); this.toDownloadQueue = new Queue <BlockDownloadRequest>(); this.ibdState = ibdState; ProtocolVersion protocolVersion = nodeSettings.ProtocolVersion; this.blockPuller = new BlockPuller(this.BlockDownloaded, this.chainState, protocolVersion, dateTimeProvider, loggerFactory); }
public ConsensusFeature( Network network, IChainState chainState, IConnectionManager connectionManager, Signals.Signals signals, IConsensusManager consensusManager, NodeDeployments nodeDeployments) { this.chainState = chainState; this.connectionManager = connectionManager; this.signals = signals; this.consensusManager = consensusManager; this.nodeDeployments = nodeDeployments; this.chainState.MaxReorgLength = network.Consensus.MaxReorgLength; }
/// <summary> /// Initializes a new instance of the <see cref="WalletFeature"/> class. /// </summary> /// <param name="broadcasterBehavior">The broadcaster behavior.</param> /// <param name="chain">The chain of blocks.</param> /// <param name="connectionManager">The connection manager.</param> /// <param name="signals">The signals responsible for receiving blocks and transactions from the network.</param> /// <param name="walletManager">The wallet manager.</param> /// <param name="walletSyncManager">The synchronization manager for the wallet, tasked with keeping the wallet synced with the network.</param> public SmartContractWalletFeature( BroadcasterBehavior broadcasterBehavior, ConcurrentChain chain, IConnectionManager connectionManager, ILoggerFactory loggerFactory, Signals.Signals signals, IWalletManager walletManager, IWalletSyncManager walletSyncManager) { this.broadcasterBehavior = broadcasterBehavior; this.chain = chain; this.connectionManager = connectionManager; this.signals = signals; this.logger = loggerFactory.CreateLogger(this.GetType().Name); this.walletManager = walletManager; this.walletSyncManager = walletSyncManager; }
public ConsensusFeature( IAsyncLoopFactory asyncLoopFactory, DBreezeCoinView dBreezeCoinView, Network network, PowConsensusValidator consensusValidator, ConcurrentChain chain, LookaheadBlockPuller blockPuller, CoinView coinView, ChainState chainState, IConnectionManager connectionManager, INodeLifetime nodeLifetime, Signals.Signals signals, ConsensusLoop consensusLoop, NodeSettings nodeSettings, NodeDeployments nodeDeployments, ILoggerFactory loggerFactory, IDateTimeProvider dateTimeProvider, ConsensusManager consensusManager, ConsensusStats consensusStats, ConsensusSettings consensusSettings, StakeChainStore stakeChain = null) { this.dBreezeCoinView = dBreezeCoinView; this.consensusValidator = consensusValidator; this.chain = chain; this.blockPuller = blockPuller; this.coinView = coinView; this.chainState = chainState; this.connectionManager = connectionManager; this.nodeLifetime = nodeLifetime; this.signals = signals; this.network = network; this.consensusLoop = consensusLoop; this.nodeSettings = nodeSettings; this.nodeDeployments = nodeDeployments; this.stakeChain = stakeChain; this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.loggerFactory = loggerFactory; this.dateTimeProvider = dateTimeProvider; this.consensusManager = consensusManager; this.consensusStats = consensusStats; this.consensusSettings = consensusSettings; this.chainState.MaxReorgLength = this.network.Consensus.Option <PowConsensusOptions>().MaxReorgLength; }
public void Given_SyncActionIsCalled_When_AnInvalidBlockHashIsSpecified_Then_AnExceptionIsThrown() { // Set up string hashLocation = "notAValidHash"; var chain = new Mock <ChainIndexer>(); ConsensusManager consensusManager = ConsensusManagerHelper.CreateConsensusManager(this.network); var loggerFactory = new Mock <LoggerFactory>(); var signals = new Signals.Signals(loggerFactory.Object, null); var nodeLifetime = new NodeLifetime(); var asyncProvider = new AsyncProvider(loggerFactory.Object, signals, nodeLifetime); var blockNotification = new Mock <BlockNotification>(this.LoggerFactory.Object, chain.Object, consensusManager, signals, asyncProvider, nodeLifetime); // Act var notificationController = new NotificationsController(blockNotification.Object, chain.Object); // Assert Assert.Throws <FormatException>(() => notificationController.SyncFrom(hashLocation)); }
public LightWalletSyncManager( ILoggerFactory loggerFactory, IWalletManager walletManager, ConcurrentChain chain, Network network, BlockNotification blockNotification, Signals.Signals signals, INodeLifetime nodeLifetime, IAsyncLoopFactory asyncLoopFactory) { this.walletManager = walletManager as WalletManager; this.chain = chain; this.signals = signals; this.blockNotification = blockNotification; this.coinType = (CoinType)network.Consensus.CoinType; this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.nodeLifetime = nodeLifetime; this.asyncLoopFactory = asyncLoopFactory; }