Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        public PartialValidation(IConsensusRules consensusRules, ILoggerFactory loggerFactory)
        {
            this.consensusRules = consensusRules;
            this.logger         = loggerFactory.CreateLogger(this.GetType().FullName);

            this.asyncQueue = new AsyncQueue <PartialValidationItem>(this.OnEnqueueAsync);
        }
Ejemplo n.º 3
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>();
        }
        /// <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;
        }
Ejemplo n.º 5
0
 public PowTestBlockDefinition(
     IConsensusLoop consensusLoop,
     IDateTimeProvider dateTimeProvider,
     ILoggerFactory loggerFactory,
     ITxMempool mempool,
     MempoolSchedulerLock mempoolLock,
     Network network,
     IConsensusRules consensusRules,
     BlockDefinitionOptions options = null)
     : base(consensusLoop, dateTimeProvider, loggerFactory, mempool, mempoolLock, network, consensusRules)
 {
     this.block = this.BlockTemplate.Block;
 }
Ejemplo n.º 6
0
 public PowBlockDefinition(
     IConsensusLoop consensusLoop,
     IDateTimeProvider dateTimeProvider,
     ILoggerFactory loggerFactory,
     ITxMempool mempool,
     MempoolSchedulerLock mempoolLock,
     Network network,
     IConsensusRules consensusRules,
     BlockDefinitionOptions options = null)
     : base(consensusLoop, dateTimeProvider, loggerFactory, mempool, mempoolLock, network)
 {
     this.consensusRules = consensusRules;
     this.logger         = loggerFactory.CreateLogger(this.GetType().FullName);
 }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
 public SmartContractMempoolValidator(ITxMempool memPool, MempoolSchedulerLock mempoolLock, IDateTimeProvider dateTimeProvider, MempoolSettings mempoolSettings, ConcurrentChain chain, ICoinView coinView, ILoggerFactory loggerFactory, NodeSettings nodeSettings, IConsensusRules consensusRules)
     : base(memPool, mempoolLock, dateTimeProvider, mempoolSettings, chain, coinView, loggerFactory, nodeSettings, consensusRules)
 {
 }
        /// <summary>
        /// Creates a proof of work block assembler.
        /// </summary>
        /// <param name="consensusLoop">Consensus loop.</param>
        /// <param name="consensusRules"></param>
        /// <param name="dateTimeProvider">Date and time provider.</param>
        /// <param name="mempool">Memory pool for transactions.</param>
        /// <param name="mempoolLock">Async lock for memory pool.</param>
        /// <param name="network">Network running on.</param>
        /// <returns>Proof of work block assembler.</returns>
        private static PowBlockDefinition CreatePowBlockAssembler(IConsensusLoop consensusLoop, IConsensusRules consensusRules, IDateTimeProvider dateTimeProvider, LoggerFactory loggerFactory, TxMempool mempool, MempoolSchedulerLock mempoolLock, Network network)
        {
            var options = new BlockDefinitionOptions
            {
                BlockMaxWeight = network.Consensus.Option <PowConsensusOptions>().MaxBlockWeight,
                BlockMaxSize   = network.Consensus.Option <PowConsensusOptions>().MaxBlockSerializedSize
            };

            var blockMinFeeRate = new FeeRate(PowMining.DefaultBlockMinTxFee);

            options.BlockMinFeeRate = blockMinFeeRate;

            return(new PowBlockDefinition(consensusLoop, dateTimeProvider, loggerFactory, mempool, mempoolLock, network, consensusRules, options));
        }
 public ReflectionVirtualMachineFeature(IConsensusRules consensusRules, ILoggerFactory loggerFactory)
 {
     this.consensusRules = consensusRules;
     this.logger         = loggerFactory.CreateLogger(this.GetType().FullName);
 }
Ejemplo n.º 11
0
 public IntegrityValidator(IConsensusRules consensusRules, ILoggerFactory loggerFactory)
 {
     this.consensusRules = consensusRules;
     this.logger         = loggerFactory.CreateLogger(this.GetType().FullName);
 }
Ejemplo n.º 12
0
        public SmartContractMempoolValidator(ITxMempool memPool, MempoolSchedulerLock mempoolLock, IDateTimeProvider dateTimeProvider, MempoolSettings mempoolSettings, ConcurrentChain chain, ICoinView coinView, ILoggerFactory loggerFactory, NodeSettings nodeSettings, IConsensusRules consensusRules)
            : base(memPool, mempoolLock, dateTimeProvider, mempoolSettings, chain, coinView, loggerFactory, nodeSettings, consensusRules)
        {
            var p2pkhRule = new P2PKHNotContractRule();

            p2pkhRule.Parent = (ConsensusRules)consensusRules;
            p2pkhRule.Initialize();

            this.preTxRules = new List <ISmartContractMempoolRule>
            {
                new MempoolOpSpendRule(),
                new TxOutSmartContractExecRule(),
                p2pkhRule
            };

            this.feeTxRules = new List <ISmartContractMempoolRule>()
            {
                new SmartContractFormatRule(),
            };
        }