Skip to content

Commit

Permalink
add into_v3_payload
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected committed Aug 22, 2023
1 parent 0770fe0 commit 6f8acb2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
11 changes: 11 additions & 0 deletions crates/payload/builder/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ impl BuiltPayload {

/// Converts the type into the response expected by `engine_getPayloadV2`
pub fn into_v2_payload(self) -> ExecutionPayloadEnvelope {
let mut envelope: ExecutionPayloadEnvelope = self.into();
envelope.blobs_bundle = None;
envelope
}

/// Converts the type into the response expected by `engine_getPayloadV2`
pub fn into_v3_payload(self) -> ExecutionPayloadEnvelope {
self.into()
}
}
Expand All @@ -75,6 +82,10 @@ impl From<BuiltPayload> for ExecutionPayload {
}

// V2 engine_getPayloadV2 response
// TODO(rjected): we could improve this by wrapping envelope / payload types by version, so we can
// have explicitly versioned return types for getPayload. Then BuiltPayload could essentially be a
// builder for those types, and it would not be possible to e.g. return cancun fields for a
// pre-cancun endpoint.
impl From<BuiltPayload> for ExecutionPayloadEnvelope {
fn from(value: BuiltPayload) -> Self {
let BuiltPayload { block, fees, sidecars, .. } = value;
Expand Down
22 changes: 21 additions & 1 deletion crates/rpc/rpc-engine-api/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ where
///
/// Note:
/// > Provider software MAY stop the corresponding build process after serving this call.
async fn get_payload_v2(
pub async fn get_payload_v2(
&self,
payload_id: PayloadId,
) -> EngineApiResult<ExecutionPayloadEnvelope> {
Expand All @@ -193,6 +193,26 @@ where
.map(|payload| (*payload).clone().into_v2_payload())?)
}

/// 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/fe8e13c288c592ec154ce25c534e26cb7ce0530d/src/engine/cancun.md#engine_getpayloadv3>
///
/// Note:
/// > Provider software MAY stop the corresponding build process after serving this call.
pub async fn get_payload_v3(
&self,
payload_id: PayloadId,
) -> EngineApiResult<ExecutionPayloadEnvelope> {
Ok(self
.inner
.payload_store
.resolve(payload_id)
.await
.ok_or(EngineApiError::UnknownPayload)?
.map(|payload| (*payload).clone().into_v3_payload())?)
}

/// Returns the execution payload bodies by the range starting at `start`, containing `count`
/// blocks.
///
Expand Down

0 comments on commit 6f8acb2

Please sign in to comment.