Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix last seen asserts #7384

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Nethermind/Nethermind.Trie/Pruning/TrieStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public void CommitNode(long blockNumber, Hash256? address, in NodeCommitInfo nod
ThrowUnknownPackage(blockNumber, node);
}

if (node!.LastSeen > 0)
if (node!.LastSeen >= 0)
{
ThrowNodeHasBeenSeen(blockNumber, node);
}
Expand Down Expand Up @@ -938,7 +938,7 @@ private void TrackPrunedPersistedNodes(in DirtyNodesCache.Key key, TrieNode node
TinyTreePath treePath = new(key.Path);
// Persisted node with LastSeen is a node that has been re-committed, likely due to processing
// recalculated to the same hash.
if (node.LastSeen > 0)
if (node.LastSeen >= 0)
{
// Update _persistedLastSeen to later value.
_persistedLastSeen.AddOrUpdate(
Expand Down Expand Up @@ -1076,7 +1076,7 @@ private void PersistNode(Hash256? address, in TreePath path, TrieNode currentNod

if (currentNode.Keccak is not null)
{
Debug.Assert(currentNode.LastSeen > 0, $"Cannot persist a dangling node (without {(nameof(TrieNode.LastSeen))} value set).");
Debug.Assert(currentNode.LastSeen >= 0, $"Cannot persist a dangling node (without {(nameof(TrieNode.LastSeen))} value set).");
// Note that the LastSeen value here can be 'in the future' (greater than block number
// if we replaced a newly added node with an older copy and updated the LastSeen value.
// Here we reach it from the old root so it appears to be out of place but it is correct as we need
Expand All @@ -1100,9 +1100,9 @@ private bool IsNoLongerNeeded(TrieNode node)
return IsNoLongerNeeded(node.LastSeen);
}

private bool IsNoLongerNeeded(long? lastSeen)
private bool IsNoLongerNeeded(long lastSeen)
{
Debug.Assert(lastSeen.HasValue, $"Any node that is cache should have {nameof(TrieNode.LastSeen)} set.");
Debug.Assert(lastSeen >= 0, $"Any node that is cache should have {nameof(TrieNode.LastSeen)} set.");
return lastSeen < LastPersistedBlockNumber
&& lastSeen < LatestCommittedBlockNumber - _pruningStrategy.MaxDepth;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Trie/TrieNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public ValueRlpStream RlpStream
public bool IsBranch => NodeType == NodeType.Branch;
public bool IsExtension => NodeType == NodeType.Extension;

public long LastSeen { get; set; }
public long LastSeen { get; set; } = -1;

public byte[]? Key
{
Expand Down