コード例 #1
0
 public PosBlockAssembler(ConsensusLoop consensusLoop, Network network, ConcurrentChain chain,
                          MempoolScheduler mempoolScheduler, TxMempool mempool,
                          IDateTimeProvider dateTimeProvider, StakeChain stakeChain, AssemblerOptions options = null)
     : base(consensusLoop, network, chain, mempoolScheduler, mempool, dateTimeProvider, options)
 {
     this.stakeChain = stakeChain;
 }
コード例 #2
0
        public MempoolOrphans(
            MempoolScheduler mempoolScheduler,
            TxMempool memPool,
            ConcurrentChain chain,
            Signals.Signals signals,
            IMempoolValidator validator,
            PowConsensusValidator consensusValidator,
            CoinView coinView,
            IDateTimeProvider dateTimeProvider,
            NodeSettings nodeArgs,
            ILoggerFactory loggerFactory)
        {
            this.MempoolScheduler   = mempoolScheduler;
            this.memPool            = memPool;
            this.chain              = chain;
            this.signals            = signals;
            this.consensusValidator = consensusValidator;
            this.coinView           = coinView;
            this.dateTimeProvider   = dateTimeProvider;
            this.nodeArgs           = nodeArgs;
            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);
        }
コード例 #3
0
 public MempoolManager(MempoolScheduler mempoolScheduler, TxMempool memPool,
                       MempoolValidator validator, MempoolOrphans orphans, IDateTimeProvider dateTimeProvider, NodeSettings nodeArgs)
 {
     this.MempoolScheduler = mempoolScheduler;
     this.memPool          = memPool;
     this.DateTimeProvider = dateTimeProvider;
     this.NodeArgs         = nodeArgs;
     this.Orphans          = orphans;
     this.Validator        = validator;
 }
コード例 #4
0
 public BlockAssemblerFactory(ConsensusLoop consensusLoop, Network network, ConcurrentChain chain,
                              MempoolScheduler mempoolScheduler, TxMempool mempool,
                              IDateTimeProvider dateTimeProvider)
 {
     this.consensusLoop    = consensusLoop;
     this.network          = network;
     this.chain            = chain;
     this.mempoolScheduler = mempoolScheduler;
     this.mempool          = mempool;
     this.dateTimeProvider = dateTimeProvider;
 }
コード例 #5
0
        public MempoolValidator(TxMempool memPool, MempoolScheduler mempoolScheduler,
                                PowConsensusValidator consensusValidator, IDateTimeProvider dateTimeProvider, NodeSettings nodeArgs,
                                ConcurrentChain chain, CoinView coinView)
        {
            this.memPool            = memPool;
            this.mempoolScheduler   = mempoolScheduler;
            this.consensusValidator = consensusValidator;
            this.dateTimeProvider   = dateTimeProvider;
            this.nodeArgs           = nodeArgs;
            this.chain    = chain;
            this.coinView = coinView;

            freeLimiter             = new FreeLimiterSection();
            this.PerformanceCounter = new MempoolPerformanceCounter();
        }
コード例 #6
0
        public MempoolOrphans(MempoolScheduler mempoolScheduler, TxMempool memPool, ConcurrentChain chain,
                              MempoolValidator validator, CoinView coinView, IDateTimeProvider dateTimeProvider, NodeSettings nodeArgs)
        {
            this.MempoolScheduler = mempoolScheduler;
            this.memPool          = memPool;
            this.chain            = chain;
            this.coinView         = coinView;
            this.dateTimeProvider = dateTimeProvider;
            this.nodeArgs         = nodeArgs;
            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;
        }
コード例 #7
0
        private static MempoolManager CreateTestMempool(NodeSettings settings, out TxMempool txMemPool)
        {
            IDateTimeProvider dateTimeProvider = DateTimeProvider.Default;

            txMemPool = new TxMempool(new FeeRate(1000), dateTimeProvider, new BlockPolicyEstimator(new FeeRate(1000), NodeSettings.Default(), new LoggerFactory()), new LoggerFactory());
            var mempoolScheduler   = new MempoolScheduler();
            var coins              = new InMemoryCoinView(settings.Network.GenesisHash);
            var chain              = new ConcurrentChain(Network.Main.GetGenesis().Header);
            var mempoolPersistence = new MempoolPersistence(settings, new LoggerFactory());

            NBitcoin.Network.Main.Consensus.Options = new PosConsensusOptions();
            var consensusValidator = new PowConsensusValidator(NBitcoin.Network.Main);
            var mempoolValidator   = new MempoolValidator(txMemPool, mempoolScheduler, consensusValidator, dateTimeProvider, settings, chain, coins, new LoggerFactory());
            var mempoolOrphans     = new MempoolOrphans(mempoolScheduler, txMemPool, chain, new Bitcoin.Signals.Signals(), mempoolValidator, consensusValidator, coins, dateTimeProvider, settings, new LoggerFactory());

            return(new MempoolManager(mempoolScheduler, txMemPool, mempoolValidator, mempoolOrphans, dateTimeProvider, settings, mempoolPersistence, new LoggerFactory()));
        }
