From 4fa2592b97386405a96a9aef3dc93ceb2ab4f3a7 Mon Sep 17 00:00:00 2001 From: ahamlat Date: Wed, 5 Jun 2024 18:27:19 +0200 Subject: [PATCH] Remove sorting updated storage entries in commit phase (#7167) Signed-off-by: Ameziane H --- .../DiffBasedWorldStateUpdateAccumulator.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/worldview/accumulator/DiffBasedWorldStateUpdateAccumulator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/worldview/accumulator/DiffBasedWorldStateUpdateAccumulator.java index 6c44f185fb..149cefbe54 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/worldview/accumulator/DiffBasedWorldStateUpdateAccumulator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/common/worldview/accumulator/DiffBasedWorldStateUpdateAccumulator.java @@ -45,7 +45,6 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; -import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; @@ -364,27 +363,28 @@ public abstract class DiffBasedWorldStateUpdateAccumulator> entries = - new TreeSet<>(Map.Entry.comparingByKey()); - entries.addAll(updatedAccount.getUpdatedStorage().entrySet()); - // parallel stream here may cause database corruption - entries.forEach( - storageUpdate -> { - final UInt256 keyUInt = storageUpdate.getKey(); - final StorageSlotKey slotKey = - new StorageSlotKey(hashAndSaveSlotPreImage(keyUInt), Optional.of(keyUInt)); - final UInt256 value = storageUpdate.getValue(); - final DiffBasedValue pendingValue = pendingStorageUpdates.get(slotKey); - if (pendingValue == null) { - pendingStorageUpdates.put( - slotKey, - new DiffBasedValue<>( - updatedAccount.getOriginalStorageValue(keyUInt), value)); - } else { - pendingValue.setUpdated(value); - } - }); + updatedAccount + .getUpdatedStorage() + .entrySet() + .forEach( + storageUpdate -> { + final UInt256 keyUInt = storageUpdate.getKey(); + final StorageSlotKey slotKey = + new StorageSlotKey( + hashAndSaveSlotPreImage(keyUInt), Optional.of(keyUInt)); + final UInt256 value = storageUpdate.getValue(); + final DiffBasedValue pendingValue = + pendingStorageUpdates.get(slotKey); + if (pendingValue == null) { + pendingStorageUpdates.put( + slotKey, + new DiffBasedValue<>( + updatedAccount.getOriginalStorageValue(keyUInt), value)); + } else { + pendingValue.setUpdated(value); + } + }); updatedAccount.getUpdatedStorage().clear();