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 blockValue to get payload V2 response #6614

Merged
merged 6 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -50,6 +50,7 @@
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.TestSpecContext;
import tech.pegasys.teku.spec.TestSpecInvocationContextProvider.SpecContext;
import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel.Version;
import tech.pegasys.teku.spec.executionlayer.PayloadStatus;
import tech.pegasys.teku.spec.util.DataStructureUtil;

Expand Down Expand Up @@ -86,7 +87,7 @@ void setUp(SpecContext specContext) throws IOException {
.timeProvider(timeProvider)
.executionClientEventsPublisher(executionClientEventsPublisher)
.build();
eeClient = new Web3JExecutionEngineClient(web3JClient);
eeClient = new Web3JExecutionEngineClient(web3JClient, Version.DEFAULT_VERSION);
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV2;
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceStateV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceUpdatedResult;
import tech.pegasys.teku.ethereum.executionclient.schema.GetPayloadV2Response;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV1;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV2;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadStatusV1;
Expand All @@ -38,7 +39,7 @@ public interface ExecutionEngineClient {
// engine namespace
SafeFuture<Response<ExecutionPayloadV1>> getPayloadV1(Bytes8 payloadId);

SafeFuture<Response<ExecutionPayloadV2>> getPayloadV2(Bytes8 payloadId);
SafeFuture<Response<GetPayloadV2Response>> getPayloadV2(Bytes8 payloadId);

SafeFuture<Response<BlobsBundleV1>> getBlobsBundleV1(Bytes8 payloadId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV2;
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceStateV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceUpdatedResult;
import tech.pegasys.teku.ethereum.executionclient.schema.GetPayloadV2Response;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV1;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV2;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadStatusV1;
Expand Down Expand Up @@ -65,7 +66,7 @@ public SafeFuture<Response<ExecutionPayloadV1>> getPayloadV1(final Bytes8 payloa
}

@Override
public SafeFuture<Response<ExecutionPayloadV2>> getPayloadV2(final Bytes8 payloadId) {
public SafeFuture<Response<GetPayloadV2Response>> getPayloadV2(final Bytes8 payloadId) {
return taskQueue.queueTask(() -> delegate.getPayloadV2(payloadId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV2;
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceStateV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceUpdatedResult;
import tech.pegasys.teku.ethereum.executionclient.schema.GetPayloadV2Response;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV1;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV2;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadStatusV1;
Expand Down Expand Up @@ -87,7 +88,7 @@ public SafeFuture<Response<ExecutionPayloadV1>> getPayloadV1(final Bytes8 payloa
}

@Override
public SafeFuture<Response<ExecutionPayloadV2>> getPayloadV2(final Bytes8 payloadId) {
public SafeFuture<Response<GetPayloadV2Response>> getPayloadV2(final Bytes8 payloadId) {
return countRequest(() -> delegate.getPayloadV2(payloadId), GET_PAYLOAD_V2_METHOD);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright ConsenSys Software Inc., 2022
*
* 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.ethereum.executionclient.schema;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.apache.tuweni.units.bigints.UInt256;
import tech.pegasys.teku.ethereum.executionclient.serialization.UInt256AsHexDeserializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.UInt256AsHexSerializer;

public class GetPayloadV2Response {
public final ExecutionPayloadV2 executionPayload;

@JsonSerialize(using = UInt256AsHexSerializer.class)
@JsonDeserialize(using = UInt256AsHexDeserializer.class)
public final UInt256 blockValue;

public GetPayloadV2Response(
@JsonProperty("executionPayload") final ExecutionPayloadV2 executionPayload,
@JsonProperty("blockValue") final UInt256 blockValue) {
this.executionPayload = executionPayload;
this.blockValue = blockValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV2;
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceStateV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceUpdatedResult;
import tech.pegasys.teku.ethereum.executionclient.schema.GetPayloadV2Response;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV1;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV2;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadStatusV1;
Expand All @@ -41,15 +42,18 @@
import tech.pegasys.teku.infrastructure.bytes.Bytes8;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.execution.PowBlock;
import tech.pegasys.teku.spec.executionlayer.ExecutionLayerChannel.Version;

public class Web3JExecutionEngineClient implements ExecutionEngineClient {

private static final Duration EXCHANGE_TRANSITION_CONFIGURATION_TIMEOUT = Duration.ofSeconds(8);

private final Web3JClient web3JClient;
private final Version engineVersion;

public Web3JExecutionEngineClient(final Web3JClient web3JClient) {
public Web3JExecutionEngineClient(final Web3JClient web3JClient, final Version engineVersion) {
this.web3JClient = web3JClient;
this.engineVersion = engineVersion;
}

@Override
Expand Down Expand Up @@ -95,14 +99,33 @@ public SafeFuture<Response<ExecutionPayloadV1>> getPayloadV1(Bytes8 payloadId) {
}

@Override
public SafeFuture<Response<ExecutionPayloadV2>> getPayloadV2(final Bytes8 payloadId) {
Request<?, ExecutionPayloadV2Web3jResponse> web3jRequest =
new Request<>(
"engine_getPayloadV2",
Collections.singletonList(payloadId.toHexString()),
web3JClient.getWeb3jService(),
ExecutionPayloadV2Web3jResponse.class);
return web3JClient.doRequest(web3jRequest, EL_ENGINE_NON_BLOCK_EXECUTION_TIMEOUT);
public SafeFuture<Response<GetPayloadV2Response>> getPayloadV2(final Bytes8 payloadId) {
if (engineVersion != Version.NO_BLOCK_VALUE) {
Request<?, GetPayloadV2Web3jResponse> web3jRequest =
new Request<>(
"engine_getPayloadV2",
Collections.singletonList(payloadId.toHexString()),
web3JClient.getWeb3jService(),
GetPayloadV2Web3jResponse.class);
return web3JClient.doRequest(web3jRequest, EL_ENGINE_NON_BLOCK_EXECUTION_TIMEOUT);
} else {
Request<?, ExecutionPayloadV2Web3jResponse> web3jRequest =
new Request<>(
"engine_getPayloadV2",
Collections.singletonList(payloadId.toHexString()),
web3JClient.getWeb3jService(),
ExecutionPayloadV2Web3jResponse.class);
return web3JClient
.doRequest(web3jRequest, EL_ENGINE_NON_BLOCK_EXECUTION_TIMEOUT)
.thenApply(
response -> {
if (response.isFailure()) {
return Response.withErrorMessage(response.getErrorMessage());
}
return new Response<>(
new GetPayloadV2Response(response.getPayload(), UInt256.ZERO));
});
}
}

@Override
Expand Down Expand Up @@ -179,6 +202,9 @@ public SafeFuture<Response<TransitionConfigurationV1>> exchangeTransitionConfigu
static class ExecutionPayloadV1Web3jResponse
extends org.web3j.protocol.core.Response<ExecutionPayloadV1> {}

static class GetPayloadV2Web3jResponse
extends org.web3j.protocol.core.Response<GetPayloadV2Response> {}

static class ExecutionPayloadV2Web3jResponse
extends org.web3j.protocol.core.Response<ExecutionPayloadV2> {}

Expand All @@ -201,9 +227,7 @@ static class TransitionConfigurationV1Web3jResponse
*/
protected List<Object> list(final Object... items) {
final List<Object> list = new ArrayList<>();
for (Object item : items) {
list.add(item);
}
Collections.addAll(list, items);
return list;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public SafeFuture<ExecutionPayload> engineGetPayload(
return executionEngineClient
.getPayloadV2(executionPayloadContext.getPayloadId())
.thenApply(ResponseUnwrapper::unwrapExecutionClientResponseOrThrow)
// Note: Currently ignoring the returned blockValue but will eventually want to use it
.thenApply(response -> response.executionPayload)
.thenCombine(
SafeFuture.of(
() ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ public static ExecutionEngineClient createEngineClient(
final MetricsSystem metricsSystem) {
checkNotNull(version);
LOG.info("Execution Engine version: {}", version);
if (version != Version.KILNV2) {
if (version != Version.KILNV2 && version != Version.NO_BLOCK_VALUE) {
throw new InvalidConfigurationException("Unsupported execution engine version: " + version);
}
final ExecutionEngineClient engineClient = new Web3JExecutionEngineClient(web3JClient);
final ExecutionEngineClient engineClient = new Web3JExecutionEngineClient(web3JClient, version);
final ExecutionEngineClient metricEngineClient =
new MetricRecordingExecutionEngineClient(engineClient, timeProvider, metricsSystem);
return new ThrottlingExecutionEngineClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@

import java.util.List;
import java.util.Optional;
import org.apache.tuweni.units.bigints.UInt256;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV2;
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceStateV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ForkChoiceUpdatedResult;
import tech.pegasys.teku.ethereum.executionclient.schema.GetPayloadV2Response;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV2;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadStatusV1;
import tech.pegasys.teku.ethereum.executionclient.schema.Response;
Expand Down Expand Up @@ -55,11 +57,13 @@ void engineGetPayload_shouldCallGetPayloadV2() {
dataStructureUtil.randomForkChoiceState(false),
dataStructureUtil.randomPayloadBuildingAttributes(false));

final SafeFuture<Response<ExecutionPayloadV2>> dummyResponse =
final SafeFuture<Response<GetPayloadV2Response>> dummyResponse =
SafeFuture.completedFuture(
new Response<>(
ExecutionPayloadV2.fromInternalExecutionPayload(
dataStructureUtil.randomExecutionPayload())));
new GetPayloadV2Response(
ExecutionPayloadV2.fromInternalExecutionPayload(
dataStructureUtil.randomExecutionPayload()),
UInt256.MAX_VALUE)));
when(executionEngineClient.getPayloadV2(context.getPayloadId())).thenReturn(dummyResponse);

handler.engineGetPayload(context, slot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ SafeFuture<ExecutionPayloadHeader> builderGetHeader(
SafeFuture<ExecutionPayload> builderGetPayload(SignedBeaconBlock signedBlindedBeaconBlock);

enum Version {
KILNV2;
KILNV2,
NO_BLOCK_VALUE;

public static final Version DEFAULT_VERSION = KILNV2;
}
Expand Down