Add consolidationRequestContract in jsonGenesisConfig (#7647)

* Include consolidationRequestContract in jsonGenesisConfigOptions

Signed-off-by: gconnect <agatevureglory@gmail.com>

* Update changelog and ran spotlessApply

Signed-off-by: gconnect <agatevureglory@gmail.com>

* Rename consolidationRequestPredeployAddress to consolidationRequestContractAddress

Signed-off-by: gconnect <agatevureglory@gmail.com>

* Create request contract addresses class

Signed-off-by: gconnect <agatevureglory@gmail.com>

* Update method calls

Signed-off-by: gconnect <agatevureglory@gmail.com>

* Refactor RequestContractAddresses class and update method calls and test

Signed-off-by: gconnect <agatevureglory@gmail.com>

---------

Signed-off-by: gconnect <agatevureglory@gmail.com>
Co-authored-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
pull/7672/head
Glory Agatevure 2 months ago committed by GitHub
parent 4f07e76a6c
commit 04ba15aa92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      CHANGELOG.md
  2. 7
      config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java
  3. 11
      config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java
  4. 5
      config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java
  5. 27
      config/src/test/java/org/hyperledger/besu/config/GenesisConfigOptionsTest.java
  6. 16
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java
  7. 9
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/ConsolidationRequestProcessor.java
  8. 21
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/MainnetRequestsValidator.java
  9. 61
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/requests/RequestContractAddresses.java
  10. 11
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/PragueRequestsValidatorTest.java

@ -1,6 +1,8 @@
# Changelog # Changelog
## [Unreleased] ## [Unreleased]
- Add configuration of Consolidation Request Contract Address via genesis configuration [#7647](https://github.com/hyperledger/besu/pull/7647)
### Upcoming Breaking Changes ### Upcoming Breaking Changes
- k8s (KUBERNETES) Nat method is now deprecated and will be removed in a future release - k8s (KUBERNETES) Nat method is now deprecated and will be removed in a future release

@ -539,4 +539,11 @@ public interface GenesisConfigOptions {
* @return the deposit address * @return the deposit address
*/ */
Optional<Address> getDepositContractAddress(); Optional<Address> getDepositContractAddress();
/**
* The consolidation request contract address
*
* @return the consolidation request contract address
*/
Optional<Address> getConsolidationRequestContractAddress();
} }

@ -52,6 +52,8 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
private static final String WITHDRAWAL_REQUEST_CONTRACT_ADDRESS_KEY = private static final String WITHDRAWAL_REQUEST_CONTRACT_ADDRESS_KEY =
"withdrawalrequestcontractaddress"; "withdrawalrequestcontractaddress";
private static final String DEPOSIT_CONTRACT_ADDRESS_KEY = "depositcontractaddress"; 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 ObjectNode configRoot;
private final Map<String, String> configOverrides = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); private final Map<String, String> configOverrides = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
@ -453,6 +455,13 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
return inputAddress.map(Address::fromHexString); 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 @Override
public Map<String, Object> asMap() { public Map<String, Object> asMap() {
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
@ -504,6 +513,8 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
getWithdrawalRequestContractAddress() getWithdrawalRequestContractAddress()
.ifPresent(l -> builder.put("withdrawalRequestContractAddress", l)); .ifPresent(l -> builder.put("withdrawalRequestContractAddress", l));
getDepositContractAddress().ifPresent(l -> builder.put("depositContractAddress", l)); getDepositContractAddress().ifPresent(l -> builder.put("depositContractAddress", l));
getConsolidationRequestContractAddress()
.ifPresent(l -> builder.put("consolidationRequestContractAddress", l));
if (isClique()) { if (isClique()) {
builder.put("clique", getCliqueConfigOptions().asMap()); builder.put("clique", getCliqueConfigOptions().asMap());

@ -467,6 +467,11 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions, Cloneable
return Optional.empty(); return Optional.empty();
} }
@Override
public Optional<Address> getConsolidationRequestContractAddress() {
return Optional.empty();
}
/** /**
* Homestead block stub genesis config options. * Homestead block stub genesis config options.
* *

@ -382,6 +382,33 @@ class GenesisConfigOptionsTest {
.containsValue(Address.ZERO); .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) { private GenesisConfigOptions fromConfigOptions(final Map<String, Object> configOptions) {
final ObjectNode rootNode = JsonUtil.createEmptyObjectNode(); final ObjectNode rootNode = JsonUtil.createEmptyObjectNode();
final ObjectNode options = JsonUtil.objectNodeFromMap(configOptions); final ObjectNode options = JsonUtil.objectNodeFromMap(configOptions);

@ -14,10 +14,8 @@
*/ */
package org.hyperledger.besu.ethereum.mainnet; package org.hyperledger.besu.ethereum.mainnet;
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.pragueRequestsProcessors;
import static org.hyperledger.besu.ethereum.mainnet.requests.MainnetRequestsValidator.pragueRequestsValidator; 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.GenesisConfigOptions;
import org.hyperledger.besu.config.PowAlgorithm; import org.hyperledger.besu.config.PowAlgorithm;
@ -41,6 +39,7 @@ import org.hyperledger.besu.ethereum.mainnet.blockhash.PragueBlockHashProcessor;
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket; import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket; import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.ethereum.mainnet.parallelization.MainnetParallelBlockProcessor; import org.hyperledger.besu.ethereum.mainnet.parallelization.MainnetParallelBlockProcessor;
import org.hyperledger.besu.ethereum.mainnet.requests.RequestContractAddresses;
import org.hyperledger.besu.ethereum.privacy.PrivateTransactionProcessor; import org.hyperledger.besu.ethereum.privacy.PrivateTransactionProcessor;
import org.hyperledger.besu.ethereum.privacy.PrivateTransactionValidator; import org.hyperledger.besu.ethereum.privacy.PrivateTransactionValidator;
import org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater; import org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater;
@ -767,12 +766,8 @@ public abstract class MainnetProtocolSpecs {
final boolean isParallelTxProcessingEnabled, final boolean isParallelTxProcessingEnabled,
final MetricsSystem metricsSystem) { final MetricsSystem metricsSystem) {
final Address withdrawalRequestContractAddress = RequestContractAddresses requestContractAddresses =
genesisConfigOptions RequestContractAddresses.fromGenesis(genesisConfigOptions);
.getWithdrawalRequestContractAddress()
.orElse(DEFAULT_WITHDRAWAL_REQUEST_CONTRACT_ADDRESS);
final Address depositContractAddress =
genesisConfigOptions.getDepositContractAddress().orElse(DEFAULT_DEPOSIT_CONTRACT_ADDRESS);
return cancunDefinition( return cancunDefinition(
chainId, chainId,
@ -794,10 +789,9 @@ public abstract class MainnetProtocolSpecs {
.precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::prague) .precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::prague)
// EIP-7002 Withdrawals / EIP-6610 Deposits / EIP-7685 Requests // EIP-7002 Withdrawals / EIP-6610 Deposits / EIP-7685 Requests
.requestsValidator(pragueRequestsValidator(depositContractAddress)) .requestsValidator(pragueRequestsValidator(requestContractAddresses))
// EIP-7002 Withdrawals / EIP-6610 Deposits / EIP-7685 Requests // EIP-7002 Withdrawals / EIP-6610 Deposits / EIP-7685 Requests
.requestProcessorCoordinator( .requestProcessorCoordinator(pragueRequestsProcessors(requestContractAddresses))
pragueRequestsProcessors(withdrawalRequestContractAddress, depositContractAddress))
// change to accept EIP-7702 transactions // change to accept EIP-7702 transactions
.transactionValidatorFactoryBuilder( .transactionValidatorFactoryBuilder(

@ -22,13 +22,18 @@ import org.apache.tuweni.bytes.Bytes;
public class ConsolidationRequestProcessor public class ConsolidationRequestProcessor
extends AbstractSystemCallRequestProcessor<ConsolidationRequest> { extends AbstractSystemCallRequestProcessor<ConsolidationRequest> {
public static final Address CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS = public static final Address CONSOLIDATION_REQUEST_CONTRACT_ADDRESS =
Address.fromHexString("0x00b42dbF2194e931E80326D950320f7d9Dbeac02"); Address.fromHexString("0x00b42dbF2194e931E80326D950320f7d9Dbeac02");
private static final int ADDRESS_BYTES = 20; private static final int ADDRESS_BYTES = 20;
private static final int PUBLIC_KEY_BYTES = 48; private static final int PUBLIC_KEY_BYTES = 48;
private static final int CONSOLIDATION_REQUEST_BYTES_SIZE = private static final int CONSOLIDATION_REQUEST_BYTES_SIZE =
ADDRESS_BYTES + PUBLIC_KEY_BYTES + PUBLIC_KEY_BYTES; 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. * Gets the call address for consolidation requests.
@ -37,7 +42,7 @@ public class ConsolidationRequestProcessor
*/ */
@Override @Override
protected Address getCallAddress() { protected Address getCallAddress() {
return CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS; return consolidationRequestContractAddress;
} }
/** /**

@ -14,27 +14,34 @@
*/ */
package org.hyperledger.besu.ethereum.mainnet.requests; package org.hyperledger.besu.ethereum.mainnet.requests;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.RequestType; import org.hyperledger.besu.datatypes.RequestType;
public class MainnetRequestsValidator { public class MainnetRequestsValidator {
public static RequestsValidatorCoordinator pragueRequestsValidator( public static RequestsValidatorCoordinator pragueRequestsValidator(
final Address depositContractAddress) { final RequestContractAddresses requestContractAddresses) {
return new RequestsValidatorCoordinator.Builder() return new RequestsValidatorCoordinator.Builder()
.addValidator(RequestType.WITHDRAWAL, new WithdrawalRequestValidator()) .addValidator(RequestType.WITHDRAWAL, new WithdrawalRequestValidator())
.addValidator(RequestType.CONSOLIDATION, new ConsolidationRequestValidator()) .addValidator(RequestType.CONSOLIDATION, new ConsolidationRequestValidator())
.addValidator(RequestType.DEPOSIT, new DepositRequestValidator(depositContractAddress)) .addValidator(
RequestType.DEPOSIT,
new DepositRequestValidator(requestContractAddresses.getDepositContractAddress()))
.build(); .build();
} }
public static RequestProcessorCoordinator pragueRequestsProcessors( public static RequestProcessorCoordinator pragueRequestsProcessors(
final Address withdrawalRequestContractAddress, final Address depositContractAddress) { final RequestContractAddresses requestContractAddresses) {
return new RequestProcessorCoordinator.Builder() return new RequestProcessorCoordinator.Builder()
.addProcessor( .addProcessor(
RequestType.WITHDRAWAL, RequestType.WITHDRAWAL,
new WithdrawalRequestProcessor(withdrawalRequestContractAddress)) new WithdrawalRequestProcessor(
.addProcessor(RequestType.CONSOLIDATION, new ConsolidationRequestProcessor()) requestContractAddresses.getWithdrawalRequestContractAddress()))
.addProcessor(RequestType.DEPOSIT, new DepositRequestProcessor(depositContractAddress)) .addProcessor(
RequestType.CONSOLIDATION,
new ConsolidationRequestProcessor(
requestContractAddresses.getConsolidationRequestContractAddress()))
.addProcessor(
RequestType.DEPOSIT,
new DepositRequestProcessor(requestContractAddresses.getDepositContractAddress()))
.build(); .build();
} }
} }

@ -0,0 +1,61 @@
/*
* Copyright contributors to Hyperledger Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.mainnet.requests;
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.WithdrawalRequestProcessor.DEFAULT_WITHDRAWAL_REQUEST_CONTRACT_ADDRESS;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.datatypes.Address;
public class RequestContractAddresses {
private final Address withdrawalRequestContractAddress;
private final Address depositContractAddress;
private final Address consolidationRequestContractAddress;
public RequestContractAddresses(
final Address withdrawalRequestContractAddress,
final Address depositContractAddress,
final Address consolidationRequestContractAddress) {
this.withdrawalRequestContractAddress = withdrawalRequestContractAddress;
this.depositContractAddress = depositContractAddress;
this.consolidationRequestContractAddress = consolidationRequestContractAddress;
}
public static RequestContractAddresses fromGenesis(
final GenesisConfigOptions genesisConfigOptions) {
return new RequestContractAddresses(
genesisConfigOptions
.getWithdrawalRequestContractAddress()
.orElse(DEFAULT_WITHDRAWAL_REQUEST_CONTRACT_ADDRESS),
genesisConfigOptions.getDepositContractAddress().orElse(DEFAULT_DEPOSIT_CONTRACT_ADDRESS),
genesisConfigOptions
.getConsolidationRequestContractAddress()
.orElse(CONSOLIDATION_REQUEST_CONTRACT_ADDRESS));
}
public Address getWithdrawalRequestContractAddress() {
return withdrawalRequestContractAddress;
}
public Address getDepositContractAddress() {
return depositContractAddress;
}
public Address getConsolidationRequestContractAddress() {
return consolidationRequestContractAddress;
}
}

@ -17,8 +17,10 @@ package org.hyperledger.besu.ethereum.mainnet;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode.NONE; import static org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode.NONE;
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.DepositRequestProcessor.DEFAULT_DEPOSIT_CONTRACT_ADDRESS;
import static org.hyperledger.besu.ethereum.mainnet.requests.MainnetRequestsValidator.pragueRequestsValidator; 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 static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.lenient;
@ -31,6 +33,7 @@ import org.hyperledger.besu.ethereum.core.BlockDataGenerator;
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.ethereum.core.Request; import org.hyperledger.besu.ethereum.core.Request;
import org.hyperledger.besu.ethereum.core.WithdrawalRequest; import org.hyperledger.besu.ethereum.core.WithdrawalRequest;
import org.hyperledger.besu.ethereum.mainnet.requests.RequestContractAddresses;
import org.hyperledger.besu.ethereum.mainnet.requests.RequestsValidatorCoordinator; import org.hyperledger.besu.ethereum.mainnet.requests.RequestsValidatorCoordinator;
import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.evm.log.LogsBloomFilter;
@ -52,9 +55,13 @@ class PragueRequestsValidatorTest {
@Mock private ProtocolSchedule protocolSchedule; @Mock private ProtocolSchedule protocolSchedule;
@Mock private ProtocolSpec protocolSpec; @Mock private ProtocolSpec protocolSpec;
@Mock private WithdrawalsValidator withdrawalsValidator; @Mock private WithdrawalsValidator withdrawalsValidator;
private final RequestContractAddresses requestContractAddresses =
new RequestContractAddresses(
DEFAULT_WITHDRAWAL_REQUEST_CONTRACT_ADDRESS,
DEFAULT_DEPOSIT_CONTRACT_ADDRESS,
CONSOLIDATION_REQUEST_CONTRACT_ADDRESS);
RequestsValidatorCoordinator requestValidator = RequestsValidatorCoordinator requestValidator = pragueRequestsValidator(requestContractAddresses);
pragueRequestsValidator(DEFAULT_DEPOSIT_CONTRACT_ADDRESS);
@BeforeEach @BeforeEach
public void setUp() { public void setUp() {

Loading…
Cancel
Save