diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AuthorityProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AuthorityProcessor.java index 7a53ecce388..f79e2c98e3a 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AuthorityProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AuthorityProcessor.java @@ -31,10 +31,10 @@ public class AuthorityProcessor { private static final Logger LOG = LoggerFactory.getLogger(AuthorityProcessor.class); - private final BigInteger chainId; + private final Optional maybeChainId; - public AuthorityProcessor(final BigInteger chainId) { - this.chainId = chainId; + public AuthorityProcessor(final Optional maybeChainId) { + this.maybeChainId = maybeChainId; } public void addContractToAuthority( @@ -53,9 +53,9 @@ public void addContractToAuthority( authorityAddress -> { LOG.trace("Set code authority: {}", authorityAddress); - if (!chainId.equals(BigInteger.ZERO) + if (maybeChainId.isPresent() && !payload.chainId().equals(BigInteger.ZERO) - && !chainId.equals(payload.chainId())) { + && !maybeChainId.get().equals(payload.chainId())) { return; } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java index 710c5743cd3..aec844894f7 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java @@ -155,8 +155,7 @@ public static ProtocolSpecBuilder atlantisDefinition( false, evmConfiguration.evmStackSize(), feeMarket, - CoinbaseFeePriceCalculator.frontier(), - new AuthorityProcessor(chainId.orElse(BigInteger.ZERO)))) + CoinbaseFeePriceCalculator.frontier())) .name("Atlantis"); } @@ -290,8 +289,7 @@ public static ProtocolSpecBuilder spiralDefinition( true, evmConfiguration.evmStackSize(), feeMarket, - CoinbaseFeePriceCalculator.frontier(), - new AuthorityProcessor(chainId.orElse(BigInteger.ZERO)))) + CoinbaseFeePriceCalculator.frontier())) .name("Spiral"); } } 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 f5c1f3c3549..6f09df923eb 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 @@ -131,8 +131,7 @@ public static ProtocolSpecBuilder frontierDefinition(final EvmConfiguration evmC false, evmConfiguration.evmStackSize(), FeeMarket.legacy(), - CoinbaseFeePriceCalculator.frontier(), - new AuthorityProcessor(BigInteger.ZERO))) + CoinbaseFeePriceCalculator.frontier())) .privateTransactionProcessorBuilder( (transactionValidatorFactory, contractCreationProcessor, @@ -265,8 +264,7 @@ public static ProtocolSpecBuilder spuriousDragonDefinition( false, evmConfiguration.evmStackSize(), feeMarket, - CoinbaseFeePriceCalculator.frontier(), - new AuthorityProcessor(chainId.orElse(BigInteger.ZERO)))) + CoinbaseFeePriceCalculator.frontier())) .name("SpuriousDragon"); } @@ -427,8 +425,7 @@ static ProtocolSpecBuilder londonDefinition( false, evmConfiguration.evmStackSize(), feeMarket, - CoinbaseFeePriceCalculator.eip1559(), - new AuthorityProcessor(chainId.orElse(BigInteger.ZERO)))) + CoinbaseFeePriceCalculator.eip1559())) .contractCreationProcessorBuilder( evm -> new ContractCreationProcessor( @@ -528,8 +525,7 @@ static ProtocolSpecBuilder shanghaiDefinition( true, evmConfiguration.evmStackSize(), feeMarket, - CoinbaseFeePriceCalculator.eip1559(), - new AuthorityProcessor(chainId.orElse(BigInteger.ZERO)))) + CoinbaseFeePriceCalculator.eip1559())) // Contract creation rules for EIP-3860 Limit and meter intitcode .transactionValidatorFactoryBuilder( (evm, gasLimitCalculator, feeMarket) -> @@ -600,7 +596,7 @@ static ProtocolSpecBuilder cancunDefinition( evmConfiguration.evmStackSize(), feeMarket, CoinbaseFeePriceCalculator.eip1559(), - new AuthorityProcessor(chainId.orElse(BigInteger.ZERO)))) + new AuthorityProcessor(chainId))) // change to check for max blob gas per block for EIP-4844 .transactionValidatorFactoryBuilder( (evm, gasLimitCalculator, feeMarket) -> 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 5984be0e1d5..9ad1db7d896 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 @@ -81,7 +81,30 @@ public class MainnetTransactionProcessor { protected final FeeMarket feeMarket; private final CoinbaseFeePriceCalculator coinbaseFeePriceCalculator; - private final AuthorityProcessor authorityProcessor; + private final Optional maybeAuthorityProcessor; + + public MainnetTransactionProcessor( + final GasCalculator gasCalculator, + final TransactionValidatorFactory transactionValidatorFactory, + final AbstractMessageProcessor contractCreationProcessor, + final AbstractMessageProcessor messageCallProcessor, + final boolean clearEmptyAccounts, + final boolean warmCoinbase, + final int maxStackSize, + final FeeMarket feeMarket, + final CoinbaseFeePriceCalculator coinbaseFeePriceCalculator) { + this( + gasCalculator, + transactionValidatorFactory, + contractCreationProcessor, + messageCallProcessor, + clearEmptyAccounts, + warmCoinbase, + maxStackSize, + feeMarket, + coinbaseFeePriceCalculator, + null); + } public MainnetTransactionProcessor( final GasCalculator gasCalculator, @@ -93,7 +116,7 @@ public MainnetTransactionProcessor( final int maxStackSize, final FeeMarket feeMarket, final CoinbaseFeePriceCalculator coinbaseFeePriceCalculator, - final AuthorityProcessor authorityProcessor) { + final AuthorityProcessor maybeAuthorityProcessor) { this.gasCalculator = gasCalculator; this.transactionValidatorFactory = transactionValidatorFactory; this.contractCreationProcessor = contractCreationProcessor; @@ -103,7 +126,7 @@ public MainnetTransactionProcessor( this.maxStackSize = maxStackSize; this.feeMarket = feeMarket; this.coinbaseFeePriceCalculator = coinbaseFeePriceCalculator; - this.authorityProcessor = authorityProcessor; + this.maybeAuthorityProcessor = Optional.ofNullable(maybeAuthorityProcessor); } /** @@ -386,7 +409,13 @@ public TransactionProcessingResult processTransaction( commonMessageFrameBuilder.versionedHashes( Optional.of(transaction.getVersionedHashes().get().stream().toList())); } else if (transaction.getAuthorizationList().isPresent()) { - authorityProcessor.addContractToAuthority(worldUpdater, authorizedCodeService, transaction); + if (maybeAuthorityProcessor.isEmpty()) { + throw new RuntimeException("Authority processor is required for 7702 transactions"); + } + + maybeAuthorityProcessor + .get() + .addContractToAuthority(worldUpdater, authorizedCodeService, transaction); addressList.addAll(authorizedCodeService.getAuthorities()); } else { commonMessageFrameBuilder.versionedHashes(Optional.empty()); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java index d901183187f..b2f5718dad3 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java @@ -89,7 +89,7 @@ MainnetTransactionProcessor createTransactionProcessor(final boolean warmCoinbas MAX_STACK_SIZE, FeeMarket.legacy(), CoinbaseFeePriceCalculator.frontier(), - new AuthorityProcessor(BigInteger.ONE)); + new AuthorityProcessor(Optional.of(BigInteger.ONE))); } @Test