Skip to content

Commit

Permalink
feat: add engine API v4 methods (#853)
Browse files Browse the repository at this point in the history
* feat: add engine API v4 methods

* fix import

---------

Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
Rjected and mattsse authored Jun 8, 2024
1 parent ca6ea99 commit a4bb5f0
Showing 1 changed file with 44 additions and 4 deletions.
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

0 comments on commit a4bb5f0

Please sign in to comment.