From 3b0dd3fb35cf034ba21ced625aaa6b0994ce3a30 Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Wed, 19 Apr 2023 22:03:23 +0300 Subject: [PATCH] fix(trie): skip storing empty nibbles in storage trie (#2313) --- crates/trie/src/trie.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/crates/trie/src/trie.rs b/crates/trie/src/trie.rs index 4f894fbe11..e242ca38f4 100644 --- a/crates/trie/src/trie.rs +++ b/crates/trie/src/trie.rs @@ -190,18 +190,20 @@ impl<'a, 'tx, TX: DbTx<'tx> + DbTxMut<'tx>> StateRoot<'a, TX> { } } BranchNodeUpdate::Storage(hashed_address, nibbles, node) => { - let key: StoredNibblesSubKey = nibbles.hex_data.into(); - if let Some(entry) = - storage_cursor.seek_by_key_subkey(hashed_address, key.clone())? - { - // "seek exact" - if entry.nibbles == key { - storage_cursor.delete_current()?; + if !nibbles.is_empty() { + let key: StoredNibblesSubKey = nibbles.hex_data.into(); + if let Some(entry) = + storage_cursor.seek_by_key_subkey(hashed_address, key.clone())? + { + // "seek exact" + if entry.nibbles == key { + storage_cursor.delete_current()?; + } } - } - storage_cursor - .upsert(hashed_address, StorageTrieEntry { nibbles: key, node })?; + storage_cursor + .upsert(hashed_address, StorageTrieEntry { nibbles: key, node })?; + } } } }