Skip to content

Commit

Permalink
Merge branch 'main' of github.com:hyperledger/besu into MakeForkIdUse…
Browse files Browse the repository at this point in the history
…Default
  • Loading branch information
pinges committed Jan 2, 2024
2 parents 9a80638 + eb6a1fc commit add4eac
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.rlp.RLP;
import org.apache.tuweni.units.bigints.UInt256;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -361,14 +362,24 @@ private void clearStorage(
(location, key) -> getStorageTrieNode(addressHash, location, key),
oldAccount.getStorageRoot());
try {

final StorageConsumingMap<StorageSlotKey, BonsaiValue<UInt256>> storageToDelete =
worldStateUpdater.getStorageToUpdate().get(address);
Map<Bytes32, Bytes> entriesToDelete = storageTrie.entriesFrom(Bytes32.ZERO, 256);
while (!entriesToDelete.isEmpty()) {
entriesToDelete
.keySet()
.forEach(
k ->
bonsaiUpdater.removeStorageValueBySlotHash(
address.addressHash(), Hash.wrap(k)));
entriesToDelete.forEach(
(k, v) -> {
final StorageSlotKey storageSlotKey =
new StorageSlotKey(Hash.wrap(k), Optional.empty());
final UInt256 slotValue =
UInt256.fromBytes(Bytes32.leftPad(RLP.decodeValue(v)));
bonsaiUpdater.removeStorageValueBySlotHash(
address.addressHash(), storageSlotKey.getSlotHash());
storageToDelete
.computeIfAbsent(
storageSlotKey, key -> new BonsaiValue<>(slotValue, null, true))
.setPrior(slotValue);
});
entriesToDelete.keySet().forEach(storageTrie::remove);
if (entriesToDelete.size() == 256) {
entriesToDelete = storageTrie.entriesFrom(Bytes32.ZERO, 256);
Expand Down

0 comments on commit add4eac

Please sign in to comment.