From 710b25fb2b2efd4b221bd4e47821929ecaea61e6 Mon Sep 17 00:00:00 2001 From: thinkAfCod Date: Sun, 29 Sep 2024 19:24:18 +0800 Subject: [PATCH] fix: test case --- .../besu/cli/config/EthNetworkConfig.java | 16 ++--- .../cli/CascadingDefaultProviderTest.java | 1 + .../options/TransactionPoolOptionsTest.java | 2 +- .../besu/services/BesuEventsImplTest.java | 3 +- .../EnginePayloadAttributesParameter.java | 2 +- .../AbstractEngineForkchoiceUpdatedTest.java | 10 +-- .../engine/EngineForkchoiceUpdatedV2Test.java | 3 + .../EnginePayloadAttributesParameterTest.java | 11 +-- .../AbstractBlockCreatorTest.java | 2 + .../ethereum/core/TransactionReceipt.java | 2 +- .../ethereum/mainnet/L1CostCalculator.java | 17 +++-- .../mainnet/MainnetProtocolSpecs.java | 1 + .../mainnet/MainnetTransactionProcessor.java | 3 +- .../mainnet/MainnetTransactionValidator.java | 5 +- .../PermissionTransactionValidator.java | 3 +- .../mainnet/TransactionValidator.java | 3 +- .../mainnet/WithdrawalsValidator.java | 2 +- .../MainnetTransactionValidatorTest.java | 65 +++++++++++++---- .../eth/transactions/TransactionPool.java | 2 +- .../AbstractTransactionPoolTest.java | 9 ++- .../hyperledger/besu/evm/EvmSpecVersion.java | 2 +- .../org/hyperledger/besu/evm/MainnetEVMs.java | 70 ++++++++++++++++++- .../besu/evm/fluent/EVMExecutor.java | 4 +- .../besu/evm/fluent/EVMExecutorTest.java | 2 +- fork.yaml | 1 - 25 files changed, 170 insertions(+), 71 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/config/EthNetworkConfig.java b/besu/src/main/java/org/hyperledger/besu/cli/config/EthNetworkConfig.java index 76686bd19c0..240c9ba3eb0 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/config/EthNetworkConfig.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/config/EthNetworkConfig.java @@ -26,6 +26,7 @@ import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -88,7 +89,7 @@ public static EthNetworkConfig getNetworkConfig(final NetworkName networkName) { .orElse(Collections.emptyList()); return new EthNetworkConfig( genesisConfigFile, - null, + new HashMap<>(), networkName.getNetworkId(), bootNodes, genesisConfigOptions.getDiscoveryOptions().getDiscoveryDnsUrl().orElse(null)); @@ -119,7 +120,7 @@ public static class Builder { private String dnsDiscoveryUrl; private GenesisConfigFile genesisConfigFile; private BigInteger networkId; - private final List bootNodes; + private List bootNodes; private Map genesisConfigOverrides; /** @@ -132,6 +133,7 @@ public Builder(final EthNetworkConfig ethNetworkConfig) { this.networkId = ethNetworkConfig.networkId; this.bootNodes = ethNetworkConfig.bootNodes; this.dnsDiscoveryUrl = ethNetworkConfig.dnsDiscoveryUrl; + this.genesisConfigOverrides = ethNetworkConfig.genesisConfigOverrides; } /** @@ -174,15 +176,7 @@ public Builder setNetworkId(final BigInteger networkId) { * @return this builder */ public Builder setBootNodes(final List bootNodes) { - if (bootNodes == null) { - return this; - } - bootNodes.forEach( - bootNode -> { - if (!this.bootNodes.contains(bootNode)) { - this.bootNodes.add(bootNode); - } - }); + this.bootNodes = bootNodes; return this; } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/CascadingDefaultProviderTest.java b/besu/src/test/java/org/hyperledger/besu/cli/CascadingDefaultProviderTest.java index 13b8f13d847..c9166514e57 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/CascadingDefaultProviderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/CascadingDefaultProviderTest.java @@ -133,6 +133,7 @@ public void overrideDefaultValuesIfKeyIsPresentInConfigFile(final @TempDir File GenesisConfigFile.fromConfig(encodeJsonGenesis(GENESIS_VALID_JSON))) .setBootNodes(nodes) .setDnsDiscoveryUrl(null) + .setGenesisConfigOverrides(new HashMap<>()) .build(); verify(mockControllerBuilder).dataDirectory(eq(dataFolder.toPath())); verify(mockControllerBuilderFactory).fromEthNetworkConfig(eq(networkConfig), any()); diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java index 4ee34295f45..039dd718f70 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java @@ -413,7 +413,7 @@ public void maxPrioritizedTxsPerTypeConfigFile() throws IOException { @Test public void maxPrioritizedTxsPerTypeWrongTxType() { internalTestFailure( - "Invalid value for option '--tx-pool-max-prioritized-by-type' (MAP): expected one of [FRONTIER, ACCESS_LIST, EIP1559, BLOB, SET_CODE] (case-insensitive) but was 'WRONG_TYPE'", + "Invalid value for option '--tx-pool-max-prioritized-by-type' (MAP): expected one of [FRONTIER, ACCESS_LIST, EIP1559, BLOB, SET_CODE, OPTIMISM_DEPOSIT] (case-insensitive) but was 'WRONG_TYPE'", "--tx-pool-max-prioritized-by-type", "WRONG_TYPE=1"); } diff --git a/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java b/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java index 14a9975e126..93fb4430318 100644 --- a/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java +++ b/besu/src/test/java/org/hyperledger/besu/services/BesuEventsImplTest.java @@ -17,7 +17,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -146,7 +145,7 @@ public void setUp() { .when( mockTransactionValidatorFactory .get() - .validate(any(), anyLong(), any(Optional.class), any(Optional.class), any())) + .validate(any(), any(), any(Optional.class), any(Optional.class), any())) .thenReturn(ValidationResult.valid()); lenient() .when(mockTransactionValidatorFactory.get().validateForSender(any(), any(), any())) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EnginePayloadAttributesParameter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EnginePayloadAttributesParameter.java index 71aa27f2853..268525df940 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EnginePayloadAttributesParameter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EnginePayloadAttributesParameter.java @@ -55,7 +55,7 @@ public EnginePayloadAttributesParameter( parentBeaconBlockRoot == null ? null : Bytes32.fromHexString(parentBeaconBlockRoot); this.noTxPool = noTxPool; this.transactions = transactions; - this.gasLimit = gasLimit.getValue(); + this.gasLimit = gasLimit == null ? null : gasLimit.getValue(); } public Long getTimestamp() { diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java index 1193cb7dbc3..9aeef10a98c 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java @@ -248,7 +248,7 @@ public void shouldReturnValidWithoutFinalizedWithPayload() { null, null, null, - new UnsignedLongParameter(0L)); + null); var mockPayloadId = PayloadIdentifier.forPayloadParams( mockHeader.getHash(), @@ -512,7 +512,7 @@ public void shouldReturnInvalidIfWithdrawalsIsNotNull_WhenWithdrawalsProhibited( null, null, null, - new UnsignedLongParameter(0L)); + null); var resp = resp( @@ -540,7 +540,7 @@ public void shouldReturnValidIfWithdrawalsIsNull_WhenWithdrawalsProhibited() { null, null, null, - new UnsignedLongParameter(0L)); + null); var mockPayloadId = PayloadIdentifier.forPayloadParams( @@ -629,7 +629,7 @@ public void shouldReturnValidIfWithdrawalsIsNotNull_WhenWithdrawalsAllowed() { null, null, null, - new UnsignedLongParameter(0L)); + null); final Optional> withdrawals = Optional.of( @@ -684,7 +684,7 @@ public void shouldReturnValidIfProtocolScheduleIsEmpty() { null, null, null, - new UnsignedLongParameter(0L)); + null); var mockPayloadId = PayloadIdentifier.forPayloadParams( diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2Test.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2Test.java index c3558ef3292..3b7679608ef 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2Test.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV2Test.java @@ -73,6 +73,9 @@ public void shouldReturnUnsupportedForkIfBlockTimestampIsAfterCancunMilestone() Bytes32.fromHexStringLenient("0xDEADBEEF").toHexString(), Address.ECREC.toString(), null, + null, + false, + null, null); final JsonRpcResponse resp = resp(param, Optional.of(payloadParams)); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EnginePayloadAttributesParameterTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EnginePayloadAttributesParameterTest.java index a4e1350eef9..2acfe589e8c 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EnginePayloadAttributesParameterTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/EnginePayloadAttributesParameterTest.java @@ -98,14 +98,7 @@ public void serialize_WithdrawalsPresent() { private EnginePayloadAttributesParameter parameterWithdrawalsOmitted() { return new EnginePayloadAttributesParameter( - TIMESTAMP, - PREV_RANDAO, - SUGGESTED_FEE_RECIPIENT_ADDRESS, - null, - null, - null, - null, - new UnsignedLongParameter(0L)); + TIMESTAMP, PREV_RANDAO, SUGGESTED_FEE_RECIPIENT_ADDRESS, null, null, null, null, null); } private EnginePayloadAttributesParameter parameterWithdrawalsPresent() { @@ -118,7 +111,7 @@ private EnginePayloadAttributesParameter parameterWithdrawalsPresent() { null, null, null, - new UnsignedLongParameter(0L)); + null); } // TODO: add a parent beacon block root test here diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java index 68e80912dfa..82549155387 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java @@ -96,6 +96,7 @@ import java.time.Clock; import java.util.List; import java.util.Optional; +import java.util.OptionalLong; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; @@ -499,6 +500,7 @@ static class AlwaysValidTransactionValidator implements TransactionValidator { @Override public ValidationResult validate( final Transaction transaction, + final OptionalLong blockTimestamp, final Optional baseFee, final Optional blobBaseFee, final TransactionValidationParams transactionValidationParams) { diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/TransactionReceipt.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/TransactionReceipt.java index fe4bd49bf64..b1f217b37e2 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/TransactionReceipt.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/TransactionReceipt.java @@ -370,7 +370,7 @@ public static TransactionReceipt readFrom( return new TransactionReceipt( transactionType, stateRoot, - 0, + -1, cumulativeGas, logs, bloomFilter, diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/L1CostCalculator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/L1CostCalculator.java index 05b1f342698..009d9cbfdf2 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/L1CostCalculator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/L1CostCalculator.java @@ -36,13 +36,13 @@ public class L1CostCalculator { private static final UInt256 SIXTEEN = UInt256.valueOf(16L); private static final BigInteger L1_COST_INTERCEPT = BigInteger.valueOf(-42_585_600L); - private static final UInt256 L1_COST_FAST_LZ_COEF = UInt256.valueOf(836_500L); + private static final BigInteger L1_COST_FAST_LZ_COEF = BigInteger.valueOf(836_500L); - private static final UInt256 MIN_TX_SIZE = UInt256.valueOf(100L); - private static final UInt256 MIN_TX_SIZE_SCALED = - UInt256.valueOf(1_000_000L).multiply(MIN_TX_SIZE); + private static final BigInteger MIN_TX_SIZE = BigInteger.valueOf(100L); + private static final BigInteger MIN_TX_SIZE_SCALED = + BigInteger.valueOf(1_000_000L).multiply(MIN_TX_SIZE); private static final UInt256 ECOTONE_DIVISOR = UInt256.valueOf(1_000_000L * 16L); - private static final UInt256 FJORD_DIVISOR = UInt256.valueOf(1_000_000_000_000L); + private static final BigInteger FJORD_DIVISOR = BigInteger.valueOf(1_000_000_000_000L); private static final int BASE_FEE_SCALAR_SLOT_OFFSET = 12; // private static final int BLOB_BASE_FEE_SCALAR_SLOT_OFFSET = 8; @@ -231,16 +231,15 @@ static Wei l1CostFjord( var blobCostPerByte = l1BlobBaseFeeScalar.multiply(l1BlobBaseFee); var l1FeeScaled = calldataCostPerByte.add(blobCostPerByte); - var fastLzSize = UInt256.valueOf(costData.getFastLzSize()); var estimatedSize = - UInt256.valueOf( - L1_COST_INTERCEPT.add(L1_COST_FAST_LZ_COEF.multiply(fastLzSize).toBigInteger())); + L1_COST_INTERCEPT.add( + L1_COST_FAST_LZ_COEF.multiply(BigInteger.valueOf(costData.getFastLzSize()))); if (estimatedSize.compareTo(MIN_TX_SIZE_SCALED) < 0) { estimatedSize = MIN_TX_SIZE_SCALED; } - var l1CostScaled = estimatedSize.multiply(l1FeeScaled); + var l1CostScaled = estimatedSize.multiply(l1FeeScaled.toBigInteger()); var l1Cost = l1CostScaled.divide(FJORD_DIVISOR); return Wei.of(l1Cost); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java index 021d5055ce5..40662d669c5 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java @@ -1024,6 +1024,7 @@ static ProtocolSpecBuilder regolithDefinition( (BaseFeeMarket) feeMarket)) .blockBodyValidatorBuilder(BaseFeeBlockBodyValidator::new) .genesisConfigOptions(Optional.of(genesisConfigOptions)) + .withdrawalsValidator(new WithdrawalsValidator.AllowedWithdrawals()) .name("Regolith"); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java index 23a6f5a9a18..8e9a9372904 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java @@ -51,6 +51,7 @@ import java.util.Deque; import java.util.List; import java.util.Optional; +import java.util.OptionalLong; import java.util.Set; import com.google.common.collect.HashMultimap; @@ -339,7 +340,7 @@ public TransactionProcessingResult processTransaction( ValidationResult validationResult = transactionValidator.validate( transaction, - blockHeader.getTimestamp(), + OptionalLong.of(blockHeader.getTimestamp()), blockHeader.getBaseFee(), Optional.ofNullable(blobGasPrice), transactionValidationParams); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java index b2b7ddfeb89..b5ddf91fc0d 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java @@ -36,6 +36,7 @@ import java.math.BigInteger; import java.util.List; import java.util.Optional; +import java.util.OptionalLong; import java.util.Set; import ethereum.ckzg4844.CKZG4844JNI; @@ -105,7 +106,7 @@ public MainnetTransactionValidator( @Override public ValidationResult validate( final Transaction transaction, - final long blockTimestamp, + final OptionalLong blockTimestamp, final Optional baseFee, final Optional blobFee, final TransactionValidationParams transactionValidationParams) { @@ -144,7 +145,7 @@ public ValidationResult validate( if (transaction.getType().equals(TransactionType.OPTIMISM_DEPOSIT)) { // genesisOptions.orElseThrow(); if (transaction.getIsSystemTx().orElse(false)) { - if (genesisOptions.get().isRegolith(blockTimestamp)) { + if (genesisOptions.get().isRegolith(blockTimestamp.orElse(0L))) { return ValidationResult.invalid( TransactionInvalidReason.SYSTEM_TX_NOT_SUPPORT, String.format( diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PermissionTransactionValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PermissionTransactionValidator.java index ef2fa1f5529..48597c6d699 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PermissionTransactionValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PermissionTransactionValidator.java @@ -21,6 +21,7 @@ import org.hyperledger.besu.evm.account.Account; import java.util.Optional; +import java.util.OptionalLong; /** * Validates a transaction based on Frontier protocol runtime requirements. @@ -42,7 +43,7 @@ public PermissionTransactionValidator( @Override public ValidationResult validate( final Transaction transaction, - final long blockTimestamp, + final OptionalLong blockTimestamp, final Optional baseFee, final Optional blobBaseFee, final TransactionValidationParams transactionValidationParams) { diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/TransactionValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/TransactionValidator.java index 8e8837d2c8e..52f09d0bf3b 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/TransactionValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/TransactionValidator.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.evm.account.Account; import java.util.Optional; +import java.util.OptionalLong; public interface TransactionValidator { @@ -34,7 +35,7 @@ public interface TransactionValidator { */ ValidationResult validate( Transaction transaction, - final long blockTimestamp, + OptionalLong blockTimestamp, Optional baseFee, Optional blobBaseFee, TransactionValidationParams transactionValidationParams); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/WithdrawalsValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/WithdrawalsValidator.java index bec9c6c6d90..2adda62054b 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/WithdrawalsValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/WithdrawalsValidator.java @@ -38,7 +38,7 @@ class ProhibitedWithdrawals implements WithdrawalsValidator { @Override public boolean validateWithdrawals(final Optional> withdrawals) { - final boolean isValid = withdrawals.isEmpty() || withdrawals.get().isEmpty(); + final boolean isValid = withdrawals.isEmpty(); if (!isValid) { LOG.warn( "withdrawals must be null when Withdrawals are prohibited but were: {}", withdrawals); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidatorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidatorTest.java index 9d9aa4482b5..1596885c16b 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidatorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidatorTest.java @@ -53,6 +53,7 @@ import java.math.BigInteger; import java.util.List; import java.util.Optional; +import java.util.OptionalLong; import java.util.Set; import java.util.function.Supplier; @@ -132,7 +133,11 @@ public void shouldRejectTransactionIfIntrinsicGasExceedsGasLimit() { assertThat( validator.validate( - transaction, 0L, Optional.empty(), Optional.empty(), transactionValidationParams)) + transaction, + OptionalLong.empty(), + Optional.empty(), + Optional.empty(), + transactionValidationParams)) .isEqualTo( ValidationResult.invalid(TransactionInvalidReason.INTRINSIC_GAS_EXCEEDS_GAS_LIMIT)); } @@ -145,7 +150,7 @@ public void shouldRejectTransactionWhenTransactionHasChainIdAndValidatorDoesNot( assertThat( validator.validate( basicTransaction, - 0L, + OptionalLong.empty(), Optional.empty(), Optional.empty(), transactionValidationParams)) @@ -165,7 +170,7 @@ public void shouldRejectTransactionWhenTransactionHasIncorrectChainId() { assertThat( validator.validate( basicTransaction, - 0L, + OptionalLong.empty(), Optional.empty(), Optional.empty(), transactionValidationParams)) @@ -317,7 +322,11 @@ public void shouldRejectTransactionWithMaxPriorityFeeGreaterThanMaxFee() { final ValidationResult validationResult = validator.validate( - transaction, 0L, Optional.of(Wei.ONE), Optional.empty(), transactionValidationParams); + transaction, + OptionalLong.empty(), + Optional.of(Wei.ONE), + Optional.empty(), + transactionValidationParams); assertThat(validationResult) .isEqualTo(ValidationResult.invalid(MAX_PRIORITY_FEE_PER_GAS_EXCEEDS_MAX_FEE_PER_GAS)); assertThat(validationResult.getErrorMessage()) @@ -360,7 +369,7 @@ public void shouldRejectTransactionWithMaxBlobPriorityFeeSmallerThanBlobBaseFee( final ValidationResult validationResult = validator.validate( transaction, - 0L, + OptionalLong.empty(), Optional.of(Wei.ONE), Optional.of(Wei.of(10)), transactionValidationParams); @@ -404,7 +413,11 @@ public void shouldAcceptOnlyTransactionsInAcceptedTransactionTypes() { assertThat( frontierValidator.validate( - transaction, 0L, Optional.empty(), Optional.empty(), transactionValidationParams)) + transaction, + OptionalLong.empty(), + Optional.empty(), + Optional.empty(), + transactionValidationParams)) .isEqualTo(ValidationResult.invalid(INVALID_TRANSACTION_FORMAT)); when(gasCalculator.transactionIntrinsicGasCost(any(), anyBoolean())).thenReturn(0L); @@ -412,7 +425,7 @@ public void shouldAcceptOnlyTransactionsInAcceptedTransactionTypes() { assertThat( eip1559Validator.validate( transaction, - 0L, + OptionalLong.empty(), Optional.of(Wei.ONE), Optional.empty(), transactionValidationParams)) @@ -440,7 +453,11 @@ public void shouldRejectTransactionIfEIP1559TransactionGasPriceLessBaseFee() { final Optional basefee = Optional.of(Wei.of(150000L)); assertThat( validator.validate( - transaction, 0L, basefee, Optional.empty(), transactionValidationParams)) + transaction, + OptionalLong.empty(), + basefee, + Optional.empty(), + transactionValidationParams)) .isEqualTo(ValidationResult.invalid(GAS_PRICE_BELOW_CURRENT_BASE_FEE)); } @@ -466,7 +483,11 @@ public void shouldAcceptZeroGasPriceTransactionIfBaseFeeIsZero() { assertThat( validator.validate( - transaction, 0L, zeroBaseFee, Optional.empty(), transactionValidationParams)) + transaction, + OptionalLong.empty(), + zeroBaseFee, + Optional.empty(), + transactionValidationParams)) .isEqualTo(ValidationResult.valid()); } @@ -493,7 +514,11 @@ public void shouldAcceptValidEIP1559() { assertThat( validator.validate( - transaction, 0L, basefee, Optional.empty(), transactionValidationParams)) + transaction, + OptionalLong.empty(), + basefee, + Optional.empty(), + transactionValidationParams)) .isEqualTo(ValidationResult.valid()); } @@ -520,7 +545,7 @@ public void shouldValidate1559TransactionWithPriceLowerThanBaseFeeForTransaction assertThat( validator.validate( transaction, - 0L, + OptionalLong.empty(), Optional.of(Wei.ONE), Optional.empty(), TransactionValidationParams.transactionPool())) @@ -546,7 +571,11 @@ public void shouldRejectTooLargeInitcode() { .createTransaction(senderKeys); var validationResult = validator.validate( - bigPayload, 0L, Optional.empty(), Optional.empty(), transactionValidationParams); + bigPayload, + OptionalLong.empty(), + Optional.empty(), + Optional.empty(), + transactionValidationParams); assertThat(validationResult.isValid()).isFalse(); assertThat(validationResult.getInvalidReason()) @@ -592,7 +621,11 @@ public void shouldRejectContractCreateWithBlob() { .createTransaction(senderKeys); var validationResult = validator.validate( - blobTx, 0L, Optional.empty(), Optional.of(Wei.of(15)), transactionValidationParams); + blobTx, + OptionalLong.empty(), + Optional.empty(), + Optional.of(Wei.of(15)), + transactionValidationParams); if (!validationResult.isValid()) { System.out.println( validationResult.getInvalidReason() + " " + validationResult.getErrorMessage()); @@ -631,7 +664,11 @@ public void shouldAcceptTransactionWithAtLeastOneBlob() { .createTransaction(senderKeys); var validationResult = validator.validate( - blobTx, 0L, Optional.empty(), Optional.of(Wei.of(15)), transactionValidationParams); + blobTx, + OptionalLong.empty(), + Optional.empty(), + Optional.of(Wei.of(15)), + transactionValidationParams); if (!validationResult.isValid()) { System.out.println( validationResult.getInvalidReason() + " " + validationResult.getErrorMessage()); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java index 20e1ec207f4..3af056d4685 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java @@ -410,7 +410,7 @@ private ValidationResultAndAccount validateTransaction( getTransactionValidator() .validate( transaction, - 0, + OptionalLong.empty(), chainHeadBlockHeader.getBaseFee(), Optional.of( Wei.ZERO), // TransactionValidationParams.transactionPool() allows underpriced diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTest.java index 7dcad2441a1..7997c5f4e2a 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTest.java @@ -29,7 +29,6 @@ import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.TRANSACTION_REPLACEMENT_UNDERPRICED; import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.TX_FEECAP_EXCEEDED; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.nullable; @@ -561,11 +560,11 @@ public void shouldNotAddRemoteTransactionsThatAreInvalidAccordingToStateDependen assertTransactionNotPending(transaction1); verify(transactionBroadcaster).onTransactionsAdded(singletonList(transaction0)); verify(transactionValidatorFactory.get()) - .validate(eq(transaction0), anyLong(), any(Optional.class), any(Optional.class), any()); + .validate(eq(transaction0), any(), any(Optional.class), any(Optional.class), any()); verify(transactionValidatorFactory.get()) .validateForSender(eq(transaction0), eq(null), any(TransactionValidationParams.class)); verify(transactionValidatorFactory.get()) - .validate(eq(transaction1), anyLong(), any(Optional.class), any(Optional.class), any()); + .validate(eq(transaction1), any(), any(Optional.class), any(Optional.class), any()); verify(transactionValidatorFactory.get()).validateForSender(eq(transaction1), any(), any()); verifyNoMoreInteractions(transactionValidatorFactory.get()); } @@ -738,7 +737,7 @@ public void shouldCallValidatorWithExpectedValidationParameters() { when(transactionValidatorFactory .get() - .validate(eq(transaction0), anyLong(), any(Optional.class), any(Optional.class), any())) + .validate(eq(transaction0), any(), any(Optional.class), any(Optional.class), any())) .thenReturn(valid()); when(transactionValidatorFactory .get() @@ -1372,7 +1371,7 @@ protected void addAndAssertTransactionViaApiInvalid( protected void givenTransactionIsValid(final Transaction transaction) { when(transactionValidatorFactory .get() - .validate(eq(transaction), anyLong(), any(Optional.class), any(Optional.class), any())) + .validate(eq(transaction), any(), any(Optional.class), any(Optional.class), any())) .thenReturn(valid()); when(transactionValidatorFactory .get() diff --git a/evm/src/main/java/org/hyperledger/besu/evm/EvmSpecVersion.java b/evm/src/main/java/org/hyperledger/besu/evm/EvmSpecVersion.java index bf610efa703..0bdda7c06f0 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/EvmSpecVersion.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/EvmSpecVersion.java @@ -114,7 +114,7 @@ public enum EvmSpecVersion { public static EvmSpecVersion defaultVersion() { EvmSpecVersion answer = null; for (EvmSpecVersion version : EvmSpecVersion.values()) { - if (version.initialHardfork.finalized()) { + if (version.initialHardfork.finalized() && !(version.initialHardfork instanceof OptimismHardforkId)) { answer = version; } } diff --git a/evm/src/main/java/org/hyperledger/besu/evm/MainnetEVMs.java b/evm/src/main/java/org/hyperledger/besu/evm/MainnetEVMs.java index 857504b9e37..c2f8f1c8be3 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/MainnetEVMs.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/MainnetEVMs.java @@ -1008,7 +1008,7 @@ public static EVM fjord( } /** - * Operation registry for cancun's operations. + * Operation registry for fjord's operations. * * @param gasCalculator the gas calculator * @param chainId the chain id @@ -1035,6 +1035,74 @@ public static void registerFjordOperations( registerCancunOperations(registry, gasCalculator, chainID); } + /** + * Granite evm. + * + * @param evmConfiguration the evm configuration + * @return the evm + */ + public static EVM granite(final EvmConfiguration evmConfiguration) { + return granite(DEV_NET_CHAIN_ID, evmConfiguration); + } + + /** + * Granite evm. + * + * @param chainId the chain id + * @param evmConfiguration the evm configuration + * @return the evm + */ + public static EVM granite(final BigInteger chainId, final EvmConfiguration evmConfiguration) { + return granite(new CancunGasCalculator(), chainId, evmConfiguration); + } + + /** + * Granite evm. + * + * @param gasCalculator the gas calculator + * @param chainId the chain id + * @param evmConfiguration the evm configuration + * @return the evm + */ + public static EVM granite( + final GasCalculator gasCalculator, + final BigInteger chainId, + final EvmConfiguration evmConfiguration) { + return new EVM( + graniteOperations(gasCalculator, chainId), + gasCalculator, + evmConfiguration, + EvmSpecVersion.GRANITE); + } + + /** + * Operation registry for granite's operations. + * + * @param gasCalculator the gas calculator + * @param chainId the chain id + * @return the operation registry + */ + public static OperationRegistry graniteOperations( + final GasCalculator gasCalculator, final BigInteger chainId) { + OperationRegistry operationRegistry = new OperationRegistry(); + registerGraniteOperations(operationRegistry, gasCalculator, chainId); + return operationRegistry; + } + + /** + * Register granite operations. + * + * @param registry the registry + * @param gasCalculator the gas calculator + * @param chainID the chain id + */ + public static void registerGraniteOperations( + final OperationRegistry registry, + final GasCalculator gasCalculator, + final BigInteger chainID) { + registerFjordOperations(registry, gasCalculator, chainID); + } + /** * Prague evm. * diff --git a/evm/src/main/java/org/hyperledger/besu/evm/fluent/EVMExecutor.java b/evm/src/main/java/org/hyperledger/besu/evm/fluent/EVMExecutor.java index 95f0a9bc068..503bd1285c5 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/fluent/EVMExecutor.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/fluent/EVMExecutor.java @@ -520,7 +520,7 @@ public static EVMExecutor cancunEOF( */ public static EVMExecutor fjord( final BigInteger chainId, final EvmConfiguration evmConfiguration) { - final EVMExecutor executor = new EVMExecutor(MainnetEVMs.cancun(chainId, evmConfiguration)); + final EVMExecutor executor = new EVMExecutor(MainnetEVMs.fjord(chainId, evmConfiguration)); executor.precompileContractRegistry = MainnetPrecompiledContracts.fjord(executor.evm.getGasCalculator()); return executor; @@ -535,7 +535,7 @@ public static EVMExecutor fjord( */ private static EVMExecutor granite( final BigInteger chainId, final EvmConfiguration evmConfiguration) { - final EVMExecutor executor = new EVMExecutor(MainnetEVMs.cancun(chainId, evmConfiguration)); + final EVMExecutor executor = new EVMExecutor(MainnetEVMs.granite(chainId, evmConfiguration)); executor.precompileContractRegistry = MainnetPrecompiledContracts.granite(executor.evm.getGasCalculator()); return executor; diff --git a/evm/src/test/java/org/hyperledger/besu/evm/fluent/EVMExecutorTest.java b/evm/src/test/java/org/hyperledger/besu/evm/fluent/EVMExecutorTest.java index aa9dcdb23f3..6e763b77d85 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/fluent/EVMExecutorTest.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/fluent/EVMExecutorTest.java @@ -49,7 +49,7 @@ class EVMExecutorTest { @Test void currentEVM() { var subject = EVMExecutor.evm(); - assertThat(subject.getEVMVersion()).isEqualTo(EvmSpecVersion.CANCUN); + assertThat(subject.getEVMVersion()).isEqualTo(EvmSpecVersion.GRANITE); } @ParameterizedTest diff --git a/fork.yaml b/fork.yaml index f8c2146ebbd..a39fe101fc9 100644 --- a/fork.yaml +++ b/fork.yaml @@ -61,7 +61,6 @@ def: gaslimit in increments of 1/1024 of the previous gaslimit. The gaslimit is changed (and limited) through the `SystemConfig` contract. globs: - - "ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/feemarket/BaseFee.java" - "ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/BaseFeeMarket.java" - "ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/CancunFeeMarket.java" - "ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/feemarket/FeeMarket.java"