// Add descendants of given transactions to mapModifiedTx with ancestor // state updated assuming given transactions are inBlock. Returns number // of updated descendants. private int UpdatePackagesForAdded(TxMempool.SetEntries alreadyAdded, Dictionary <uint256, TxMemPoolModifiedEntry> mapModifiedTx) { int descendantsUpdated = 0; foreach (var setEntry in alreadyAdded) { TxMempool.SetEntries setEntries = new TxMempool.SetEntries(); this.mempoolScheduler.ReadAsync(() => this.mempool.CalculateDescendants(setEntry, setEntries)).GetAwaiter().GetResult(); foreach (var desc in setEntries) { if (alreadyAdded.Contains(desc)) { continue; } ++descendantsUpdated; TxMemPoolModifiedEntry modEntry; if (!mapModifiedTx.TryGetValue(desc.TransactionHash, out modEntry)) { modEntry = new TxMemPoolModifiedEntry(desc); mapModifiedTx.Add(desc.TransactionHash, modEntry); } modEntry.SizeWithAncestors -= setEntry.GetTxSize(); modEntry.ModFeesWithAncestors -= setEntry.ModifiedFee; modEntry.SigOpCostWithAncestors -= setEntry.SigOpCost; } } return(descendantsUpdated); }
/// <summary> /// Add descendants of given transactions to mapModifiedTx with ancestor /// state updated assuming given transactions are inBlock. Returns number /// of updated descendants. /// </summary> private int UpdatePackagesForAdded(TxMempool.SetEntries alreadyAdded, Dictionary <uint256, TxMemPoolModifiedEntry> mapModifiedTx) { int descendantsUpdated = 0; foreach (TxMempoolEntry addedEntry in alreadyAdded) { var setEntries = new TxMempool.SetEntries(); this.MempoolLock.ReadAsync(() => { if (!this.Mempool.MapTx.ContainsKey(addedEntry.TransactionHash)) { this.logger.LogWarning("{0} is not present in {1} any longer, skipping.", addedEntry.TransactionHash, nameof(this.Mempool.MapTx)); return; } this.Mempool.CalculateDescendants(addedEntry, setEntries); }).GetAwaiter().GetResult(); foreach (TxMempoolEntry desc in setEntries) { if (alreadyAdded.Contains(desc)) { continue; } descendantsUpdated++; TxMemPoolModifiedEntry modEntry; if (!mapModifiedTx.TryGetValue(desc.TransactionHash, out modEntry)) { modEntry = new TxMemPoolModifiedEntry(desc); mapModifiedTx.Add(desc.TransactionHash, modEntry); this.logger.LogDebug("Added transaction '{0}' to the block template because it's a required ancestor for '{1}'.", desc.TransactionHash, addedEntry.TransactionHash); } modEntry.SizeWithAncestors -= addedEntry.GetTxSize(); modEntry.ModFeesWithAncestors -= addedEntry.ModifiedFee; modEntry.SigOpCostWithAncestors -= addedEntry.SigOpCost; } } return(descendantsUpdated); }