Esempio n. 1
0
        public ConsensusManager(
            Network network,
            ILoggerFactory loggerFactory,
            IChainState chainState,
            IBlockValidator blockValidator,
            ICheckpoints checkpoints,
            ConsensusSettings consensusSettings,
            IBlockPuller blockPuller,
            IConsensusRules consensusRules,
            IFinalizedBlockHeight finalizedBlockHeight,
            IConnectionManager connectionManager,
            IBlockStore blockStore = null)
        {
            this.network           = network;
            this.chainState        = chainState;
            this.blockValidator    = blockValidator;
            this.consensusSettings = consensusSettings;
            this.blockPuller       = blockPuller;
            this.consensusRules    = consensusRules;
            this.connectionManager = connectionManager;
            this.blockStore        = blockStore;
            this.logger            = loggerFactory.CreateLogger(this.GetType().FullName);

            this.chainedHeaderTree = new ChainedHeaderTree(network, loggerFactory, blockValidator, checkpoints, chainState, finalizedBlockHeight, consensusSettings);

            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.toDownloadQueue = new Queue <BlockDownloadRequest>();
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the object.
        /// </summary>
        /// <param name="nodeSettings">User defined node settings.</param>
        /// <param name="dataFolder">Locations of important folders and files on disk.</param>
        /// <param name="nodeLifetime">Global application life cycle control - triggers when application shuts down.</param>
        /// <param name="chain">Thread safe access to the best chain of block headers (that the node is aware of) from genesis.</param>
        /// <param name="chainState">Information about node's chain.</param>
        /// <param name="connectionManager">Manager of node's network connections.</param>
        /// <param name="finalizedBlockHeight"><inheritdoc cref="IFinalizedBlockHeight"/></param>
        /// <param name="chainRepository">Access to the database of blocks.</param>
        /// <param name="dateTimeProvider">Provider of time functions.</param>
        /// <param name="asyncLoopFactory">Factory for creating background async loop tasks.</param>
        /// <param name="timeSyncBehaviorState">State of time synchronization feature that stores collected data samples.</param>
        /// <param name="dbreezeSerializer">Provider of binary (de)serialization for data stored in the database.</param>
        /// <param name="loggerFactory">Factory to be used to create logger for the node.</param>
        /// <param name="initialBlockDownloadState">Provider of IBD state.</param>
        /// <param name="bestChainSelector">Selects the best available chain based on tips provided by the peers and switches to it.</param>
        public BaseFeature(
            NodeSettings nodeSettings,
            DataFolder dataFolder,
            INodeLifetime nodeLifetime,
            ConcurrentChain chain,
            IChainState chainState,
            IConnectionManager connectionManager,
            IChainRepository chainRepository,
            IFinalizedBlockHeight finalizedBlockHeight,
            IDateTimeProvider dateTimeProvider,
            IAsyncLoopFactory asyncLoopFactory,
            ITimeSyncBehaviorState timeSyncBehaviorState,
            DBreezeSerializer dbreezeSerializer,
            ILoggerFactory loggerFactory,
            IInitialBlockDownloadState initialBlockDownloadState,
            IPeerBanning peerBanning,
            IPeerAddressManager peerAddressManager,
            BestChainSelector bestChainSelector)
        {
            this.chainState           = Guard.NotNull(chainState, nameof(chainState));
            this.chainRepository      = Guard.NotNull(chainRepository, nameof(chainRepository));
            this.finalizedBlockHeight = Guard.NotNull(finalizedBlockHeight, nameof(finalizedBlockHeight));
            this.nodeSettings         = Guard.NotNull(nodeSettings, nameof(nodeSettings));
            this.dataFolder           = Guard.NotNull(dataFolder, nameof(dataFolder));
            this.nodeLifetime         = Guard.NotNull(nodeLifetime, nameof(nodeLifetime));
            this.chain             = Guard.NotNull(chain, nameof(chain));
            this.connectionManager = Guard.NotNull(connectionManager, nameof(connectionManager));
            this.bestChainSelector = bestChainSelector;
            this.peerBanning       = Guard.NotNull(peerBanning, nameof(peerBanning));

            this.peerAddressManager = Guard.NotNull(peerAddressManager, nameof(peerAddressManager));
            this.peerAddressManager.PeerFilePath = this.dataFolder;

            this.initialBlockDownloadState = initialBlockDownloadState;
            this.dateTimeProvider          = dateTimeProvider;
            this.asyncLoopFactory          = asyncLoopFactory;
            this.timeSyncBehaviorState     = timeSyncBehaviorState;
            this.loggerFactory             = loggerFactory;
            this.dbreezeSerializer         = dbreezeSerializer;
            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
            this.disposableResources = new List <IDisposable>();
        }