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

Add consolidationRequestContract in jsonGenesisConfig #7647

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## [Unreleased]
- Add configuration of Consolidation Request Contract Address via genesis configuration [#7647](https://github.com/hyperledger/besu/pull/7647)


### Upcoming Breaking Changes
- k8s (KUBERNETES) Nat method is now deprecated and will be removed in a future release
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,4 +539,11 @@ default boolean isConsensusMigration() {
* @return the deposit address
*/
Optional<Address> getDepositContractAddress();

/**
* The consolidation request contract address
*
* @return the consolidation request contract address
*/
Optional<Address> getConsolidationRequestContractAddress();
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
private static final String WITHDRAWAL_REQUEST_CONTRACT_ADDRESS_KEY =
"withdrawalrequestcontractaddress";
private static final String DEPOSIT_CONTRACT_ADDRESS_KEY = "depositcontractaddress";
private static final String CONSOLIDATION_REQUEST_CONTRACT_ADDRESS_KEY =
"consolidationrequestcontractaddress";

private final ObjectNode configRoot;
private final Map<String, String> configOverrides = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
Expand Down Expand Up @@ -453,6 +455,13 @@ public Optional<Address> getDepositContractAddress() {
return inputAddress.map(Address::fromHexString);
}

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

@Override
public Map<String, Object> asMap() {
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
Expand Down Expand Up @@ -504,6 +513,8 @@ public Map<String, Object> asMap() {
getWithdrawalRequestContractAddress()
.ifPresent(l -> builder.put("withdrawalRequestContractAddress", l));
getDepositContractAddress().ifPresent(l -> builder.put("depositContractAddress", l));
getConsolidationRequestContractAddress()
.ifPresent(l -> builder.put("consolidationRequestContractAddress", l));

if (isClique()) {
builder.put("clique", getCliqueConfigOptions().asMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ public Optional<Address> getDepositContractAddress() {
return Optional.empty();
}

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

/**
* Homestead block stub genesis config options.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,33 @@ void asMapIncludesDepositContractAddress() {
.containsValue(Address.ZERO);
}

@Test
void shouldGetConsolidationRequestContractAddress() {
final GenesisConfigOptions config =
fromConfigOptions(
singletonMap(
"consolidationRequestContractAddress",
"0x00000000219ab540356cbb839cbe05303d7705fa"));
assertThat(config.getConsolidationRequestContractAddress())
.hasValue(Address.fromHexString("0x00000000219ab540356cbb839cbe05303d7705fa"));
}

@Test
void shouldNotHaveConsolidationRequestContractAddressWhenEmpty() {
final GenesisConfigOptions config = fromConfigOptions(emptyMap());
assertThat(config.getConsolidationRequestContractAddress()).isEmpty();
}

@Test
void asMapIncludesConsolidationRequestContractAddress() {
final GenesisConfigOptions config =
fromConfigOptions(Map.of("consolidationRequestContractAddress", "0x0"));

assertThat(config.asMap())
.containsOnlyKeys("consolidationRequestContractAddress")
.containsValue(Address.ZERO);
}

private GenesisConfigOptions fromConfigOptions(final Map<String, Object> configOptions) {
final ObjectNode rootNode = JsonUtil.createEmptyObjectNode();
final ObjectNode options = JsonUtil.objectNodeFromMap(configOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.ethereum.mainnet;

import static org.hyperledger.besu.ethereum.mainnet.requests.ConsolidationRequestProcessor.CONSOLIDATION_REQUEST_CONTRACT_ADDRESS;
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;
Expand Down Expand Up @@ -774,6 +775,11 @@ static ProtocolSpecBuilder pragueDefinition(
final Address depositContractAddress =
genesisConfigOptions.getDepositContractAddress().orElse(DEFAULT_DEPOSIT_CONTRACT_ADDRESS);

final Address consolidationRequestContractAddress =
genesisConfigOptions
.getConsolidationRequestContractAddress()
.orElse(CONSOLIDATION_REQUEST_CONTRACT_ADDRESS);

return cancunDefinition(
chainId,
enableRevertReason,
Expand All @@ -795,9 +801,13 @@ static ProtocolSpecBuilder pragueDefinition(

// EIP-7002 Withdrawals / EIP-6610 Deposits / EIP-7685 Requests
.requestsValidator(pragueRequestsValidator(depositContractAddress))
.requestsValidator(pragueRequestsValidator(consolidationRequestContractAddress))
// EIP-7002 Withdrawals / EIP-6610 Deposits / EIP-7685 Requests
.requestProcessorCoordinator(
pragueRequestsProcessors(withdrawalRequestContractAddress, depositContractAddress))
pragueRequestsProcessors(
withdrawalRequestContractAddress,
depositContractAddress,
consolidationRequestContractAddress))
gconnect marked this conversation as resolved.
Show resolved Hide resolved

// change to accept EIP-7702 transactions
.transactionValidatorFactoryBuilder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@

public class ConsolidationRequestProcessor
extends AbstractSystemCallRequestProcessor<ConsolidationRequest> {
public static final Address CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS =
public static final Address CONSOLIDATION_REQUEST_CONTRACT_ADDRESS =
Address.fromHexString("0x00b42dbF2194e931E80326D950320f7d9Dbeac02");

private static final int ADDRESS_BYTES = 20;
private static final int PUBLIC_KEY_BYTES = 48;
private static final int CONSOLIDATION_REQUEST_BYTES_SIZE =
ADDRESS_BYTES + PUBLIC_KEY_BYTES + PUBLIC_KEY_BYTES;
private final Address consolidationRequestContractAddress;

public ConsolidationRequestProcessor(final Address consolidationRequestContractAddress) {
this.consolidationRequestContractAddress = consolidationRequestContractAddress;
}

/**
* Gets the call address for consolidation requests.
Expand All @@ -37,7 +42,7 @@ public class ConsolidationRequestProcessor
*/
@Override
protected Address getCallAddress() {
return CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS;
return consolidationRequestContractAddress;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ public static RequestsValidatorCoordinator pragueRequestsValidator(
}

public static RequestProcessorCoordinator pragueRequestsProcessors(
final Address withdrawalRequestContractAddress, final Address depositContractAddress) {
final Address withdrawalRequestContractAddress,
final Address depositContractAddress,
final Address consolidationRequestContractAddress) {
gconnect marked this conversation as resolved.
Show resolved Hide resolved
return new RequestProcessorCoordinator.Builder()
.addProcessor(
RequestType.WITHDRAWAL,
new WithdrawalRequestProcessor(withdrawalRequestContractAddress))
.addProcessor(RequestType.CONSOLIDATION, new ConsolidationRequestProcessor())
.addProcessor(
RequestType.CONSOLIDATION,
new ConsolidationRequestProcessor(consolidationRequestContractAddress))
.addProcessor(RequestType.DEPOSIT, new DepositRequestProcessor(depositContractAddress))
.build();
}
Expand Down
Loading