public MempoolManager(MempoolScheduler mempoolScheduler, TxMempool memPool,
                       MempoolValidator validator, MempoolOrphans orphans, IDateTimeProvider dateTimeProvider, NodeSettings nodeArgs, IMempoolPersistence mempoolPersistence)
 {
     this.MempoolScheduler   = mempoolScheduler;
     this.memPool            = memPool;
     this.DateTimeProvider   = dateTimeProvider;
     this.NodeArgs           = nodeArgs;
     this.Orphans            = orphans;
     this.Validator          = validator;
     this.mempoolPersistence = mempoolPersistence;
 }
        public MempoolBehavior(MempoolValidator validator, MempoolManager manager, MempoolOrphans orphans,
                               ConnectionManager connectionManager, BlockStore.ChainBehavior.ChainState chainState)
        {
            this.validator         = validator;
            this.manager           = manager;
            this.orphans           = orphans;
            this.connectionManager = connectionManager;
            this.chainState        = chainState;

            this.inventoryTxToSend    = new Dictionary <uint256, uint256>();
            this.filterInventoryKnown = new Dictionary <uint256, uint256>();
        }
        public Task <bool> AddOrphanTx(ulong nodeId, Transaction tx)
        {
            return(this.MempoolScheduler.WriteAsync(() =>
            {
                var hash = tx.GetHash();
                if (this.mapOrphanTransactions.ContainsKey(hash))
                {
                    return false;
                }

                // Ignore big transactions, to avoid a
                // send-big-orphans memory exhaustion attack. If a peer has a legitimate
                // large transaction with a missing parent then we assume
                // it will rebroadcast it later, after the parent transaction(s)
                // have been mined or received.
                // 100 orphans, each of which is at most 99,999 bytes big is
                // at most 10 megabytes of orphans and somewhat more byprev index (in the worst case):
                var sz = MempoolValidator.GetTransactionWeight(tx, this.Validator.ConsensusOptions);
                if (sz >= this.consensusValidator.ConsensusOptions.MAX_STANDARD_TX_WEIGHT)
                {
                    Logging.Logs.Mempool.LogInformation($"ignoring large orphan tx (size: {sz}, hash: {hash})");
                    return false;
                }

                var orphan = new OrphanTx
                {
                    Tx = tx,
                    NodeId = nodeId,
                    TimeExpire = this.dateTimeProvider.GetTime() + ORPHAN_TX_EXPIRE_TIME
                };
                if (this.mapOrphanTransactions.TryAdd(hash, orphan))
                {
                    foreach (var txin in tx.Inputs)
                    {
                        var prv = this.mapOrphanTransactionsByPrev.TryGet(txin.PrevOut);
                        if (prv == null)
                        {
                            prv = new List <OrphanTx>();
                            this.mapOrphanTransactionsByPrev.Add(txin.PrevOut, prv);
                        }
                        prv.Add(orphan);
                    }
                }

                var orphanSize = this.mapOrphanTransactions.Count;
                Logging.Logs.Mempool.LogInformation(
                    $"stored orphan tx {hash} (mapsz {orphanSize} outsz {this.mapOrphanTransactionsByPrev.Count})");
                this.Validator.PerformanceCounter.SetMempoolOrphanSize(orphanSize);

                return true;
            }));
        }
        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;
        }
Example #5
0
 public MempoolCoinView(CoinView inner, TxMempool memPool, AsyncLock mempoolScheduler, MempoolValidator mempoolValidator)
 {
     this.Inner            = inner;
     this.memPool          = memPool;
     this.mempoolScheduler = mempoolScheduler;
     this.mempoolValidator = mempoolValidator;
     this.Set = new UnspentOutputSet();
 }