diff --git a/src/Nethermind/Nethermind.Trie/Pruning/TrieStore.cs b/src/Nethermind/Nethermind.Trie/Pruning/TrieStore.cs index 24bbf58dcfc..7aecf87dd7d 100644 --- a/src/Nethermind/Nethermind.Trie/Pruning/TrieStore.cs +++ b/src/Nethermind/Nethermind.Trie/Pruning/TrieStore.cs @@ -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); } @@ -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( @@ -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 @@ -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; } diff --git a/src/Nethermind/Nethermind.Trie/TrieNode.cs b/src/Nethermind/Nethermind.Trie/TrieNode.cs index 46165abd430..fd738105008 100644 --- a/src/Nethermind/Nethermind.Trie/TrieNode.cs +++ b/src/Nethermind/Nethermind.Trie/TrieNode.cs @@ -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 {