Skip to content

Commit

Permalink
Fix trie exception when killed after memory pruning before next block (
Browse files Browse the repository at this point in the history
  • Loading branch information
asdacap authored Apr 8, 2024
1 parent bb28ea8 commit 8779f51
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Nethermind/Nethermind.Trie.Test/Pruning/TreeStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,39 @@ public async Task Will_RemovePastKeys_OnSnapshot()
}
}

[Test]
public async Task Will_Trigger_ReorgBoundaryEvent_On_Prune()
{
MemDb memDb = new();

using TrieStore fullTrieStore = CreateTrieStore(
kvStore: memDb,
pruningStrategy: new TestPruningStrategy(true, true, 2, 100000),
persistenceStrategy: No.Persistence);

long reorgBoundary = 0;
fullTrieStore.ReorgBoundaryReached += (sender, reached) => reorgBoundary = reached.BlockNumber;

IScopedTrieStore trieStore = fullTrieStore.GetTrieStore(null);

for (int i = 0; i < 64; i++)
{
TrieNode node = new(NodeType.Leaf, TestItem.Keccaks[i], new byte[2]);
trieStore.CommitNode(i, new NodeCommitInfo(node, TreePath.Empty));
trieStore.FinishBlockCommit(TrieType.State, i, node);

if (i > 4)
{
Assert.That(() => reorgBoundary, Is.EqualTo(i - 3).After(1000, 1));
}
else
{
// Pruning is done in background
await Task.Delay(TimeSpan.FromMilliseconds(100));
}
}
}

[Test]
public async Task Will_Not_RemovePastKeys_OnSnapshot_DuringFullPruning()
{
Expand Down
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Trie/Pruning/TrieStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ private bool SaveSnapshot()
Task deleteTask = Task.Run(() => RemovePastKeys(persistedHashes));

writeBatch.Dispose();
AnnounceReorgBoundaries();
deleteTask.Wait();

foreach (KeyValuePair<HashAndTinyPathAndHash, long> keyValuePair in _persistedLastSeens)
Expand Down

0 comments on commit 8779f51

Please sign in to comment.