Skip to content

Commit

Permalink
add engine new payload V5 (#9071)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-aouadi authored Jan 31, 2025
1 parent 01be1ab commit dc90a57
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ SafeFuture<Response<PayloadStatusV1>> newPayloadV4(
Bytes32 parentBeaconBlockRoot,
List<Bytes> executionRequests);

SafeFuture<Response<PayloadStatusV1>> newPayloadV5(
ExecutionPayloadV3 executionPayload,
List<VersionedHash> blobVersionedHashes,
Bytes32 parentBeaconBlockRoot,
List<Bytes> executionRequests,
List<Bytes> inclusionList);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,23 @@ public SafeFuture<Response<PayloadStatusV1>> newPayloadV4(
executionPayload, blobVersionedHashes, parentBeaconBlockRoot, executionRequests));
}

@Override
public SafeFuture<Response<PayloadStatusV1>> newPayloadV5(
final ExecutionPayloadV3 executionPayload,
final List<VersionedHash> blobVersionedHashes,
final Bytes32 parentBeaconBlockRoot,
final List<Bytes> executionRequests,
final List<Bytes> inclusionList) {
return taskQueue.queueTask(
() ->
delegate.newPayloadV5(
executionPayload,
blobVersionedHashes,
parentBeaconBlockRoot,
executionRequests,
inclusionList));
}

@Override
public SafeFuture<Response<ForkChoiceUpdatedResult>> forkChoiceUpdatedV1(
final ForkChoiceStateV1 forkChoiceState,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright Consensys Software Inc., 2025
*
* 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.Bytes;
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.ExecutionPayloadV3;
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 EngineNewPayloadV5 extends AbstractEngineJsonRpcMethod<PayloadStatus> {

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

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

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

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

@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);
final List<Bytes> executionRequests = params.getRequiredListParameter(3, Bytes.class);
final List<Bytes> inclusionList = params.getRequiredListParameter(4, Bytes.class);

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

final ExecutionPayloadV3 executionPayloadV3 =
ExecutionPayloadV3.fromInternalExecutionPayload(executionPayload);
return executionEngineClient
.newPayloadV5(
executionPayloadV3,
blobVersionedHashes,
parentBeaconBlockRoot,
executionRequests,
inclusionList)
.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 @@ -66,6 +66,7 @@ public class MetricRecordingExecutionEngineClient extends MetricRecordingAbstrac
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";
public static final String NEW_PAYLOAD_V5_METHOD = "new_payloadV5";
public static final String EXCHANGE_CAPABILITIES_METHOD = "exchange_capabilities";
public static final String GET_CLIENT_VERSION_V1_METHOD = "get_client_versionV1";
public static final String GET_BLOBS_V1_METHOD = "get_blobs_versionV1";
Expand Down Expand Up @@ -154,6 +155,24 @@ public SafeFuture<Response<PayloadStatusV1>> newPayloadV4(
NEW_PAYLOAD_V4_METHOD);
}

@Override
public SafeFuture<Response<PayloadStatusV1>> newPayloadV5(
final ExecutionPayloadV3 executionPayload,
final List<VersionedHash> blobVersionedHashes,
final Bytes32 parentBeaconBlockRoot,
final List<Bytes> executionRequests,
final List<Bytes> inclusionList) {
return countRequest(
() ->
delegate.newPayloadV5(
executionPayload,
blobVersionedHashes,
parentBeaconBlockRoot,
executionRequests,
inclusionList),
NEW_PAYLOAD_V5_METHOD);
}

