@@ -297,6 +297,19 @@ public void commit() {
297297 final BonsaiAccount updatedAccount ;
298298 final BonsaiValue <BonsaiAccount > updatedAccountValue =
299299 accountsToUpdate .get (updatedAddress );
300+
301+ final Map <StorageSlotKey , BonsaiValue <UInt256 >> pendingStorageUpdates =
302+ storageToUpdate .computeIfAbsent (
303+ updatedAddress ,
304+ k ->
305+ new StorageConsumingMap <>(
306+ updatedAddress , new ConcurrentHashMap <>(), storagePreloader ));
307+
308+ if (tracked .getStorageWasCleared ()) {
309+ storageToClear .add (updatedAddress );
310+ pendingStorageUpdates .clear ();
311+ }
312+
300313 if (tracked .getWrappedAccount () == null ) {
301314 updatedAccount = new BonsaiAccount (this , tracked );
302315 tracked .setWrappedAccount (updatedAccount );
@@ -316,6 +329,17 @@ public void commit() {
316329 }
317330 if (tracked .getStorageWasCleared ()) {
318331 updatedAccount .clearStorage ();
332+ wrappedWorldView ()
333+ .getAllAccountStorage (updatedAddress , updatedAccount .getStorageRoot ())
334+ .forEach (
335+ (keyHash , entryValue ) -> {
336+ final StorageSlotKey storageSlotKey =
337+ new StorageSlotKey (Hash .wrap (keyHash ), Optional .empty ());
338+ final UInt256 value = UInt256 .fromBytes (RLP .decodeOne (entryValue ));
339+ pendingStorageUpdates .put (
340+ storageSlotKey , new BonsaiValue <>(value , null , true ));
341+ });
342+ updatedAccount .setStorageRoot (Hash .EMPTY_TRIE_HASH );
319343 }
320344 tracked .getUpdatedStorage ().forEach (updatedAccount ::setStorageValue );
321345 }
@@ -344,19 +368,6 @@ public void commit() {
344368 return ;
345369 }
346370
347- final StorageConsumingMap <StorageSlotKey , BonsaiValue <UInt256 >>
348- pendingStorageUpdates =
349- storageToUpdate .computeIfAbsent (
350- updatedAddress ,
351- __ ->
352- new StorageConsumingMap <>(
353- updatedAddress , new ConcurrentHashMap <>(), storagePreloader ));
354-
355- if (tracked .getStorageWasCleared ()) {
356- storageToClear .add (updatedAddress );
357- pendingStorageUpdates .clear ();
358- }
359-
360371 final TreeSet <Map .Entry <UInt256 , UInt256 >> entries =
361372 new TreeSet <>(Map .Entry .comparingByKey ());
362373 entries .addAll (updatedAccount .getUpdatedStorage ().entrySet ());
0 commit comments