diff --git a/neo/Ledger/MemoryPool.cs b/neo/Ledger/MemoryPool.cs index 7fdbafe187..521701d0de 100644 --- a/neo/Ledger/MemoryPool.cs +++ b/neo/Ledger/MemoryPool.cs @@ -45,7 +45,7 @@ public int CompareTo(PoolItem otherItem) } } - // Allow reverified transactions to be rebroadcast if it has been this many block times since last broadcast. + // Allow a reverified transaction to be rebroadcasted if it has been this many block times since last broadcast. private const int BlocksTillRebroadcastLowPriorityPoolTx = 30; private const int BlocksTillRebroadcastHighPriorityPoolTx = 10; private int RebroadcastMultiplierThreshold => Capacity / 10; @@ -82,7 +82,6 @@ public int CompareTo(PoolItem otherItem) /// private readonly SortedSet _sortedLowPrioTransactions = new SortedSet(); - /// /// Store the unverified transactions currently in the pool. /// @@ -94,13 +93,12 @@ public int CompareTo(PoolItem otherItem) private readonly SortedSet _unverifiedSortedHighPriorityTransactions = new SortedSet(); private readonly SortedSet _unverifiedSortedLowPriorityTransactions = new SortedSet(); - // internal methods to aid in unit testing + // Internal methods to aid in unit testing internal int SortedHighPrioTxCount => _sortedHighPrioTransactions.Count; internal int SortedLowPrioTxCount => _sortedLowPrioTransactions.Count; internal int UnverifiedSortedHighPrioTxCount => _unverifiedSortedHighPriorityTransactions.Count; internal int UnverifiedSortedLowPrioTxCount => _unverifiedSortedLowPriorityTransactions.Count; - private int _maxTxPerBlock; private int _maxLowPriorityTxPerBlock; @@ -429,15 +427,15 @@ internal void UpdatePoolForBlockPersisted(Block block, Snapshot snapshot) SortedSet unverifiedSortedTxPool, int count, double secondsTimeout, Snapshot snapshot) { DateTime reverifyCutOffTimeStamp = DateTime.UtcNow.AddSeconds(secondsTimeout); - List reverifiedItems = new List(count); List invalidItems = new List(); + + // Since unverifiedSortedTxPool is ordered in an ascending manner, we take from the end. foreach (PoolItem item in unverifiedSortedTxPool.Reverse().Take(count)) { - // Re-verify the top fee max high priority transactions that can be verified in a block if (item.Transaction.Verify(snapshot, _unsortedTransactions.Select(p => p.Value.Transaction))) reverifiedItems.Add(item); - else // Transaction no longer valid -- will be removed from unverifiedTxPool. + else // Transaction no longer valid -- it will be removed from unverifiedTxPool. invalidItems.Add(item); if (DateTime.UtcNow > reverifyCutOffTimeStamp) break;