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 engine_getPayloadV4 and engine_newPayloadV4 for Electra #8115

Merged
merged 6 commits into from
Mar 20, 2024
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 @@ -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 All @@ -47,6 +49,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 @@ -56,6 +60,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 @@ -21,10 +21,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 @@ -79,6 +81,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 @@ -100,6 +107,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 @@ -23,10 +23,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 @@ -59,7 +61,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";
public static final String EXCHANGE_CAPABILITIES_METHOD = "exchange_capabilities";
public static final String GET_CLIENT_VERSION_V1_METHOD = "get_client_versionV1";

Expand Down Expand Up @@ -106,6 +110,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 @@ -128,6 +137,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
@@ -0,0 +1,63 @@
/*
* Copyright Consensys Software Inc., 2024
*
* 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.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.bytes.Bytes48;
import tech.pegasys.teku.ethereum.executionclient.serialization.Bytes32Deserializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.Bytes48Deserializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.BytesDeserializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.BytesSerializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.UInt64AsHexDeserializer;
import tech.pegasys.teku.ethereum.executionclient.serialization.UInt64AsHexSerializer;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;

public class DepositReceiptV1 {
@JsonSerialize(using = BytesSerializer.class)
@JsonDeserialize(using = Bytes48Deserializer.class)
public final Bytes48 pubkey;

@JsonSerialize(using = BytesSerializer.class)
@JsonDeserialize(using = Bytes32Deserializer.class)
public final Bytes32 withdrawalCredentials;

@JsonSerialize(using = UInt64AsHexSerializer.class)
@JsonDeserialize(using = UInt64AsHexDeserializer.class)
public final UInt64 amount;

@JsonSerialize(using = BytesSerializer.class)
@JsonDeserialize(using = BytesDeserializer.class)
public final Bytes signature;

@JsonSerialize(using = UInt64AsHexSerializer.class)
@JsonDeserialize(using = UInt64AsHexDeserializer.class)
public final UInt64 index;

public DepositReceiptV1(
@JsonProperty("pubkey") final Bytes48 pubkey,
@JsonProperty("withdrawalCredentials") final Bytes32 withdrawalCredentials,
@JsonProperty("amount") final UInt64 amount,
@JsonProperty("signature") final Bytes signature,
@JsonProperty("index") final UInt64 index) {
this.pubkey = pubkey;
this.withdrawalCredentials = withdrawalCredentials;
this.amount = amount;
this.signature = signature;
this.index = index;
}
}
Loading