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

[Merge] ExecutionEngineOptions added #4403

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import tech.pegasys.teku.networking.eth2.P2PConfig;
import tech.pegasys.teku.networks.Eth2NetworkConfiguration;
import tech.pegasys.teku.services.powchain.PowchainConfiguration;
import tech.pegasys.teku.services.powchain.execution.ExecutionEngineConfiguration;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.storage.store.StoreConfig;
import tech.pegasys.teku.sync.SyncConfig;
Expand All @@ -36,6 +37,7 @@ public class BeaconChainConfiguration {
private final LoggingConfig loggingConfig;
private final StoreConfig storeConfig;
private final PowchainConfiguration powchainConfiguration;
private final ExecutionEngineConfiguration executionEngineConfiguration;
private final Spec spec;

public BeaconChainConfiguration(
Expand All @@ -47,6 +49,7 @@ public BeaconChainConfiguration(
final SyncConfig syncConfig,
final BeaconRestApiConfig beaconRestApiConfig,
final PowchainConfiguration powchainConfiguration,
final ExecutionEngineConfiguration executionEngineConfiguration,
final LoggingConfig loggingConfig,
final StoreConfig storeConfig,
final Spec spec) {
Expand All @@ -58,6 +61,7 @@ public BeaconChainConfiguration(
this.syncConfig = syncConfig;
this.beaconRestApiConfig = beaconRestApiConfig;
this.powchainConfiguration = powchainConfiguration;
this.executionEngineConfiguration = executionEngineConfiguration;
this.loggingConfig = loggingConfig;
this.storeConfig = storeConfig;
this.spec = spec;
Expand Down Expand Up @@ -99,6 +103,10 @@ public PowchainConfiguration powchainConfig() {
return powchainConfiguration;
}

public ExecutionEngineConfiguration executionEngineConfiguration() {
return executionEngineConfiguration;
}

public LoggingConfig loggingConfig() {
return loggingConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel;
import tech.pegasys.teku.spec.logic.SpecLogic;
import tech.pegasys.teku.ssz.type.Bytes20;
import tech.pegasys.teku.statetransition.EpochCachePrimer;
import tech.pegasys.teku.statetransition.OperationPool;
import tech.pegasys.teku.statetransition.OperationsReOrgManager;
Expand Down Expand Up @@ -484,6 +485,11 @@ public void initValidatorApiHandler() {
depositProvider,
eth1DataCache,
VersionProvider.getDefaultGraffiti(),
beaconConfig
.executionEngineConfiguration()
.getFeeRecipient()
.map(eth1Address -> Bytes20.fromHexString(eth1Address.toHexString()))
.orElse(Bytes20.ZERO),
spec,
executionEngineChannel);
syncCommitteeSubscriptionManager =
Expand Down Expand Up @@ -805,9 +811,12 @@ private void initOperationsReOrgManager() {
private void createExecutionEngineChannel() {
Optional<SpecLogic> specLogic = spec.getSpecLogicForMilestone(SpecMilestone.MERGE);
if (specLogic.isPresent() && beaconConfig.powchainConfig().isEnabled()) {
executionEngineChannel =
ExecutionEngineChannelImpl.create(
beaconConfig.powchainConfig().getEth1Endpoints().get(0));
final String eth1Endpoint = beaconConfig.powchainConfig().getEth1Endpoints().get(0);
Optional<String> eeEndpoint = Optional.empty();
if (beaconConfig.executionEngineConfiguration().isEnabled()) {
eeEndpoint = Optional.of(beaconConfig.executionEngineConfiguration().getEndpoints().get(0));
}
executionEngineChannel = ExecutionEngineChannelImpl.create(eth1Endpoint, eeEndpoint);
} else {
executionEngineChannel = ExecutionEngineChannelImpl.createStub();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ public class ExecutionEngineChannelImpl implements ExecutionEngineChannel {

private final ExecutionEngineClient executionEngineClient;

public static ExecutionEngineChannelImpl create(String eth1EngineEndpoint) {
checkNotNull(eth1EngineEndpoint);
return new ExecutionEngineChannelImpl(new Web3JExecutionEngineClient(eth1EngineEndpoint));
public static ExecutionEngineChannelImpl create(
String eth1Endpoint, Optional<String> eeEndpoint) {
checkNotNull(eth1Endpoint);
checkNotNull(eeEndpoint);
return new ExecutionEngineChannelImpl(new Web3JExecutionEngineClient(eth1Endpoint, eeEndpoint));
}

public static ExecutionEngineChannelImpl createStub() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright 2021 ConsenSys AG.
*
* 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.
*/

package tech.pegasys.teku.services.powchain.execution;

import static com.google.common.base.Preconditions.checkNotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.datastructures.eth1.Eth1Address;

public class ExecutionEngineConfiguration {

private final Spec spec;
private final List<String> endpoints;
private final Optional<Eth1Address> feeRecipient;

private ExecutionEngineConfiguration(
final Spec spec, final List<String> endpoints, final Optional<Eth1Address> feeRecipient) {
this.spec = spec;
this.endpoints = endpoints;
this.feeRecipient = feeRecipient;
}

public static Builder builder() {
return new Builder();
}

public boolean isEnabled() {
return !endpoints.isEmpty();
}

public Spec getSpec() {
return spec;
}

public List<String> getEndpoints() {
return endpoints;
}

public Optional<Eth1Address> getFeeRecipient() {
return feeRecipient;
}

public static class Builder {
private Spec spec;
private List<String> endpoints = new ArrayList<>();
private Optional<Eth1Address> feeRecipient;

private Builder() {}

public ExecutionEngineConfiguration build() {
validate();
return new ExecutionEngineConfiguration(spec, endpoints, feeRecipient);
}

private void validate() {
checkNotNull(spec, "Must specify a spec");
}

public Builder endpoints(final List<String> endpoints) {
checkNotNull(endpoints);
this.endpoints = endpoints.stream().filter(s -> !s.isBlank()).collect(Collectors.toList());
return this;
}

public Builder feeRecipient(final Eth1Address feeRecipient) {
this.feeRecipient = Optional.ofNullable(feeRecipient);
return this;
}

public Builder feeRecipient(final String feeRecipient) {
if (feeRecipient == null) {
this.feeRecipient = Optional.empty();
} else {
this.feeRecipient = Optional.of(Eth1Address.fromHexString(feeRecipient));
}
return this;
}

public Builder specProvider(final Spec spec) {
this.spec = spec;
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@

public class Web3JExecutionEngineClient implements ExecutionEngineClient {

private final HttpService web3jService;
private final Web3j web3j;
private final Web3j eth1Web3j;
private final HttpService eeWeb3jService;

public Web3JExecutionEngineClient(String eth1Endpoint) {
this.web3jService = new HttpService(eth1Endpoint);
this.web3j = Web3j.build(web3jService);
public Web3JExecutionEngineClient(String eth1Endpoint, Optional<String> maybeEeEndpoint) {
HttpService eth1Web3jService = new HttpService(eth1Endpoint);
this.eth1Web3j = Web3j.build(eth1Web3jService);
this.eeWeb3jService = maybeEeEndpoint.map(HttpService::new).orElse(eth1Web3jService);
}

@Override
Expand All @@ -49,7 +50,7 @@ public SafeFuture<Response<PreparePayloadResponse>> preparePayload(
new Request<>(
"engine_preparePayload",
Collections.singletonList(request),
web3jService,
eeWeb3jService,
PreparePayloadWeb3jResponse.class);
return doRequest(web3jRequest);
}
Expand All @@ -60,7 +61,7 @@ public SafeFuture<Response<ExecutionPayload>> getPayload(UInt64 payloadId) {
new Request<>(
"engine_getPayload",
Collections.singletonList(payloadId.toString()),
web3jService,
eeWeb3jService,
GetPayloadWeb3jResponse.class);
return doRequest(web3jRequest);
}
Expand All @@ -71,7 +72,7 @@ public SafeFuture<Response<ExecutePayloadResponse>> executePayload(ExecutionPayl
new Request<>(
"engine_executePayload",
Collections.singletonList(request),
web3jService,
eeWeb3jService,
NewBlockWeb3jResponse.class);
return doRequest(web3jRequest);
}
Expand All @@ -83,7 +84,7 @@ public SafeFuture<Response<GenericResponse>> forkChoiceUpdated(
new Request<>(
"engine_forkChoiceUpdated",
List.of(headBlockHash.toHexString(), finalizedBlockHash.toHexString()),
web3jService,
eeWeb3jService,
GenericWeb3jResponse.class);
return doRequest(web3jRequest);
}
Expand All @@ -95,22 +96,22 @@ public SafeFuture<Response<GenericResponse>> consensusValidated(
new Request<>(
"engine_consensusValidated",
List.of(blockHash.toHexString(), validationResult),
web3jService,
eeWeb3jService,
GenericWeb3jResponse.class);
return doRequest(web3jRequest);
}

@Override
public SafeFuture<Optional<EthBlock.Block>> getPowBlock(Bytes32 blockHash) {
return SafeFuture.of(web3j.ethGetBlockByHash(blockHash.toHexString(), false).sendAsync())
return SafeFuture.of(eth1Web3j.ethGetBlockByHash(blockHash.toHexString(), false).sendAsync())
.thenApply(EthBlock::getBlock)
.thenApply(Optional::ofNullable);
}

@Override
public SafeFuture<EthBlock.Block> getPowChainHead() {
return SafeFuture.of(
web3j.ethGetBlockByNumber(DefaultBlockParameterName.LATEST, false).sendAsync())
eth1Web3j.ethGetBlockByNumber(DefaultBlockParameterName.LATEST, false).sendAsync())
.thenApply(EthBlock::getBlock);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import tech.pegasys.teku.cli.options.DataStorageOptions;
import tech.pegasys.teku.cli.options.DepositOptions;
import tech.pegasys.teku.cli.options.Eth2NetworkOptions;
import tech.pegasys.teku.cli.options.ExecutionEngineOptions;
import tech.pegasys.teku.cli.options.InteropOptions;
import tech.pegasys.teku.cli.options.LoggingOptions;
import tech.pegasys.teku.cli.options.MetricsOptions;
Expand Down Expand Up @@ -157,6 +158,9 @@ private static class ConfigFileCommand {
@Mixin(name = "Deposit")
private DepositOptions depositOptions;

@Mixin(name = "Execution Engine")
private ExecutionEngineOptions executionEngineOptionsptions;

@Mixin(name = "Logging")
private LoggingOptions loggingOptions;

Expand Down Expand Up @@ -343,6 +347,7 @@ protected TekuConfiguration tekuConfiguration() {
// Eth2NetworkOptions configures network defaults across builders, so configure this first
eth2NetworkOptions.configure(builder);
depositOptions.configure(builder);
executionEngineOptionsptions.configure(builder);
weakSubjectivityOptions.configure(builder);
validatorOptions.configure(builder);
dataOptions.configure(builder);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2020 ConsenSys AG.
*
* 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.
*/

package tech.pegasys.teku.cli.options;

import java.util.ArrayList;
import java.util.List;
import picocli.CommandLine.Option;
import tech.pegasys.teku.config.TekuConfiguration;

public class ExecutionEngineOptions {

@Option(
names = {"--ee-endpoints", "--ee-endpoint"},
paramLabel = "<NETWORK>",
description = "URLs for Execution Engine nodes.",
hidden = true,
split = ",",
arity = "0..*")
private List<String> eeEndpoints = new ArrayList<>();

@Option(
names = {"--ee-fee-recipient-address"},
paramLabel = "<ADDRESS>",
description =
"Suggested fee recipient sent to the execution engine, which could use it as coinbase when producing a new execution block.",
hidden = true,
arity = "0..1")
private String feeRecipient = null;

public void configure(final TekuConfiguration.Builder builder) {
builder.executionEngine(b -> b.endpoints(eeEndpoints).feeRecipient(feeRecipient));
}
}
Loading