chore: introduce versioned ExecutionPayload (#4400)

This commit is contained in:
Dan Cline
2023-08-29 19:28:58 -07:00
committed by GitHub
parent d66eff1f76
commit e576c007e3
8 changed files with 515 additions and 171 deletions

View File

@ -6,7 +6,8 @@ use reth_primitives::{
use reth_revm_primitives::config::revm_spec_by_timestamp_after_merge;
use reth_rlp::Encodable;
use reth_rpc_types::engine::{
ExecutionPayload, ExecutionPayloadEnvelope, PayloadAttributes, PayloadId,
ExecutionPayloadEnvelopeV2, ExecutionPayloadEnvelopeV3, ExecutionPayloadV1, PayloadAttributes,
PayloadId,
};
use revm_primitives::{BlockEnv, CfgEnv};
@ -57,26 +58,23 @@ impl BuiltPayload {
}
/// Converts the type into the response expected by `engine_getPayloadV1`
pub fn into_v1_payload(self) -> ExecutionPayload {
pub fn into_v1_payload(self) -> ExecutionPayloadV1 {
self.into()
}
/// 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.should_override_builder = None;
envelope
pub fn into_v2_payload(self) -> ExecutionPayloadEnvelopeV2 {
self.into()
}
/// Converts the type into the response expected by `engine_getPayloadV2`
pub fn into_v3_payload(self) -> ExecutionPayloadEnvelope {
pub fn into_v3_payload(self) -> ExecutionPayloadEnvelopeV3 {
self.into()
}
}
// V1 engine_getPayloadV1 response
impl From<BuiltPayload> for ExecutionPayload {
impl From<BuiltPayload> for ExecutionPayloadV1 {
fn from(value: BuiltPayload) -> Self {
value.block.into()
}
@ -87,13 +85,21 @@ impl From<BuiltPayload> for ExecutionPayload {
// 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 {
impl From<BuiltPayload> for ExecutionPayloadEnvelopeV2 {
fn from(value: BuiltPayload) -> Self {
let BuiltPayload { block, fees, .. } = value;
ExecutionPayloadEnvelopeV2 { block_value: fees, execution_payload: block.into() }
}
}
impl From<BuiltPayload> for ExecutionPayloadEnvelopeV3 {
fn from(value: BuiltPayload) -> Self {
let BuiltPayload { block, fees, sidecars, .. } = value;
ExecutionPayloadEnvelope {
ExecutionPayloadEnvelopeV3 {
payload_inner: block.into(),
block_value: fees,
payload: block.into(),
// From the engine API spec:
//
// > Client software **MAY** use any heuristics to decide whether to set
@ -102,8 +108,8 @@ impl From<BuiltPayload> for ExecutionPayloadEnvelope {
//
// Spec:
// <https://github.com/ethereum/execution-apis/blob/fe8e13c288c592ec154ce25c534e26cb7ce0530d/src/engine/cancun.md#specification-2>
should_override_builder: Some(false),
blobs_bundle: Some(sidecars.into()),
should_override_builder: false,
blobs_bundle: sidecars.into(),
}
}
}