Skip to content

Commit

Permalink
Fix an issue in update warm storage method
Browse files Browse the repository at this point in the history
Signed-off-by: Ameziane H <ameziane.hamlat@consensys.net>
  • Loading branch information
ahamlat committed Dec 18, 2022
1 parent 6ff2780 commit ade955b
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions evm/src/main/java/org/hyperledger/besu/evm/frame/MessageFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,19 +311,21 @@ private MessageFrame(
this.warmedUpStorage = initWithAccessedList(accessListWarmStorage);
}

// TO BE REVIEWED
private Map<Address, Map<Bytes32, Bytes32>> initWithAccessedList(
final Multimap<Address, Bytes32> accessListWarmStorage) {

Map<Address, Map<Bytes32, Bytes32>> warmList = new ConcurrentHashMap<>();
if (!accessListWarmStorage.isEmpty()) {
for (Address address : accessListWarmStorage.keySet()) {
Set<Address> addresses = accessListWarmStorage.keySet();
for (Address address : addresses) {
Optional.ofNullable(worldUpdater.get(address)).ifPresent(account -> {
Map<Bytes32, Bytes32> keyValuesMap = new ConcurrentHashMap<>();
for (Bytes32 key : accessListWarmStorage.get(address)) {
keyValuesMap.put(key, worldUpdater.get(address).getStorageValue(UInt256.fromBytes(key)));
keyValuesMap.put(key, account.getStorageValue(UInt256.fromBytes(key)));
}
warmList.put(address, keyValuesMap);
}
});
}

return warmList;
}

Expand Down Expand Up @@ -887,8 +889,8 @@ public UInt256 warmUpStorage(final Account account, final Bytes32 slot) {
public boolean isWarm(final Address address, final Bytes32 slot) {
MessageFrame frame = this;
while (frame != null) {
if (frame.warmedUpStorage.containsKey(address)
&& frame.warmedUpStorage.get(address).containsKey(slot)) {
Map<Bytes32, Bytes32> addressWarmedStorage = frame.warmedUpStorage.get(address);
if (addressWarmedStorage != null && addressWarmedStorage.containsKey(slot)) {
return true;
}
frame = frame.parentMessageFrame;
Expand All @@ -909,13 +911,13 @@ public Bytes getFromWarmedUpStorage(final Address address, final Bytes32 slot) {
}

public void updateWarmUpStorage(final Address address, final UInt256 slot, final UInt256 value) {
MessageFrame frame = this;
while (frame != null) {
if (frame.warmedUpStorage.containsKey(address)
&& frame.warmedUpStorage.get(address).containsKey(slot)) {
frame.warmedUpStorage.get(address).put(slot, value);
return;
}
Map<Bytes32, Bytes32> addressWarmedStorage = warmedUpStorage.get(address);
if (addressWarmedStorage != null ) {
addressWarmedStorage.put(slot, value);
} else {
addressWarmedStorage = new ConcurrentHashMap<>();
addressWarmedStorage.put(slot, value);
warmedUpStorage.put(address, addressWarmedStorage);
}
}

Expand Down

0 comments on commit ade955b

Please sign in to comment.