-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add engine_getPayloadV4 and engine_newPayloadV4 for Electra (#8115)
- Loading branch information
1 parent
015f4e3
commit c93c873
Showing
20 changed files
with
1,048 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
.../src/main/java/tech/pegasys/teku/ethereum/executionclient/methods/EngineGetPayloadV4.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
.../src/main/java/tech/pegasys/teku/ethereum/executionclient/methods/EngineNewPayloadV4.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...ent/src/main/java/tech/pegasys/teku/ethereum/executionclient/schema/DepositReceiptV1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.