コード例 #8
0
        public PowBlockAssembler(
            ConsensusLoop consensusLoop,
            Network network,
            ConcurrentChain chain,
            MempoolScheduler mempoolScheduler,
            TxMempool mempool,
            IDateTimeProvider dateTimeProvider,
            ILogger logger,
            AssemblerOptions options = null)
        {
            options = options ?? new AssemblerOptions();
            this.blockMinFeeRate = options.BlockMinFeeRate;
            // Limit weight to between 4K and MAX_BLOCK_WEIGHT-4K for sanity:
            this.blockMaxWeight = (uint)Math.Max(4000, Math.Min(PowMining.DefaultBlockMaxWeight - 4000, options.BlockMaxWeight));
            // Limit size to between 1K and MAX_BLOCK_SERIALIZED_SIZE-1K for sanity:
            this.blockMaxSize = (uint)Math.Max(1000, Math.Min(network.Consensus.Option <PowConsensusOptions>().MAX_BLOCK_SERIALIZED_SIZE - 1000, options.BlockMaxSize));
            // Whether we need to account for byte usage (in addition to weight usage)
            this.needSizeAccounting = (this.blockMaxSize < network.Consensus.Option <PowConsensusOptions>().MAX_BLOCK_SERIALIZED_SIZE - 1000);

            this.consensusLoop    = consensusLoop;
            this.chain            = chain;
            this.mempoolScheduler = mempoolScheduler;
            this.mempool          = mempool;
            this.dateTimeProvider = dateTimeProvider;
            this.logger           = logger;
            this.options          = options;
            this.network          = network;

            this.inBlock = new TxMempool.SetEntries();

            // Reserve space for coinbase tx
            this.blockSize       = 1000;
            this.blockWeight     = 4000;
            this.blockSigOpsCost = 400;
            this.fIncludeWitness = false;

            // These counters do not include coinbase tx
            this.blockTx = 0;
            this.fees    = 0;

            this.pblocktemplate = new BlockTemplate {
                Block = new Block(), VTxFees = new List <Money>()
            };
        }
コード例 #9
0
 public MempoolManager(
     MempoolScheduler mempoolScheduler,
     TxMempool memPool,
     IMempoolValidator validator,
     MempoolOrphans orphans,
     IDateTimeProvider dateTimeProvider,
     NodeSettings nodeArgs,
     IMempoolPersistence mempoolPersistence,
     ILoggerFactory loggerFactory)
 {
     this.MempoolScheduler   = mempoolScheduler;
     this.memPool            = memPool;
     this.DateTimeProvider   = dateTimeProvider;
     this.NodeArgs           = nodeArgs;
     this.Orphans            = orphans;
     this.Validator          = validator;
     this.mempoolPersistence = mempoolPersistence;
     this.mempoolLogger      = loggerFactory.CreateLogger(this.GetType().FullName);
 }
コード例 #10
0
 public PosAssemblerFactory(
     ConsensusLoop consensusLoop,
     Network network,
     ConcurrentChain chain,
     MempoolScheduler mempoolScheduler,
     TxMempool mempool,
     IDateTimeProvider dateTimeProvider,
     ILoggerFactory loggerFactory,
     StakeChain stakeChain = null)
 {
     this.consensusLoop    = consensusLoop;
     this.network          = network;
     this.chain            = chain;
     this.mempoolScheduler = mempoolScheduler;
     this.mempool          = mempool;
     this.dateTimeProvider = dateTimeProvider;
     this.stakeChain       = stakeChain;
     this.logger           = loggerFactory.CreateLogger(this.GetType().FullName);
 }
コード例 #11
0
 public MempoolValidator(
     TxMempool memPool,
     MempoolScheduler mempoolScheduler,
     PowConsensusValidator consensusValidator,
     IDateTimeProvider dateTimeProvider,
     NodeSettings nodeArgs,
     ConcurrentChain chain,
     CoinView coinView,
     ILoggerFactory loggerFactory)
 {
     this.memPool            = memPool;
     this.mempoolScheduler   = mempoolScheduler;
     this.consensusValidator = consensusValidator;
     this.dateTimeProvider   = dateTimeProvider;
     this.nodeArgs           = nodeArgs;
     this.chain              = chain;
     this.coinView           = coinView;
     this.logger             = loggerFactory.CreateLogger(this.GetType().FullName);
     this.freeLimiter        = new FreeLimiterSection();
     this.PerformanceCounter = new MempoolPerformanceCounter();
 }
