fix(trie): skip storing empty nibbles in storage trie (#2313)

This commit is contained in:
Roman Krasiuk
2023-04-19 22:03:23 +03:00
committed by GitHub
parent 4a912f1e18
commit 3b0dd3fb35

View File

@ -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 })?;
}
}
}
}