Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7288: include WithdrawalRequestPredeployAddress in genesis configuration #7356

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,13 @@ default boolean isConsensusMigration() {
*/
boolean isFixedBaseFee();

/**
* The withdrawal request predeploy address
*
* @return the withdrawal request predeploy address
*/
Optional<Address> getWithdrawalRequestContractAddress();

/**
* The deposit contract address that should be in the logger field in Receipt of Deposit
* transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -438,6 +440,13 @@ public boolean isFixedBaseFee() {
return getOptionalBoolean(FIXED_BASE_FEE_KEY).orElse(false);
}

@Override
public Optional<Address> getWithdrawalRequestContractAddress() {
Optional<String> inputAddress =
JsonUtil.getString(configRoot, WITHDRAWAL_REQUEST_CONTRACT_ADDRESS_KEY);
return inputAddress.map(Address::fromHexString);
}

@Override
public Optional<Address> getDepositContractAddress() {
Optional<String> inputAddress = JsonUtil.getString(configRoot, DEPOSIT_CONTRACT_ADDRESS_KEY);
Expand Down Expand Up @@ -492,6 +501,8 @@ public Map<String, Object> 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,11 @@ public List<Long> getForkBlockTimestamps() {
return Collections.emptyList();
}

@Override
public Optional<Address> getWithdrawalRequestContractAddress() {
return Optional.empty();
}

@Override
public Optional<Address> getDepositContractAddress() {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class WithdrawalRequestProcessor
extends AbstractSystemCallRequestProcessor<WithdrawalRequest> {

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;
Expand All @@ -35,14 +35,20 @@ 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.
*
* @return The call address.
*/
@Override
protected Address getCallAddress() {
return WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS;
return withdrawalRequestContractAddress;
}

/**
Expand Down
Loading