Skip to content

Commit

Permalink
Merge branch 'master' into rvcount-message
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim8y authored Sep 30, 2024
2 parents d5a882b + 6e74e33 commit 977f350
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/Neo/Ledger/MemoryPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,20 @@ private void RemoveConflictsOfVerified(PoolItem item)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal bool TryRemoveUnVerified(UInt256 hash, [MaybeNullWhen(false)] out PoolItem? item)
{
if (!_unverifiedTransactions.TryGetValue(hash, out item))
return false;
_txRwLock.EnterWriteLock();
try
{
if (!_unverifiedTransactions.TryGetValue(hash, out item))
return false;

_unverifiedTransactions.Remove(hash);
_unverifiedSortedTransactions.Remove(item);
return true;
_unverifiedTransactions.Remove(hash);
_unverifiedSortedTransactions.Remove(item);
return true;
}
finally
{
_txRwLock.ExitWriteLock();
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
19 changes: 19 additions & 0 deletions tests/Neo.UnitTests/Ledger/UT_MemoryPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,25 @@ public void TestUpdatePoolForBlockPersisted()
_unit.VerifiedCount.Should().Be(0);
}

[TestMethod]
public void TestTryRemoveUnVerified()
{
AddTransactions(32);
_unit.SortedTxCount.Should().Be(32);

var txs = _unit.GetSortedVerifiedTransactions().ToArray();
_unit.InvalidateVerifiedTransactions();

_unit.SortedTxCount.Should().Be(0);

foreach (var tx in txs)
{
_unit.TryRemoveUnVerified(tx.Hash, out _);
}

_unit.UnVerifiedCount.Should().Be(0);
}

public static StorageKey CreateStorageKey(int id, byte prefix, byte[] key = null)
{
byte[] buffer = GC.AllocateUninitializedArray<byte>(sizeof(byte) + (key?.Length ?? 0));
Expand Down

0 comments on commit 977f350

Please sign in to comment.