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] Make Teku working with Geth EE #4431

Merged
merged 19 commits into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1e8da2e
Fix EE API `fee_recipient` field serializer
Nashatyrev Sep 29, 2021
1d816ee
Genesis ExecutionPayload should refer eth1 block in `blockHash` field…
Nashatyrev Sep 30, 2021
6679a56
Minor: add `ExecutionPayload.extraData` to equals/hashCode/toString
Nashatyrev Sep 30, 2021
9d26eb2
Rename `ExecutionPayload.receiptsRoot` to `receiptRoot`
Nashatyrev Sep 30, 2021
a696f41
Fix `ExecutionPayload.baseFeePerGas` constructor property name
Nashatyrev Sep 30, 2021
c762896
Add null checks for fields in the `ExecutionPayload` constructor
Nashatyrev Sep 30, 2021
10ceb9e
Fix `ExecutionPayload.baseFeePerGas` field serializer
Nashatyrev Sep 30, 2021
ad809ef
Adjust GENESIS_GAS_LIMIT
Nashatyrev Sep 30, 2021
ddc6010
Make Bytes32Deserializer more lenient
Nashatyrev Sep 30, 2021
f589f54
Fix engine_forkchoiceUpdated and engine_consensusValidated to pass re…
Nashatyrev Sep 30, 2021
6dc9e2b
Allow returning null in response payload for one-way functions
Nashatyrev Sep 30, 2021
52ce0fd
Rename engine_forkChoiceUpdated to engine_forkchoiceUpdated
Nashatyrev Sep 30, 2021
03e4665
engine_preparePayload returns UInt not an object containing UInt
Nashatyrev Sep 30, 2021
c933646
Spotless
Nashatyrev Sep 30, 2021
b212249
Revert "engine_preparePayload returns UInt not an object containing U…
Nashatyrev Oct 1, 2021
7467c11
Fix PreparePayloadResponse deserialization
Nashatyrev Oct 1, 2021
a3d1ee0
Fix `getPayload` argument serialization
Nashatyrev Oct 1, 2021
e3f62a6
Spotless
Nashatyrev Oct 1, 2021
8821206
Return back `GENESIS_GAS_LIMIT` constant value as per spec
Nashatyrev Oct 1, 2021
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 @@ -88,7 +88,7 @@ public void updateCandidateState(
stateMerge ->
stateMerge.setLatestExecutionPayloadHeader(
new ExecutionPayloadHeader(
eth1BlockHash,
Bytes32.ZERO,
Bytes20.ZERO,
Bytes32.ZERO,
Bytes32.ZERO,
Expand All @@ -100,7 +100,7 @@ public void updateCandidateState(
eth1Timestamp,
Bytes.EMPTY,
specConfig.toVersionMerge().orElseThrow().getGenesisBaseFeePerGas(),
Bytes32.ZERO,
eth1BlockHash,
Bytes32.ZERO)));

// Process deposits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import tech.pegasys.teku.services.powchain.execution.client.schema.ExecutePayloadResponse;
import tech.pegasys.teku.services.powchain.execution.client.schema.ExecutionPayload;
import tech.pegasys.teku.services.powchain.execution.client.schema.PreparePayloadRequest;
import tech.pegasys.teku.services.powchain.execution.client.schema.PreparePayloadResponse;
import tech.pegasys.teku.services.powchain.execution.client.schema.Response;
import tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel;
import tech.pegasys.teku.ssz.type.Bytes20;
Expand Down Expand Up @@ -60,7 +59,7 @@ public ExecutionEngineChannelImpl(ExecutionEngineClient executionEngineClient) {

private static <K> K unwrapResponseOrThrow(Response<K> response) {
checkArgument(
response.getPayload() != null, "Invalid remote response: %s", response.getReason());
response.getReason() == null, "Invalid remote response: %s", response.getReason());
return response.getPayload();
}

Expand All @@ -74,8 +73,6 @@ public SafeFuture<UInt64> preparePayload(
Bytes32 parentHash, UInt64 timestamp, Bytes32 random, Bytes20 feeRecipient) {
return executionEngineClient
.preparePayload(new PreparePayloadRequest(parentHash, timestamp, random, feeRecipient))
.thenApply(ExecutionEngineChannelImpl::unwrapResponseOrThrow)
.thenApply(PreparePayloadResponse::getPayloadId)
.thenPeek(
getPayloadId ->
printConsole(
Expand Down Expand Up @@ -117,7 +114,7 @@ public SafeFuture<ExecutionPayloadStatus> executePayload(
@Override
public SafeFuture<Void> forkChoiceUpdated(Bytes32 bestBlockHash, Bytes32 finalizedBlockHash) {
return executionEngineClient
.forkChoiceUpdated(bestBlockHash, finalizedBlockHash)
.forkchoiceUpdated(bestBlockHash, finalizedBlockHash)
.thenApply(ExecutionEngineChannelImpl::unwrapResponseOrThrow)
.thenPeek(
__ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void chainHeadUpdated(
updateForkChoice(
headBlockRoot, state.getFinalized_checkpoint().getRoot()))
.orElseGet(() -> SafeFuture.completedFuture(null)))
.finish(err -> LOG.warn("forkChoiceUpdated failed", err));
.finish(err -> LOG.warn("forkchoiceUpdated failed", err));
}

private static Optional<Bytes32> getPayloadBlockHash(Optional<BeaconBlock> block) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,20 @@
import tech.pegasys.teku.services.powchain.execution.client.schema.ExecutionPayload;
import tech.pegasys.teku.services.powchain.execution.client.schema.GenericResponse;
import tech.pegasys.teku.services.powchain.execution.client.schema.PreparePayloadRequest;
import tech.pegasys.teku.services.powchain.execution.client.schema.PreparePayloadResponse;
import tech.pegasys.teku.services.powchain.execution.client.schema.Response;
import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel;
import tech.pegasys.teku.ssz.type.Bytes20;

public interface ExecutionEngineClient {

SafeFuture<Response<PreparePayloadResponse>> preparePayload(PreparePayloadRequest request);
SafeFuture<UInt64> preparePayload(PreparePayloadRequest request);

SafeFuture<Response<ExecutionPayload>> getPayload(UInt64 payloadId);

SafeFuture<Response<ExecutePayloadResponse>> executePayload(ExecutionPayload request);

SafeFuture<Response<GenericResponse>> forkChoiceUpdated(
SafeFuture<Response<GenericResponse>> forkchoiceUpdated(
Bytes32 headBlockHash, Bytes32 finalizedBlockHash);

SafeFuture<Response<GenericResponse>> consensusValidated(
Expand All @@ -57,11 +56,10 @@ SafeFuture<Response<GenericResponse>> consensusValidated(
private Optional<PreparePayloadRequest> lastPreparePayloadRequest = Optional.empty();

@Override
public SafeFuture<Response<PreparePayloadResponse>> preparePayload(
PreparePayloadRequest request) {
public SafeFuture<UInt64> preparePayload(PreparePayloadRequest request) {
lastPreparePayloadRequest = Optional.of(request);
payloadId = payloadId.increment();
return SafeFuture.completedFuture(new Response<>(new PreparePayloadResponse(payloadId)));
return SafeFuture.completedFuture(payloadId);
}

@Override
Expand Down Expand Up @@ -100,7 +98,7 @@ public SafeFuture<Response<ExecutePayloadResponse>> executePayload(
}

@Override
public SafeFuture<Response<GenericResponse>> forkChoiceUpdated(
public SafeFuture<Response<GenericResponse>> forkchoiceUpdated(
Bytes32 headBlockHash, Bytes32 finalizedBlockHash) {
return SafeFuture.completedFuture(new Response<>(new GenericResponse(true)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package tech.pegasys.teku.services.powchain.execution.client;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import org.apache.tuweni.bytes.Bytes32;
Expand All @@ -25,12 +24,16 @@
import org.web3j.protocol.http.HttpService;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.services.powchain.execution.client.schema.ConsensusValidatedRequest;
import tech.pegasys.teku.services.powchain.execution.client.schema.ExecutePayloadResponse;
import tech.pegasys.teku.services.powchain.execution.client.schema.ExecutionPayload;
import tech.pegasys.teku.services.powchain.execution.client.schema.ForkchoiceUpdatedRequest;
import tech.pegasys.teku.services.powchain.execution.client.schema.GenericResponse;
import tech.pegasys.teku.services.powchain.execution.client.schema.PreparePayloadRequest;
import tech.pegasys.teku.services.powchain.execution.client.schema.PreparePayloadResponse;
import tech.pegasys.teku.services.powchain.execution.client.schema.Response;
import tech.pegasys.teku.services.powchain.execution.client.serializer.UInt64AsHexDeserializer;
import tech.pegasys.teku.services.powchain.execution.client.serializer.UInt64AsHexSerializer;
import tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel.ConsensusValidationResult;

public class Web3JExecutionEngineClient implements ExecutionEngineClient {

Expand All @@ -44,23 +47,22 @@ public Web3JExecutionEngineClient(String eth1Endpoint, Optional<String> maybeEeE
}

@Override
public SafeFuture<Response<PreparePayloadResponse>> preparePayload(
PreparePayloadRequest request) {
Request<?, PreparePayloadWeb3jResponse> web3jRequest =
public SafeFuture<UInt64> preparePayload(PreparePayloadRequest request) {
Request<?, UInt64Web3jResponse> web3jRequest =
new Request<>(
"engine_preparePayload",
Collections.singletonList(request),
eeWeb3jService,
PreparePayloadWeb3jResponse.class);
return doRequest(web3jRequest);
UInt64Web3jResponse.class);
return doRequest1(web3jRequest).thenApply(UInt64Web3jResponse::getUInt);
Nashatyrev marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public SafeFuture<Response<ExecutionPayload>> getPayload(UInt64 payloadId) {
Request<?, GetPayloadWeb3jResponse> web3jRequest =
new Request<>(
"engine_getPayload",
Collections.singletonList(payloadId.toString()),
Collections.singletonList(UInt64AsHexSerializer.toHexString(payloadId)),
eeWeb3jService,
GetPayloadWeb3jResponse.class);
return doRequest(web3jRequest);
Expand All @@ -78,12 +80,13 @@ public SafeFuture<Response<ExecutePayloadResponse>> executePayload(ExecutionPayl
}

@Override
public SafeFuture<Response<GenericResponse>> forkChoiceUpdated(
public SafeFuture<Response<GenericResponse>> forkchoiceUpdated(
Bytes32 headBlockHash, Bytes32 finalizedBlockHash) {
Request<?, GenericWeb3jResponse> web3jRequest =
new Request<>(
"engine_forkChoiceUpdated",
List.of(headBlockHash.toHexString(), finalizedBlockHash.toHexString()),
"engine_forkchoiceUpdated",
Collections.singletonList(
new ForkchoiceUpdatedRequest(headBlockHash, finalizedBlockHash)),
eeWeb3jService,
GenericWeb3jResponse.class);
return doRequest(web3jRequest);
Expand All @@ -95,7 +98,9 @@ public SafeFuture<Response<GenericResponse>> consensusValidated(
Request<?, GenericWeb3jResponse> web3jRequest =
new Request<>(
"engine_consensusValidated",
List.of(blockHash.toHexString(), validationResult),
Collections.singletonList(
new ConsensusValidatedRequest(
blockHash, ConsensusValidationResult.valueOf(validationResult))),
eeWeb3jService,
GenericWeb3jResponse.class);
return doRequest(web3jRequest);
Expand Down Expand Up @@ -134,13 +139,21 @@ private <T> SafeFuture<Response<T>> doRequest(
return SafeFuture.of(responseFuture);
}

static class GetPayloadWeb3jResponse extends org.web3j.protocol.core.Response<ExecutionPayload> {}
private <T extends org.web3j.protocol.core.Response<?>> SafeFuture<T> doRequest1(
Request<?, T> web3jRequest) {
return SafeFuture.of(web3jRequest.sendAsync());
}

static class PreparePayloadWeb3jResponse
extends org.web3j.protocol.core.Response<PreparePayloadResponse> {}
static class GetPayloadWeb3jResponse extends org.web3j.protocol.core.Response<ExecutionPayload> {}

static class NewBlockWeb3jResponse
extends org.web3j.protocol.core.Response<ExecutePayloadResponse> {}

static class GenericWeb3jResponse extends org.web3j.protocol.core.Response<GenericResponse> {}

static class UInt64Web3jResponse extends org.web3j.protocol.core.Response<String> {
public UInt64 getUInt() {
return UInt64AsHexDeserializer.decode(getResult());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.client.schema;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.base.Objects;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.services.powchain.execution.client.serializer.BytesSerializer;
import tech.pegasys.teku.spec.executionengine.ExecutionEngineChannel.ConsensusValidationResult;

public class ConsensusValidatedRequest {
@JsonSerialize(using = BytesSerializer.class)
public final Bytes32 blockHash;

public final ConsensusValidationResult status;

public ConsensusValidatedRequest(Bytes32 blockHash, ConsensusValidationResult status) {
this.blockHash = blockHash;
this.status = status;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ConsensusValidatedRequest)) {
return false;
}
ConsensusValidatedRequest that = (ConsensusValidatedRequest) o;
return Objects.equal(blockHash, that.blockHash) && status == that.status;
}

@Override
public int hashCode() {
return Objects.hashCode(blockHash, status);
}

@Override
public String toString() {
return "ConsensusValidatedRequest{" + "blockHash=" + blockHash + ", status=" + status + '}';
}
}
Loading