2626import org .hyperledger .besu .ethereum .rlp .RLP ;
2727import org .hyperledger .besu .ethereum .trie .common .PmtStateTrieAccountValue ;
2828import org .hyperledger .besu .ethereum .trie .pathbased .bonsai .storage .BonsaiWorldStateKeyValueStorage ;
29- import org .hyperledger .besu .ethereum .trie .pathbased .common .worldview .PathBasedWorldView ;
3029import org .hyperledger .besu .ethereum .trie .patricia .StoredMerklePatriciaTrie ;
3130import org .hyperledger .besu .ethereum .worldstate .WorldStateStorageCoordinator ;
3231import org .hyperledger .besu .plugin .services .storage .WorldStateKeyValueStorage ;
@@ -101,12 +100,7 @@ protected int doPersist(
101100
102101 final Hash updatedStorageRoot = currentValue .getStorageRoot ();
103102 if (!accountChanges .storageChanges ().isEmpty ()) {
104- applyStorageChangesAndVerifyStorageRoot (
105- accountHash ,
106- updatedStorageRoot ,
107- accountChanges ,
108- worldStateStorageCoordinator ,
109- bonsaiUpdater );
103+ applyStorageChanges (accountHash , accountChanges , bonsaiUpdater );
110104 }
111105
112106 final PmtStateTrieAccountValue updatedValue =
@@ -122,44 +116,20 @@ protected int doPersist(
122116 return 0 ;
123117 }
124118
125- private void applyStorageChangesAndVerifyStorageRoot (
119+ private void applyStorageChanges (
126120 final Hash accountHash ,
127- final Hash expectedStorageRoot ,
128121 final BlockAccessListChanges .AccountFinalChanges accountChanges ,
129- final WorldStateStorageCoordinator worldStateStorageCoordinator ,
130122 final BonsaiWorldStateKeyValueStorage .Updater bonsaiUpdater ) {
131- final StoredMerklePatriciaTrie <Bytes , Bytes > storageTrie =
132- new StoredMerklePatriciaTrie <>(
133- (location , hash ) ->
134- worldStateStorageCoordinator .getAccountStorageTrieNode (accountHash , location , hash ),
135- Bytes32 .wrap (expectedStorageRoot .getBytes ()),
136- value -> value ,
137- value -> value );
138-
139123 for (final var storageChange : accountChanges .storageChanges ()) {
140124 final Hash slotHash = storageChange .slot ().getSlotHash ();
141125 final UInt256 value = storageChange .value ();
142- final Bytes slotKey = slotHash .getBytes ();
143126
144127 if (value .equals (UInt256 .ZERO )) {
145128 bonsaiUpdater .removeStorageValueBySlotHash (accountHash , slotHash );
146- storageTrie .remove (slotKey );
147129 } else {
148130 bonsaiUpdater .putStorageValueBySlotHash (accountHash , slotHash , value .toBytes ());
149- storageTrie .put (slotKey , PathBasedWorldView .encodeTrieValue (value .toBytes ()));
150131 }
151132 }
152-
153- final Hash calculatedStorageRoot = Hash .wrap (storageTrie .getRootHash ());
154- if (!calculatedStorageRoot .equals (expectedStorageRoot )) {
155- throw new IllegalStateException (
156- "Storage root mismatch for account "
157- + accountHash
158- + ": expected "
159- + expectedStorageRoot
160- + " but got "
161- + calculatedStorageRoot );
162- }
163133 }
164134
165135 @ Override
0 commit comments