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

feat: add engine API v4 methods #853

Merged
merged 2 commits into from
Jun 8, 2024
Merged
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
48 changes: 44 additions & 4 deletions crates/provider/src/ext/engine.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::Provider;
use alloy_network::Network;
use alloy_primitives::{BlockHash, B256};
use alloy_rpc_types_engine::{
ClientVersionV1, ExecutionPayloadBodiesV1, ExecutionPayloadEnvelopeV2,
ExecutionPayloadEnvelopeV3, ExecutionPayloadInputV2, ExecutionPayloadV1, ExecutionPayloadV3,
ForkchoiceState, ForkchoiceUpdated, PayloadAttributes, PayloadId, PayloadStatus,
ExecutionPayloadEnvelopeV3, ExecutionPayloadEnvelopeV4, ExecutionPayloadInputV2,
ExecutionPayloadV1, ExecutionPayloadV3, ExecutionPayloadV4, ForkchoiceState, ForkchoiceUpdated,
PayloadAttributes, PayloadId, PayloadStatus,
};
use alloy_transport::{Transport, TransportResult};

use crate::Provider;

/// Extension trait that gives access to engine API RPC methods.
///
/// Note:
Expand Down Expand Up @@ -41,6 +41,16 @@ pub trait EngineApi<N, T>: Send + Sync {
parent_beacon_block_root: B256,
) -> TransportResult<PayloadStatus>;

/// Sends the given payload to the execution layer client, as specified for the Prague fork.
///
/// See also <https://github.com/ethereum/execution-apis/blob/03911ffc053b8b806123f1fc237184b0092a485a/src/engine/prague.md#engine_newpayloadv4>
async fn new_payload_v4(
&self,
payload: ExecutionPayloadV4,
versioned_hashes: Vec<B256>,
parent_beacon_block_root: B256,
) -> TransportResult<PayloadStatus>;

/// Updates the execution layer client with the given fork choice, as specified for the Paris
/// fork.
///
Expand Down Expand Up @@ -110,6 +120,18 @@ pub trait EngineApi<N, T>: Send + Sync {
payload_id: PayloadId,
) -> TransportResult<ExecutionPayloadEnvelopeV3>;

/// Returns the most recent version of the payload that is available in the corresponding
/// payload build process at the time of receiving this call.
///
/// See also <https://github.com/ethereum/execution-apis/blob/main/src/engine/prague.md#engine_getpayloadv4>
///
/// Note:
/// > Provider software MAY stop the corresponding build process after serving this call.
async fn get_payload_v4(
&self,
payload_id: PayloadId,
) -> TransportResult<ExecutionPayloadEnvelopeV4>;

/// Returns the execution payload bodies by the given hash.
///
/// See also <https://github.com/ethereum/execution-apis/blob/6452a6b194d7db269bf1dbd087a267251d3cc7f8/src/engine/shanghai.md#engine_getpayloadbodiesbyhashv1>
Expand Down Expand Up @@ -186,6 +208,17 @@ where
.await
}

async fn new_payload_v4(
&self,
payload: ExecutionPayloadV4,
versioned_hashes: Vec<B256>,
parent_beacon_block_root: B256,
) -> TransportResult<PayloadStatus> {
self.client()
.request("engine_newPayloadV4", (payload, versioned_hashes, parent_beacon_block_root))
.await
}

async fn fork_choice_updated_v1(
&self,
fork_choice_state: ForkchoiceState,
Expand Down Expand Up @@ -234,6 +267,13 @@ where
self.client().request("engine_getPayloadV3", (payload_id,)).await
}

async fn get_payload_v4(
&self,
payload_id: PayloadId,
) -> TransportResult<ExecutionPayloadEnvelopeV4> {
self.client().request("engine_getPayloadV4", (payload_id,)).await
}

async fn get_payload_bodies_by_hash_v1(
&self,
block_hashes: Vec<BlockHash>,
Expand Down
Loading