@Override
public SafeFuture<Response<ForkChoiceUpdatedResult>> forkChoiceUpdatedV1(
final ForkChoiceStateV1 forkChoiceState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,31 @@ public SafeFuture<Response<PayloadStatusV1>> newPayloadV4(
return web3JClient.doRequest(web3jRequest, EL_ENGINE_BLOCK_EXECUTION_TIMEOUT);
}

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

@Override
public SafeFuture<Response<ForkChoiceUpdatedResult>> forkChoiceUpdatedV1(
final ForkChoiceStateV1 forkChoiceState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public SafeFuture<PayloadStatus> engineNewPayload(
.add(executionPayload)
.addOptional(newPayloadRequest.getVersionedHashes())
.addOptional(newPayloadRequest.getParentBeaconBlockRoot())
.addOptional(newPayloadRequest.getExecutionRequests());
.addOptional(newPayloadRequest.getExecutionRequests())
.addOptional(newPayloadRequest.getInclusionList());

return engineMethodsResolver
.getMethod(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import tech.pegasys.teku.ethereum.executionclient.methods.EngineNewPayloadV2;
import tech.pegasys.teku.ethereum.executionclient.methods.EngineNewPayloadV3;
import tech.pegasys.teku.ethereum.executionclient.methods.EngineNewPayloadV4;
import tech.pegasys.teku.ethereum.executionclient.methods.EngineNewPayloadV5;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.datastructures.util.ForkAndSpecMilestone;
Expand Down Expand Up @@ -128,7 +129,7 @@ private Map<EngineApiMethod, EngineJsonRpcMethod<?>> electraSupportedMethods() {
private Map<EngineApiMethod, EngineJsonRpcMethod<?>> eip7805SupportedMethods() {
final Map<EngineApiMethod, EngineJsonRpcMethod<?>> methods = new HashMap<>();

methods.put(ENGINE_NEW_PAYLOAD, new EngineNewPayloadV4(executionEngineClient));
methods.put(ENGINE_NEW_PAYLOAD, new EngineNewPayloadV5(executionEngineClient));
methods.put(ENGINE_GET_PAYLOAD, new EngineGetPayloadV4(executionEngineClient, spec));
methods.put(ENGINE_FORK_CHOICE_UPDATED, new EngineForkChoiceUpdatedV3(executionEngineClient));
methods.put(ENGINE_GET_INCLUSION_LIST, new EngineGetInclusionListV1(executionEngineClient));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ public class NewPayloadRequest {
private final Optional<List<VersionedHash>> versionedHashes;
private final Optional<Bytes32> parentBeaconBlockRoot;
private final Optional<List<Bytes>> executionRequests;
private final Optional<List<Bytes>> inclusionList;

public NewPayloadRequest(final ExecutionPayload executionPayload) {
this.executionPayload = executionPayload;
this.versionedHashes = Optional.empty();
this.parentBeaconBlockRoot = Optional.empty();
this.executionRequests = Optional.empty();
this.inclusionList = Optional.empty();
}

public NewPayloadRequest(
Expand All @@ -43,6 +45,7 @@ public NewPayloadRequest(
this.versionedHashes = Optional.of(versionedHashes);
this.parentBeaconBlockRoot = Optional.of(parentBeaconBlockRoot);
this.executionRequests = Optional.empty();
this.inclusionList = Optional.empty();
}

public NewPayloadRequest(
Expand All @@ -54,6 +57,20 @@ public NewPayloadRequest(
this.versionedHashes = Optional.of(versionedHashes);
this.parentBeaconBlockRoot = Optional.of(parentBeaconBlockRoot);
this.executionRequests = Optional.of(executionRequests);
this.inclusionList = Optional.empty();
}

public NewPayloadRequest(
final ExecutionPayload executionPayload,
final List<VersionedHash> versionedHashes,
final Bytes32 parentBeaconBlockRoot,
final List<Bytes> executionRequests,
final List<Bytes> inclusionList) {
this.executionPayload = executionPayload;
this.versionedHashes = Optional.of(versionedHashes);
this.parentBeaconBlockRoot = Optional.of(parentBeaconBlockRoot);
this.executionRequests = Optional.of(executionRequests);
this.inclusionList = Optional.of(inclusionList);
}

public ExecutionPayload getExecutionPayload() {
Expand All @@ -72,6 +89,10 @@ public Optional<List<Bytes>> getExecutionRequests() {
return executionRequests;
}

public Optional<List<Bytes>> getInclusionList() {
return inclusionList;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
Expand All @@ -84,13 +105,14 @@ public boolean equals(final Object o) {
return Objects.equals(executionPayload, that.executionPayload)
&& Objects.equals(versionedHashes, that.versionedHashes)
&& Objects.equals(parentBeaconBlockRoot, that.parentBeaconBlockRoot)
&& Objects.equals(executionRequests, that.executionRequests);
&& Objects.equals(executionRequests, that.executionRequests)
&& Objects.equals(inclusionList, that.inclusionList);
}

@Override
public int hashCode() {
return Objects.hash(
executionPayload, versionedHashes, parentBeaconBlockRoot, executionRequests);
executionPayload, versionedHashes, parentBeaconBlockRoot, executionRequests, inclusionList);
}

@Override
Expand All @@ -100,6 +122,7 @@ public String toString() {
.add("versionedHashes", versionedHashes)
.add("parentBeaconBlockRoot", parentBeaconBlockRoot)
.add("executionRequests", executionRequests)
.add("inclusionList", inclusionList)
.toString();
}
}

0 comments on commit dc90a57

Please sign in to comment.