Skip to content

Commit

Permalink
Update Besu to 23.10.0 - cherry pick (#9199)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukelee-sl authored Oct 12, 2023
1 parent 008f53f commit 1438a8f
Show file tree
Hide file tree
Showing 46 changed files with 312 additions and 531 deletions.
2 changes: 1 addition & 1 deletion hedera-dependency-versions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plugins {
}

val besuNativeVersion = "0.8.2"
val besuVersion = "23.7.2"
val besuVersion = "23.10.0"
val bouncycastleVersion = "1.70"
val daggerVersion = "2.42"
val eclipseCollectionsVersion = "10.4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.evm.EVM;
import org.hyperledger.besu.evm.account.EvmAccount;
import org.hyperledger.besu.evm.account.MutableAccount;
import org.hyperledger.besu.evm.frame.MessageFrame;
import org.hyperledger.besu.evm.gascalculator.GasCalculator;
import org.hyperledger.besu.evm.processor.AbstractMessageProcessor;
Expand Down Expand Up @@ -101,7 +101,7 @@ protected HederaEvmTxProcessor(
* Executes the {@link MessageFrame} of the EVM transaction and fills execution results into a
* field.
*
* @param sender The origin {@link EvmAccount} that initiates the transaction
* @param sender The origin {@link MutableAccount} that initiates the transaction
* @param receiver the priority form of the receiving {@link Address} (i.e., EIP-1014 if
* present); or the newly created address
* @param gasPrice GasPrice to use for gas calculations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ public Operation.OperationResult execute(final MessageFrame frame, final EVM evm
final Wei value = Wei.wrap(frame.getStackItem(0));

final Address address = frame.getRecipientAddress();
final MutableAccount account =
frame.getWorldUpdater().getAccount(address).getMutable();
final MutableAccount account = frame.getWorldUpdater().getAccount(address);

frame.clearReturnData();

Expand Down Expand Up @@ -116,8 +115,7 @@ private void spawnChildMessage(final MessageFrame frame) {
frame.decrementRemainingGas(cost);

final Address address = frame.getRecipientAddress();
final MutableAccount account =
frame.getWorldUpdater().getAccount(address).getMutable();
final MutableAccount account = frame.getWorldUpdater().getAccount(address);

account.incrementNonce();

Expand All @@ -136,7 +134,8 @@ private void spawnChildMessage(final MessageFrame frame) {
final long childGasStipend = gasCalculator().gasAvailableForChildCreate(frame.getRemainingGas());
frame.decrementRemainingGas(childGasStipend);

final MessageFrame childFrame = MessageFrame.builder()
// child frame is added to frame stack via build method
MessageFrame.builder()
.parentMessageFrame(frame)
.type(MessageFrame.Type.CONTRACT_CREATION)
.worldUpdater(frame.getWorldUpdater().updater())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.evm.account.Account;
import org.hyperledger.besu.evm.account.EvmAccount;
import org.hyperledger.besu.evm.account.MutableAccount;
import org.hyperledger.besu.evm.worldstate.WorldUpdater;
import org.hyperledger.besu.evm.worldstate.WorldView;
import org.hyperledger.besu.evm.worldstate.WrappedEvmAccount;

/**
* This class implementation help for both "base" and "stacked" {@link WorldUpdater}s.
Expand Down Expand Up @@ -91,7 +90,7 @@ protected W wrappedWorldView() {
}

@Override
public EvmAccount createAccount(Address address, long nonce, Wei balance) {
public MutableAccount createAccount(Address address, long nonce, Wei balance) {
return null;
}

Expand Down Expand Up @@ -148,10 +147,10 @@ public Account get(Address address) {
}

@Override
public EvmAccount getAccount(Address address) {
public MutableAccount getAccount(Address address) {
final var extantMutable = this.updatedAccounts.get(address);
if (extantMutable != null) {
return new WrappedEvmAccount(extantMutable);
return extantMutable;
}

final var origin = getForMutation(address);
Expand All @@ -161,7 +160,7 @@ public EvmAccount getAccount(Address address) {
final var trackedAccount = track(new UpdateTrackingAccount<>(origin, null));
trackedAccount.setEvmEntityAccess(hederaEvmEntityAccess);

return new WrappedEvmAccount(trackedAccount);
return trackedAccount;
}

public Map<Address, UpdateTrackingAccount<A>> getUpdatedAccounts() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.evm.ModificationNotAllowedException;
import org.hyperledger.besu.evm.account.Account;
import org.hyperledger.besu.evm.account.AccountStorageEntry;
import org.hyperledger.besu.evm.account.EvmAccount;
import org.hyperledger.besu.evm.account.MutableAccount;

/**
Expand All @@ -44,7 +42,7 @@
* Contains {@code updateAccountTracker} for immediate set of balance in the world state. Note that in practice this
* only track the modified account values, but doesn't remind if they were modified or not.
*/
public class UpdateTrackingAccount<A extends Account> implements MutableAccount, EvmAccount {
public class UpdateTrackingAccount<A extends Account> implements MutableAccount {
@Nullable
protected final A account;

Expand Down Expand Up @@ -261,8 +259,8 @@ public String toString() {
}

@Override
public MutableAccount getMutable() throws ModificationNotAllowedException {
return this;
public void becomeImmutable() {
throw new UnsupportedOperationException("Not Implemented Yet");
}

public void setEvmEntityAccess(HederaEvmEntityAccess hederaEvmEntityAccess) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.hyperledger.besu.evm.EVM;
import org.hyperledger.besu.evm.EvmSpecVersion;
import org.hyperledger.besu.evm.MainnetEVMs;
import org.hyperledger.besu.evm.account.EvmAccount;
import org.hyperledger.besu.evm.account.MutableAccount;
import org.hyperledger.besu.evm.code.CodeV0;
import org.hyperledger.besu.evm.frame.BlockValues;
Expand Down Expand Up @@ -214,19 +213,15 @@ void throwsWhenSenderCannotCoverUpfrontCost() {

given(blockMetaSource.computeBlockValues(anyLong())).willReturn(hederaBlockValues);
given(globalDynamicProperties.fundingAccountAddress()).willReturn(fundingAccount);
final var wrappedSenderAccount = mock(EvmAccount.class);
final var mutableSenderAccount = mock(MutableAccount.class);
final var wrappedSenderAccount = mock(MutableAccount.class);
given(stackedUpdater.getSenderAccount(any())).willReturn(wrappedSenderAccount);
given(stackedUpdater.getSenderAccount(any()).getMutable()).willReturn(mutableSenderAccount);
given(gasCalculator.getSelfDestructRefundAmount()).willReturn(0L);
given(gasCalculator.getMaxRefundQuotient()).willReturn(2L);
given(gasCalculator.transactionIntrinsicGasCost(Bytes.EMPTY, false)).willReturn(100_000L);

final var wrappedRecipientAccount = mock(EvmAccount.class);
final var mutableRecipientAccount = mock(MutableAccount.class);
final var wrappedRecipientAccount = mock(MutableAccount.class);

given(stackedUpdater.getOrCreate(any())).willReturn(wrappedRecipientAccount);
given(stackedUpdater.getOrCreate(any()).getMutable()).willReturn(mutableRecipientAccount);
given(updater.updater()).willReturn(stackedUpdater);

evmTxProcessor.setupFields(false);
Expand All @@ -242,19 +237,18 @@ void throwsWhenIntrinsicGasCostExceedsGasLimit() {
given(globalDynamicProperties.fundingAccountAddress()).willReturn(fundingAccount);
given(blockMetaSource.computeBlockValues(anyLong())).willReturn(hederaBlockValues);

final var evmAccount = mock(EvmAccount.class);
final var mutableAccount = mock(MutableAccount.class);
given(gasCalculator.getSelfDestructRefundAmount()).willReturn(0L);
given(gasCalculator.getMaxRefundQuotient()).willReturn(2L);

final var senderMutableAccount = mock(MutableAccount.class);
given(senderMutableAccount.decrementBalance(any())).willReturn(Wei.of(1234L));
given(senderMutableAccount.incrementBalance(any())).willReturn(Wei.of(1500L));
given(evmAccount.getMutable()).willReturn(senderMutableAccount);

given(stackedUpdater.getSenderAccount(any())).willReturn(evmAccount);
given(stackedUpdater.getSenderAccount(any()).getMutable()).willReturn(senderMutableAccount);
given(stackedUpdater.getOrCreate(any())).willReturn(evmAccount);
given(stackedUpdater.getOrCreate(any()).getMutable()).willReturn(senderMutableAccount);
given(stackedUpdater.getSenderAccount(any())).willReturn(mutableAccount);
given(stackedUpdater.getSenderAccount(any())).willReturn(senderMutableAccount);
given(stackedUpdater.getOrCreate(any())).willReturn(mutableAccount);
given(stackedUpdater.getOrCreate(any())).willReturn(senderMutableAccount);

givenInvalidMock();

Expand Down Expand Up @@ -332,22 +326,15 @@ private void givenValidMock(final long intrinsicGasCost) {
given(updater.updater()).willReturn(stackedUpdater);
given(globalDynamicProperties.fundingAccountAddress()).willReturn(fundingAccount);

final var evmAccount = mock(EvmAccount.class);
final var mutableAccount = mock(MutableAccount.class);

given(gasCalculator.transactionIntrinsicGasCost(Bytes.EMPTY, false)).willReturn(intrinsicGasCost);

given(gasCalculator.getSelfDestructRefundAmount()).willReturn(0L);
given(gasCalculator.getMaxRefundQuotient()).willReturn(2L);

final var senderMutableAccount = mock(MutableAccount.class);
given(senderMutableAccount.decrementBalance(any())).willReturn(Wei.of(1234L));
given(senderMutableAccount.incrementBalance(any())).willReturn(Wei.of(1500L));
given(evmAccount.getMutable()).willReturn(senderMutableAccount);

given(stackedUpdater.getSenderAccount(any())).willReturn(evmAccount);
given(stackedUpdater.getSenderAccount(any()).getMutable()).willReturn(senderMutableAccount);
given(stackedUpdater.getOrCreate(any())).willReturn(evmAccount);
given(stackedUpdater.getOrCreate(any()).getMutable()).willReturn(senderMutableAccount);
given(stackedUpdater.getSenderAccount(any())).willReturn(mutableAccount);
given(stackedUpdater.getOrCreate(any())).willReturn(mutableAccount);

given(blockMetaSource.computeBlockValues(anyLong())).willReturn(hederaBlockValues);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.evm.EVM;
import org.hyperledger.besu.evm.account.EvmAccount;
import org.hyperledger.besu.evm.account.MutableAccount;
import org.hyperledger.besu.evm.frame.MessageFrame;
import org.hyperledger.besu.evm.frame.TxValues;
Expand All @@ -65,10 +64,7 @@ class AbstractEvmRecordingCreateOperationTest {
private MessageFrame frame;

@Mock
private EvmAccount recipientAccount;

@Mock
private MutableAccount mutableAccount;
private MutableAccount recipientAccount;

@Mock
private HederaEvmWorldUpdater updater;
Expand Down Expand Up @@ -142,8 +138,7 @@ void failsWithInsufficientRecipientBalanceForValue() {
given(frame.getRecipientAddress()).willReturn(recipient);
given(frame.getWorldUpdater()).willReturn(updater);
given(updater.getAccount(recipient)).willReturn(recipientAccount);
given(recipientAccount.getMutable()).willReturn(mutableAccount);
given(mutableAccount.getBalance()).willReturn(Wei.ONE);
given(recipientAccount.getBalance()).willReturn(Wei.ONE);

assertSameResult(EMPTY_HALT_RESULT, subject.execute(frame, evm));
verify(frame).pushStackItem(UInt256.ZERO);
Expand Down Expand Up @@ -217,8 +212,7 @@ void failsWhenMatchingHollowAccountExistsAndLazyCreationDisabled() {
given(frame.getRecipientAddress()).willReturn(recipient);
given(frame.getWorldUpdater()).willReturn(updater);
given(updater.getAccount(recipient)).willReturn(recipientAccount);
given(recipientAccount.getMutable()).willReturn(mutableAccount);
given(mutableAccount.getBalance()).willReturn(Wei.of(value));
given(recipientAccount.getBalance()).willReturn(Wei.of(value));
given(frame.getDepth()).willReturn(1023);
given(frame.getStackItem(anyInt())).willReturn(Bytes.ofUnsignedLong(1));
given(externalizer.shouldFailBasedOnLazyCreation(eq(frame), any())).willReturn(true);
Expand Down Expand Up @@ -247,8 +241,7 @@ private void givenSpawnPrereqs(MessageFrame frame) {
given(frame.getRecipientAddress()).willReturn(recipient);
given(frame.getWorldUpdater()).willReturn(updater);
given(updater.getAccount(recipient)).willReturn(recipientAccount);
given(recipientAccount.getMutable()).willReturn(mutableAccount);
given(mutableAccount.getBalance()).willReturn(Wei.of(value));
given(recipientAccount.getBalance()).willReturn(Wei.of(value));
given(frame.getDepth()).willReturn(1023);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.apache.tuweni.units.bigints.UInt256;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.evm.EVM;
import org.hyperledger.besu.evm.account.EvmAccount;
import org.hyperledger.besu.evm.account.MutableAccount;
import org.hyperledger.besu.evm.frame.ExceptionalHaltReason;
import org.hyperledger.besu.evm.frame.MessageFrame;
import org.hyperledger.besu.evm.gascalculator.GasCalculator;
Expand Down Expand Up @@ -56,10 +56,10 @@ class HederaEvmSLoadOperationTest {
EVM evm;

@Mock
AbstractLedgerEvmWorldUpdater worldUpdater;
AbstractLedgerEvmWorldUpdater<?, ?> worldUpdater;

@Mock
EvmAccount evmAccount;
MutableAccount evmAccount;

final Bytes keyBytesMock = Bytes.of(1, 2, 3, 4);
final Bytes valueBytesMock = Bytes.of(4, 3, 2, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,6 @@ void nonTrackingAlwaysHasZeroOriginalStorage() {
assertSame(UInt256.ZERO, subject.getOriginalStorageValue(UInt256.ONE));
}

@Test
void getMutableReturnsSelf() {
final var account = new WorldStateAccount(targetAddress, Wei.of(initialBalance), codeCache, entityAccess);
final var subject = new UpdateTrackingAccount<>(account, null);

assertSame(subject, subject.getMutable());
}

@Test
void toStringWorksAsExpected() {
final var expectedNoUpdatedStorageOrCode = "0x000000000000000000000000000000000000066e -> {nonce:0,"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ class UpdatedHederaEvmAccountTest {
private static final long newBalance = 200_000L;
private static final int newNonce = 2;
private final Address address = Address.fromHexString("0x000000000000000000000000000000000000077e");
private UpdateTrackingAccount subject;
private UpdateTrackingAccount<?> subject;

@Mock
private HederaEvmEntityAccess hederaEvmEntityAccess;

@BeforeEach
void setUp() {
subject = new UpdateTrackingAccount(address, null);
subject = new UpdateTrackingAccount<>(address, null);
subject.setBalance(Wei.ONE);
subject.setNonce(1L);
subject.setEvmEntityAccess(hederaEvmEntityAccess);
}

@Test
void testConstructor() {
UpdateTrackingAccount newSubject = new UpdateTrackingAccount(newAddress, null);
UpdateTrackingAccount<?> newSubject = new UpdateTrackingAccount<>(newAddress, null);
assertEquals(newSubject.getAddress(), newAddress);
}

Expand Down Expand Up @@ -106,7 +106,7 @@ void getStorageValueFromDb() {

@Test
void getOriginalStorageValue() {
subject = new UpdateTrackingAccount(address, null);
subject = new UpdateTrackingAccount<>(address, null);
assertEquals(ZERO, subject.getOriginalStorageValue(MIN_VALUE));
}

Expand All @@ -128,11 +128,6 @@ void clearStorage() {
assertEquals(0, subject.getUpdatedStorage().size());
}

@Test
void getMutable() {
assertEquals(subject, subject.getMutable());
}

@Test
void setCode() {
subject.setCode(Bytes.EMPTY);
Expand Down
Loading

0 comments on commit 1438a8f

Please sign in to comment.