From 94b497e261ca87c1811bf4d9f13bf81bdb1787f3 Mon Sep 17 00:00:00 2001 From: Matilda-Clerke Date: Mon, 29 Jul 2024 16:19:11 +1000 Subject: [PATCH] 7288: include WithdrawalRequestPredeployAddress in genesis configuration (#7356) * 7288: include WithdrawalRequestPredeployAddress in genesis configuration Signed-off-by: Matilda Clerke * 7288: Update changelog Signed-off-by: Matilda Clerke * 7288: Fix typo in new variable Signed-off-by: Matilda Clerke * 7288: Rename withdrawalRequestPredeployAddress to withdrawalRequestContractAddress Signed-off-by: Matilda Clerke * 7288: Update changelog to match recent changes Signed-off-by: Matilda Clerke * 5098: Move changelog item to next release Signed-off-by: Matilda Clerke --------- Signed-off-by: Matilda Clerke Signed-off-by: Matilda-Clerke --- CHANGELOG.md | 1 + .../besu/config/GenesisConfigOptions.java | 7 +++++ .../besu/config/JsonGenesisConfigOptions.java | 11 ++++++++ .../besu/config/StubGenesisConfigOptions.java | 5 ++++ .../besu/config/GenesisConfigOptionsTest.java | 26 +++++++++++++++++++ .../mainnet/MainnetProtocolSpecs.java | 8 +++++- .../requests/MainnetRequestsValidator.java | 6 +++-- .../requests/WithdrawalRequestProcessor.java | 10 +++++-- 8 files changed, 69 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04e0f76e4a8..072a84c2ba4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - --Xbonsai-limit-trie-logs-enabled is deprecated, use --bonsai-limit-trie-logs-enabled instead - --Xbonsai-trie-logs-pruning-window-size is deprecated, use --bonsai-trie-logs-pruning-window-size instead - `besu storage x-trie-log` subcommand is deprecated, use `besu storage trie-log` instead +- Allow configuration of Withdrawal Request Contract Address via genesis configuration [#7356](https://github.com/hyperledger/besu/pull/7356) ### Breaking Changes diff --git a/config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java b/config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java index 849b121186e..d6323ee9bfb 100644 --- a/config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java +++ b/config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java @@ -525,6 +525,13 @@ default boolean isConsensusMigration() { */ boolean isFixedBaseFee(); + /** + * The withdrawal request predeploy address + * + * @return the withdrawal request predeploy address + */ + Optional
getWithdrawalRequestContractAddress(); + /** * The deposit contract address that should be in the logger field in Receipt of Deposit * transaction diff --git a/config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java b/config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java index b418a678518..67114b29bf3 100644 --- a/config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java +++ b/config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java @@ -49,6 +49,8 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions { private static final String CHECKPOINT_CONFIG_KEY = "checkpoint"; private static final String ZERO_BASE_FEE_KEY = "zerobasefee"; private static final String FIXED_BASE_FEE_KEY = "fixedbasefee"; + private static final String WITHDRAWAL_REQUEST_CONTRACT_ADDRESS_KEY = + "withdrawalrequestcontractaddress"; private static final String DEPOSIT_CONTRACT_ADDRESS_KEY = "depositcontractaddress"; private final ObjectNode configRoot; @@ -438,6 +440,13 @@ public boolean isFixedBaseFee() { return getOptionalBoolean(FIXED_BASE_FEE_KEY).orElse(false); } + @Override + public Optional
getWithdrawalRequestContractAddress() { + Optional inputAddress = + JsonUtil.getString(configRoot, WITHDRAWAL_REQUEST_CONTRACT_ADDRESS_KEY); + return inputAddress.map(Address::fromHexString); + } + @Override public Optional
getDepositContractAddress() { Optional inputAddress = JsonUtil.getString(configRoot, DEPOSIT_CONTRACT_ADDRESS_KEY); @@ -492,6 +501,8 @@ public Map asMap() { getEvmStackSize().ifPresent(l -> builder.put("evmstacksize", l)); getEcip1017EraRounds().ifPresent(l -> builder.put("ecip1017EraRounds", l)); + getWithdrawalRequestContractAddress() + .ifPresent(l -> builder.put("withdrawalRequestContractAddress", l)); getDepositContractAddress().ifPresent(l -> builder.put("depositContractAddress", l)); if (isClique()) { diff --git a/config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java b/config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java index 24f33310299..efe56a086d0 100644 --- a/config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java +++ b/config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java @@ -457,6 +457,11 @@ public List getForkBlockTimestamps() { return Collections.emptyList(); } + @Override + public Optional
getWithdrawalRequestContractAddress() { + return Optional.empty(); + } + @Override public Optional
getDepositContractAddress() { return Optional.empty(); diff --git a/config/src/test/java/org/hyperledger/besu/config/GenesisConfigOptionsTest.java b/config/src/test/java/org/hyperledger/besu/config/GenesisConfigOptionsTest.java index ed313ad6cfc..219ea4fcf8a 100644 --- a/config/src/test/java/org/hyperledger/besu/config/GenesisConfigOptionsTest.java +++ b/config/src/test/java/org/hyperledger/besu/config/GenesisConfigOptionsTest.java @@ -332,6 +332,32 @@ void asMapIncludesFixedBaseFee() { assertThat(config.asMap()).containsOnlyKeys("fixedBaseFee").containsValue(true); } + @Test + void shouldGetWithdrawalRequestContractAddress() { + final GenesisConfigOptions config = + fromConfigOptions( + singletonMap( + "withdrawalRequestContractAddress", "0x00000000219ab540356cbb839cbe05303d7705fa")); + assertThat(config.getWithdrawalRequestContractAddress()) + .hasValue(Address.fromHexString("0x00000000219ab540356cbb839cbe05303d7705fa")); + } + + @Test + void shouldNotHaveWithdrawalRequestContractAddressWhenEmpty() { + final GenesisConfigOptions config = fromConfigOptions(emptyMap()); + assertThat(config.getWithdrawalRequestContractAddress()).isEmpty(); + } + + @Test + void asMapIncludesWithdrawalRequestContractAddress() { + final GenesisConfigOptions config = + fromConfigOptions(Map.of("withdrawalRequestContractAddress", "0x0")); + + assertThat(config.asMap()) + .containsOnlyKeys("withdrawalRequestContractAddress") + .containsValue(Address.ZERO); + } + @Test void shouldGetDepositContractAddress() { final GenesisConfigOptions config = 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 36d8257ffb9..a96ca58fddb 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 @@ -17,6 +17,7 @@ import static org.hyperledger.besu.ethereum.mainnet.requests.DepositRequestProcessor.DEFAULT_DEPOSIT_CONTRACT_ADDRESS; import static org.hyperledger.besu.ethereum.mainnet.requests.MainnetRequestsValidator.pragueRequestsProcessors; import static org.hyperledger.besu.ethereum.mainnet.requests.MainnetRequestsValidator.pragueRequestsValidator; +import static org.hyperledger.besu.ethereum.mainnet.requests.WithdrawalRequestProcessor.DEFAULT_WITHDRAWAL_REQUEST_CONTRACT_ADDRESS; import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.config.PowAlgorithm; @@ -766,6 +767,10 @@ static ProtocolSpecBuilder pragueDefinition( final boolean isParallelTxProcessingEnabled, final MetricsSystem metricsSystem) { + final Address withdrawalRequestContractAddress = + genesisConfigOptions + .getWithdrawalRequestContractAddress() + .orElse(DEFAULT_WITHDRAWAL_REQUEST_CONTRACT_ADDRESS); final Address depositContractAddress = genesisConfigOptions.getDepositContractAddress().orElse(DEFAULT_DEPOSIT_CONTRACT_ADDRESS); @@ -791,7 +796,8 @@ static ProtocolSpecBuilder pragueDefinition( // EIP-7002 Withdrawals / EIP-6610 Deposits / EIP-7685 Requests .requestsValidator(pragueRequestsValidator(depositContractAddress)) // EIP-7002 Withdrawals / EIP-6610 Deposits / EIP-7685 Requests - .requestProcessorCoordinator(pragueRequestsProcessors(depositContractAddress)) + .requestProcessorCoordinator( + pragueRequestsProcessors(withdrawalRequestContractAddress, depositContractAddress)) // change to accept EIP-7702 transactions .transactionValidatorFactoryBuilder( diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/MainnetRequestsValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/MainnetRequestsValidator.java index d855544edee..6e61a0343c3 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/MainnetRequestsValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/MainnetRequestsValidator.java @@ -28,9 +28,11 @@ public static RequestsValidatorCoordinator pragueRequestsValidator( } public static RequestProcessorCoordinator pragueRequestsProcessors( - final Address depositContractAddress) { + final Address withdrawalRequestContractAddress, final Address depositContractAddress) { return new RequestProcessorCoordinator.Builder() - .addProcessor(RequestType.WITHDRAWAL, new WithdrawalRequestProcessor()) + .addProcessor( + RequestType.WITHDRAWAL, + new WithdrawalRequestProcessor(withdrawalRequestContractAddress)) .addProcessor(RequestType.CONSOLIDATION, new ConsolidationRequestProcessor()) .addProcessor(RequestType.DEPOSIT, new DepositRequestProcessor(depositContractAddress)) .build(); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/WithdrawalRequestProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/WithdrawalRequestProcessor.java index b230a6d6103..d4021c9a104 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/WithdrawalRequestProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/WithdrawalRequestProcessor.java @@ -26,7 +26,7 @@ public class WithdrawalRequestProcessor extends AbstractSystemCallRequestProcessor { - public static final Address WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS = + public static final Address DEFAULT_WITHDRAWAL_REQUEST_CONTRACT_ADDRESS = Address.fromHexString("0x00A3ca265EBcb825B45F985A16CEFB49958cE017"); private static final int ADDRESS_BYTES = 20; @@ -35,6 +35,12 @@ public class WithdrawalRequestProcessor private static final int WITHDRAWAL_REQUEST_BYTES_SIZE = ADDRESS_BYTES + PUBLIC_KEY_BYTES + AMOUNT_BYTES; + private final Address withdrawalRequestContractAddress; + + public WithdrawalRequestProcessor(final Address withdrawalRequestContractAddress) { + this.withdrawalRequestContractAddress = withdrawalRequestContractAddress; + } + /** * Gets the call address for withdrawal requests. * @@ -42,7 +48,7 @@ public class WithdrawalRequestProcessor */ @Override protected Address getCallAddress() { - return WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS; + return withdrawalRequestContractAddress; } /**