Skip to content

Commit

Permalink
add a fix to load correctly the storage trie in the Bonsai WorldState (
Browse files Browse the repository at this point in the history
…hyperledger#6205)

revert some modification that was made to pass tests hyperledger#5686 and fix this tests by loading the storage with EMPTY_TRIE_HASH if we detect that it has been cleared before pushing the new slots after recreation.

---------

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: matkt <karim.t2am@gmail.com>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
  • Loading branch information
matkt authored and gfukushima committed Dec 15, 2023
1 parent 98991c2 commit a925273
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,10 @@ private void updateAccountStorageState(
worldStateUpdater.getAccountsToUpdate().get(updatedAddress);
final BonsaiAccount accountOriginal = accountValue.getPrior();
final Hash storageRoot =
(accountOriginal == null) ? Hash.EMPTY_TRIE_HASH : accountOriginal.getStorageRoot();
(accountOriginal == null
|| worldStateUpdater.getStorageToClear().contains(updatedAddress))
? Hash.EMPTY_TRIE_HASH
: accountOriginal.getStorageRoot();
final StoredMerklePatriciaTrie<Bytes, Bytes> storageTrie =
createTrie(
(location, key) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,17 +328,6 @@ public void commit() {
}
if (tracked.getStorageWasCleared()) {
updatedAccount.clearStorage();
wrappedWorldView()
.getAllAccountStorage(updatedAddress, updatedAccount.getStorageRoot())
.forEach(
(keyHash, entryValue) -> {
final StorageSlotKey storageSlotKey =
new StorageSlotKey(Hash.wrap(keyHash), Optional.empty());
final UInt256 value = UInt256.fromBytes(RLP.decodeOne(entryValue));
pendingStorageUpdates.put(
storageSlotKey, new BonsaiValue<>(value, null, true));
});
updatedAccount.setStorageRoot(Hash.EMPTY_TRIE_HASH);
}
tracked.getUpdatedStorage().forEach(updatedAccount::setStorageValue);
}
Expand Down

0 comments on commit a925273

Please sign in to comment.