コード例 #12
0
            public TestContext()
            {
                this.blockinfo = new List <Blockinfo>();
                var lst = blockinfoarr.Cast <long>().ToList();

                for (int i = 0; i < lst.Count; i += 2)
                {
                    this.blockinfo.Add(new Blockinfo()
                    {
                        extranonce = (int)lst[i], nonce = (uint)lst[i + 1]
                    });
                }

                // Note that by default, these tests run with size accounting enabled.
                this.network = Network.Main;
                var hex = Encoders.Hex.DecodeData("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f");

                this.scriptPubKey = new Script(new[] { Op.GetPushOp(hex), OpcodeType.OP_CHECKSIG });
                this.newBlock     = new BlockTemplate();

                this.entry = new TestMemPoolEntryHelper();
                this.chain = new ConcurrentChain(network);
                this.network.Consensus.Options = new PowConsensusOptions();
                this.cachedCoinView            = new CachedCoinView(new InMemoryCoinView(chain.Tip.HashBlock));
                this.consensus = new ConsensusLoop(new PowConsensusValidator(network), chain, cachedCoinView, new LookaheadBlockPuller(chain, new ConnectionManager(network, new NodeConnectionParameters(), new NodeSettings(), new LoggerFactory()), new LoggerFactory()), new NodeDeployments(this.network));
                this.consensus.Initialize();

                this.entry.Fee(11);
                this.entry.Height(11);
                var date1 = new MemoryPoolTests.DateTimeProviderSet();

                date1.time     = DateTimeProvider.Default.GetTime();
                date1.timeutc  = DateTimeProvider.Default.GetUtcNow();
                this.date      = date1;
                this.mempool   = new TxMempool(new FeeRate(1000), DateTimeProvider.Default, new BlockPolicyEstimator(new FeeRate(1000), NodeSettings.Default(), new LoggerFactory()), new LoggerFactory());;
                this.scheduler = new MempoolScheduler();

                // Simple block creation, nothing special yet:
                this.newBlock = AssemblerForTest(this).CreateNewBlock(this.scriptPubKey);
                this.chain.SetTip(this.newBlock.Block.Header);
                this.consensus.AcceptBlock(new ContextInformation(new BlockResult {
                    Block = this.newBlock.Block
                }, this.network.Consensus)
                {
                    CheckPow = false, CheckMerkleRoot = false
                });

                // We can't make transactions until we have inputs
                // Therefore, load 100 blocks :)
                this.baseheight = 0;
                List <Block> blocks = new List <Block>();

                this.txFirst = new List <Transaction>();
                for (int i = 0; i < this.blockinfo.Count; ++i)
                {
                    var pblock = this.newBlock.Block.Clone();                     // pointer for convenience
                    pblock.Header.HashPrevBlock = this.chain.Tip.HashBlock;
                    pblock.Header.Version       = 1;
                    pblock.Header.Time          = Utils.DateTimeToUnixTime(this.chain.Tip.GetMedianTimePast()) + 1;
                    Transaction txCoinbase = pblock.Transactions[0].Clone();
                    txCoinbase.Inputs.Clear();
                    txCoinbase.Version = 1;
                    txCoinbase.AddInput(new TxIn(new Script(new[] { Op.GetPushOp(this.blockinfo[i].extranonce), Op.GetPushOp(this.chain.Height) })));
                    // Ignore the (optional) segwit commitment added by CreateNewBlock (as the hardcoded nonces don't account for this)
                    txCoinbase.AddOutput(new TxOut(Money.Zero, new Script()));
                    pblock.Transactions[0] = txCoinbase;

                    if (this.txFirst.Count == 0)
                    {
                        this.baseheight = this.chain.Height;
                    }
                    if (this.txFirst.Count < 4)
                    {
                        this.txFirst.Add(pblock.Transactions[0]);
                    }
                    pblock.UpdateMerkleRoot();

                    pblock.Header.Nonce = this.blockinfo[i].nonce;

                    this.chain.SetTip(pblock.Header);
                    this.consensus.AcceptBlock(new ContextInformation(new BlockResult {
                        Block = pblock
                    }, this.network.Consensus)
                    {
                        CheckPow = false, CheckMerkleRoot = false
                    });
                    blocks.Add(pblock);
                }

                // Just to make sure we can still make simple blocks
                this.newBlock = AssemblerForTest(this).CreateNewBlock(this.scriptPubKey);
                Assert.NotNull(this.newBlock);
            }