From 9e616d2a93d22f5a67a561645f7822cc4a3a5a92 Mon Sep 17 00:00:00 2001 From: matkt Date: Tue, 12 Dec 2023 09:59:34 +0100 Subject: [PATCH] add a fix to load correctly the storage trie in the Bonsai WorldState (#6205) revert some modification that was made to pass tests #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 Signed-off-by: matkt Signed-off-by: jflo --- .../ethereum/bonsai/worldview/BonsaiWorldState.java | 5 ++++- .../worldview/BonsaiWorldStateUpdateAccumulator.java | 11 ----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldState.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldState.java index 7c7f7fd5516..73717425def 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldState.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldState.java @@ -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 storageTrie = createTrie( (location, key) -> diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java index f66fcd0f56f..f4a0da55c9e 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java @@ -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); }