From 692ee41a6bd0df36252663d2f7974ab1c368d9a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 13 Sep 2023 09:56:58 +0200 Subject: [PATCH] Fix recorder for `NonExisting` keys 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. --- trie-db/src/recorder.rs | 2 +- trie-db/test/src/triedb.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/trie-db/src/recorder.rs b/trie-db/src/recorder.rs index 0111bf1f..c2c4b06e 100644 --- a/trie-db/src/recorder.rs +++ b/trie-db/src/recorder.rs @@ -71,7 +71,7 @@ impl TrieRecorder> for Recorder { }, 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); diff --git a/trie-db/test/src/triedb.rs b/trie-db/test/src/triedb.rs index 253da380..5f2fa699 100644 --- a/trie-db/test/src/triedb.rs +++ b/trie-db/test/src/triedb.rs @@ -1167,7 +1167,7 @@ fn test_trie_nodes_recorded_internal() { } assert_eq!( - RecordedForKey::None, + RecordedForKey::Value, recorder.trie_nodes_recorded_for_key(&NON_EXISTENT_KEY), ); }