Skip to content

Commit

Permalink
[EIP-6110] Add engine API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Mar 5, 2024
1 parent 7d54f3a commit 9c41641
Show file tree
Hide file tree
Showing 12 changed files with 707 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV2;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV3;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV4;
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.GetPayloadV3Response;
import tech.pegasys.teku.ethereum.executionclient.schema.GetPayloadV4Response;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV1;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV2;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV3;
Expand All @@ -46,6 +48,8 @@ public interface ExecutionEngineClient {

SafeFuture<Response<GetPayloadV3Response>> getPayloadV3(Bytes8 payloadId);

SafeFuture<Response<GetPayloadV4Response>> getPayloadV4(Bytes8 payloadId);

SafeFuture<Response<PayloadStatusV1>> newPayloadV1(ExecutionPayloadV1 executionPayload);

SafeFuture<Response<PayloadStatusV1>> newPayloadV2(ExecutionPayloadV2 executionPayload);
Expand All @@ -55,6 +59,11 @@ SafeFuture<Response<PayloadStatusV1>> newPayloadV3(
List<VersionedHash> blobVersionedHashes,
Bytes32 parentBeaconBlockRoot);

SafeFuture<Response<PayloadStatusV1>> newPayloadV4(
ExecutionPayloadV4 executionPayload,
List<VersionedHash> blobVersionedHashes,
Bytes32 parentBeaconBlockRoot);

SafeFuture<Response<ForkChoiceUpdatedResult>> forkChoiceUpdatedV1(
ForkChoiceStateV1 forkChoiceState, Optional<PayloadAttributesV1> payloadAttributes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV2;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV3;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV4;
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.GetPayloadV3Response;
import tech.pegasys.teku.ethereum.executionclient.schema.GetPayloadV4Response;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV1;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV2;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV3;
Expand Down Expand Up @@ -78,6 +80,11 @@ public SafeFuture<Response<GetPayloadV3Response>> getPayloadV3(final Bytes8 payl
return taskQueue.queueTask(() -> delegate.getPayloadV3(payloadId));
}

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

@Override
public SafeFuture<Response<PayloadStatusV1>> newPayloadV1(
final ExecutionPayloadV1 executionPayload) {
Expand All @@ -99,6 +106,15 @@ public SafeFuture<Response<PayloadStatusV1>> newPayloadV3(
() -> delegate.newPayloadV3(executionPayload, blobVersionedHashes, parentBeaconBlockRoot));
}

@Override
public SafeFuture<Response<PayloadStatusV1>> newPayloadV4(
final ExecutionPayloadV4 executionPayload,
final List<VersionedHash> blobVersionedHashes,
final Bytes32 parentBeaconBlockRoot) {
return taskQueue.queueTask(
() -> delegate.newPayloadV4(executionPayload, blobVersionedHashes, parentBeaconBlockRoot));
}

@Override
public SafeFuture<Response<ForkChoiceUpdatedResult>> forkChoiceUpdatedV1(
final ForkChoiceStateV1 forkChoiceState,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright Consensys Software Inc., 2023
*
* 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.methods;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import tech.pegasys.teku.ethereum.executionclient.ExecutionEngineClient;
import tech.pegasys.teku.ethereum.executionclient.response.ResponseUnwrapper;
import tech.pegasys.teku.ethereum.executionclient.schema.GetPayloadV4Response;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSchema;
import tech.pegasys.teku.spec.datastructures.execution.BlobsBundle;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadContext;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSchema;
import tech.pegasys.teku.spec.datastructures.execution.GetPayloadResponse;
import tech.pegasys.teku.spec.schemas.SchemaDefinitions;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsBellatrix;
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb;

public class EngineGetPayloadV4 extends AbstractEngineJsonRpcMethod<GetPayloadResponse> {

private static final Logger LOG = LogManager.getLogger();

private final Spec spec;

public EngineGetPayloadV4(final ExecutionEngineClient executionEngineClient, final Spec spec) {
super(executionEngineClient);
this.spec = spec;
}

@Override
public String getName() {
return EngineApiMethod.ENGINE_GET_PAYLOAD.getName();
}

@Override
public int getVersion() {
return 4;
}

@Override
public SafeFuture<GetPayloadResponse> execute(final JsonRpcRequestParams params) {
final ExecutionPayloadContext executionPayloadContext =
params.getRequiredParameter(0, ExecutionPayloadContext.class);
final UInt64 slot = params.getRequiredParameter(1, UInt64.class);

LOG.trace(
"Calling {}(payloadId={}, slot={})",
getVersionedName(),
executionPayloadContext.getPayloadId(),
slot);

return executionEngineClient
.getPayloadV4(executionPayloadContext.getPayloadId())
.thenApply(ResponseUnwrapper::unwrapExecutionClientResponseOrThrow)
.thenApply(
response -> {
final SchemaDefinitions schemaDefinitions = spec.atSlot(slot).getSchemaDefinitions();
final ExecutionPayloadSchema<?> payloadSchema =
SchemaDefinitionsBellatrix.required(schemaDefinitions)
.getExecutionPayloadSchema();
final ExecutionPayload executionPayload =
response.executionPayload.asInternalExecutionPayload(payloadSchema);
final BlobsBundle blobsBundle = getBlobsBundle(response, schemaDefinitions);
return new GetPayloadResponse(
executionPayload,
response.blockValue,
blobsBundle,
response.shouldOverrideBuilder);
})
.thenPeek(
getPayloadResponse ->
LOG.trace(
"Response {}(payloadId={}, slot={}) -> {}",
getVersionedName(),
executionPayloadContext.getPayloadId(),
slot,
getPayloadResponse));
}

private BlobsBundle getBlobsBundle(
final GetPayloadV4Response response, final SchemaDefinitions schemaDefinitions) {
final BlobSchema blobSchema =
SchemaDefinitionsDeneb.required(schemaDefinitions).getBlobSchema();
return response.blobsBundle.asInternalBlobsBundle(blobSchema);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright Consensys Software Inc., 2023
*
* 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.methods;

import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.ethereum.executionclient.ExecutionEngineClient;
import tech.pegasys.teku.ethereum.executionclient.response.ResponseUnwrapper;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV4;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadStatusV1;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.executionlayer.PayloadStatus;
import tech.pegasys.teku.spec.logic.versions.deneb.types.VersionedHash;

public class EngineNewPayloadV4 extends AbstractEngineJsonRpcMethod<PayloadStatus> {

private static final Logger LOG = LogManager.getLogger();

public EngineNewPayloadV4(final ExecutionEngineClient executionEngineClient) {
super(executionEngineClient);
}

@Override
public String getName() {
return EngineApiMethod.ENGINE_NEW_PAYLOAD.getName();
}

@Override
public int getVersion() {
return 4;
}

@Override
public SafeFuture<PayloadStatus> execute(final JsonRpcRequestParams params) {
final ExecutionPayload executionPayload =
params.getRequiredParameter(0, ExecutionPayload.class);
final List<VersionedHash> blobVersionedHashes =
params.getRequiredListParameter(1, VersionedHash.class);
final Bytes32 parentBeaconBlockRoot = params.getRequiredParameter(2, Bytes32.class);

LOG.trace(
"Calling {}(executionPayload={}, blobVersionedHashes={}, parentBeaconBlockRoot={})",
getVersionedName(),
executionPayload,
blobVersionedHashes,
parentBeaconBlockRoot);

final ExecutionPayloadV4 executionPayloadV4 =
ExecutionPayloadV4.fromInternalExecutionPayload(executionPayload);
return executionEngineClient
.newPayloadV4(executionPayloadV4, blobVersionedHashes, parentBeaconBlockRoot)
.thenApply(ResponseUnwrapper::unwrapExecutionClientResponseOrThrow)
.thenApply(PayloadStatusV1::asInternalExecutionPayload)
.thenPeek(
payloadStatus ->
LOG.trace(
"Response {}(executionPayload={}) -> {}",
getVersionedName(),
executionPayload,
payloadStatus))
.exceptionally(PayloadStatus::failedExecution);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV2;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV3;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV4;
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.GetPayloadV3Response;
import tech.pegasys.teku.ethereum.executionclient.schema.GetPayloadV4Response;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV1;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV2;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV3;
Expand Down Expand Up @@ -58,7 +60,9 @@ public class MetricRecordingExecutionEngineClient extends MetricRecordingAbstrac
public static final String FORKCHOICE_UPDATED_WITH_ATTRIBUTES_V3_METHOD =
"forkchoice_updated_with_attributesV3";
public static final String GET_PAYLOAD_V3_METHOD = "get_payloadV3";
public static final String GET_PAYLOAD_V4_METHOD = "get_payloadV4";
public static final String NEW_PAYLOAD_V3_METHOD = "new_payloadV3";
public static final String NEW_PAYLOAD_V4_METHOD = "new_payloadV4";

private final ExecutionEngineClient delegate;

Expand Down Expand Up @@ -103,6 +107,11 @@ public SafeFuture<Response<GetPayloadV3Response>> getPayloadV3(final Bytes8 payl
return countRequest(() -> delegate.getPayloadV3(payloadId), GET_PAYLOAD_V3_METHOD);
}

@Override
public SafeFuture<Response<GetPayloadV4Response>> getPayloadV4(final Bytes8 payloadId) {
return countRequest(() -> delegate.getPayloadV4(payloadId), GET_PAYLOAD_V4_METHOD);
}

@Override
public SafeFuture<Response<PayloadStatusV1>> newPayloadV1(
final ExecutionPayloadV1 executionPayload) {
Expand All @@ -125,6 +134,16 @@ public SafeFuture<Response<PayloadStatusV1>> newPayloadV3(
NEW_PAYLOAD_V3_METHOD);
}

@Override
public SafeFuture<Response<PayloadStatusV1>> newPayloadV4(
final ExecutionPayloadV4 executionPayload,
final List<VersionedHash> blobVersionedHashes,
final Bytes32 parentBeaconBlockRoot) {
return countRequest(
() -> delegate.newPayloadV4(executionPayload, blobVersionedHashes, parentBeaconBlockRoot),
NEW_PAYLOAD_V4_METHOD);
}

@Override
public SafeFuture<Response<ForkChoiceUpdatedResult>> forkChoiceUpdatedV1(
final ForkChoiceStateV1 forkChoiceState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV1;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV2;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV3;
import tech.pegasys.teku.ethereum.executionclient.schema.ExecutionPayloadV4;
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.GetPayloadV3Response;
import tech.pegasys.teku.ethereum.executionclient.schema.GetPayloadV4Response;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV1;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV2;
import tech.pegasys.teku.ethereum.executionclient.schema.PayloadAttributesV3;
Expand Down Expand Up @@ -118,6 +120,17 @@ public SafeFuture<Response<GetPayloadV3Response>> getPayloadV3(final Bytes8 payl
return web3JClient.doRequest(web3jRequest, EL_ENGINE_NON_BLOCK_EXECUTION_TIMEOUT);
}

@Override
public SafeFuture<Response<GetPayloadV4Response>> getPayloadV4(final Bytes8 payloadId) {
final Request<?, GetPayloadV4Web3jResponse> web3jRequest =
new Request<>(
"engine_getPayloadV4",
Collections.singletonList(payloadId.toHexString()),
web3JClient.getWeb3jService(),
GetPayloadV4Web3jResponse.class);
return web3JClient.doRequest(web3jRequest, EL_ENGINE_NON_BLOCK_EXECUTION_TIMEOUT);
}

@Override
public SafeFuture<Response<PayloadStatusV1>> newPayloadV1(ExecutionPayloadV1 executionPayload) {
Request<?, PayloadStatusV1Web3jResponse> web3jRequest =
Expand Down Expand Up @@ -158,6 +171,23 @@ public SafeFuture<Response<PayloadStatusV1>> newPayloadV3(
return web3JClient.doRequest(web3jRequest, EL_ENGINE_BLOCK_EXECUTION_TIMEOUT);
}

@Override
public SafeFuture<Response<PayloadStatusV1>> newPayloadV4(
final ExecutionPayloadV4 executionPayload,
final List<VersionedHash> blobVersionedHashes,
final Bytes32 parentBeaconBlockRoot) {
final List<String> expectedBlobVersionedHashes =
blobVersionedHashes.stream().map(VersionedHash::toHexString).toList();
final Request<?, PayloadStatusV1Web3jResponse> web3jRequest =
new Request<>(
"engine_newPayloadV4",
list(
executionPayload, expectedBlobVersionedHashes, parentBeaconBlockRoot.toHexString()),
web3JClient.getWeb3jService(),
PayloadStatusV1Web3jResponse.class);
return web3JClient.doRequest(web3jRequest, EL_ENGINE_BLOCK_EXECUTION_TIMEOUT);
}

@Override
public SafeFuture<Response<ForkChoiceUpdatedResult>> forkChoiceUpdatedV1(
ForkChoiceStateV1 forkChoiceState, Optional<PayloadAttributesV1> payloadAttributes) {
Expand Down Expand Up @@ -216,6 +246,9 @@ static class GetPayloadV2Web3jResponse
static class GetPayloadV3Web3jResponse
extends org.web3j.protocol.core.Response<GetPayloadV3Response> {}

static class GetPayloadV4Web3jResponse
extends org.web3j.protocol.core.Response<GetPayloadV4Response> {}

static class PayloadStatusV1Web3jResponse
extends org.web3j.protocol.core.Response<PayloadStatusV1> {}

Expand Down
Loading

0 comments on commit 9c41641

Please sign in to comment.