Skip to content

Commit

Permalink
Fix recorder for NonExisting keys
Browse files Browse the repository at this point in the history
We handle `NonExisting` keys as if we have recorded the value. The reason behind this is that we have recorded all the
trie nodes to proof that the key doesn't exist in the `trie`. So, next time we want to access the key we can use the
`cache` (if present) and do not net to iterate over the trie nodes again.
  • Loading branch information
bkchr committed Sep 13, 2023
1 parent 0b9bede commit 692ee41
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion trie-db/src/recorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<L: TrieLayout> TrieRecorder<TrieHash<L>> for Recorder<L> {
},
TrieAccess::NonExisting { full_key } => {
// We handle the non existing value/hash like having recorded the value.
self.recorded_keys.entry(full_key.to_vec()).insert(RecordedForKey::None);
self.recorded_keys.entry(full_key.to_vec()).insert(RecordedForKey::Value);
},
TrieAccess::InlineValue { full_key } => {
self.recorded_keys.entry(full_key.to_vec()).insert(RecordedForKey::Value);
Expand Down
2 changes: 1 addition & 1 deletion trie-db/test/src/triedb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ fn test_trie_nodes_recorded_internal<T: TrieLayout>() {
}

assert_eq!(
RecordedForKey::None,
RecordedForKey::Value,
recorder.trie_nodes_recorded_for_key(&NON_EXISTENT_KEY),
);
}
Expand Down

0 comments on commit 692ee41

Please sign in to comment.