mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: integrate blobs into the payload builder (#4305)
This commit is contained in:
@ -13,6 +13,7 @@ description = "reth payload builder"
|
||||
reth-primitives.workspace = true
|
||||
reth-rpc-types.workspace = true
|
||||
reth-rlp.workspace = true
|
||||
reth-transaction-pool.workspace = true
|
||||
reth-interfaces.workspace = true
|
||||
reth-revm-primitives = { path = "../../revm/revm-primitives" }
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
//! Error types emitted by types or implementations of this crate.
|
||||
|
||||
use reth_primitives::H256;
|
||||
use reth_transaction_pool::BlobStoreError;
|
||||
use revm_primitives::EVMError;
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
@ -13,6 +14,9 @@ pub enum PayloadBuilderError {
|
||||
/// An oneshot channels has been closed.
|
||||
#[error("sender has been dropped")]
|
||||
ChannelClosed,
|
||||
/// Error occurring in the blob store.
|
||||
#[error(transparent)]
|
||||
BlobStore(#[from] BlobStoreError),
|
||||
/// Other internal error
|
||||
#[error(transparent)]
|
||||
Internal(#[from] reth_interfaces::Error),
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
//! Contains types required for building a payload.
|
||||
|
||||
use reth_primitives::{Address, ChainSpec, Header, SealedBlock, Withdrawal, H256, U256};
|
||||
use reth_primitives::{
|
||||
Address, BlobTransactionSidecar, ChainSpec, Header, SealedBlock, Withdrawal, H256, U256,
|
||||
};
|
||||
use reth_revm_primitives::config::revm_spec_by_timestamp_after_merge;
|
||||
use reth_rlp::Encodable;
|
||||
use reth_rpc_types::engine::{
|
||||
@ -21,6 +23,9 @@ pub struct BuiltPayload {
|
||||
pub(crate) block: SealedBlock,
|
||||
/// The fees of the block
|
||||
pub(crate) fees: U256,
|
||||
/// The blobs, proofs, and commitments in the block. If the block is pre-cancun, this will be
|
||||
/// empty.
|
||||
pub(crate) sidecars: Vec<BlobTransactionSidecar>,
|
||||
}
|
||||
|
||||
// === impl BuiltPayload ===
|
||||
@ -28,7 +33,7 @@ pub struct BuiltPayload {
|
||||
impl BuiltPayload {
|
||||
/// Initializes the payload with the given initial block.
|
||||
pub fn new(id: PayloadId, block: SealedBlock, fees: U256) -> Self {
|
||||
Self { id, block, fees }
|
||||
Self { id, block, fees, sidecars: Vec::new() }
|
||||
}
|
||||
|
||||
/// Returns the identifier of the payload.
|
||||
@ -46,6 +51,11 @@ impl BuiltPayload {
|
||||
self.fees
|
||||
}
|
||||
|
||||
/// Adds sidecars to the payload.
|
||||
pub fn extend_sidecars(&mut self, sidecars: Vec<BlobTransactionSidecar>) {
|
||||
self.sidecars.extend(sidecars)
|
||||
}
|
||||
|
||||
/// Converts the type into the response expected by `engine_getPayloadV1`
|
||||
pub fn into_v1_payload(self) -> ExecutionPayload {
|
||||
self.into()
|
||||
@ -53,6 +63,14 @@ 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.should_override_builder = None;
|
||||
envelope
|
||||
}
|
||||
|
||||
/// Converts the type into the response expected by `engine_getPayloadV2`
|
||||
pub fn into_v3_payload(self) -> ExecutionPayloadEnvelope {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
@ -65,14 +83,27 @@ 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, .. } = value;
|
||||
let BuiltPayload { block, fees, sidecars, .. } = value;
|
||||
|
||||
ExecutionPayloadEnvelope {
|
||||
block_value: fees,
|
||||
payload: block.into(),
|
||||
should_override_builder: None,
|
||||
// From the engine API spec:
|
||||
//
|
||||
// > Client software **MAY** use any heuristics to decide whether to set
|
||||
// `shouldOverrideBuilder` flag or not. If client software does not implement any
|
||||
// heuristic this flag **SHOULD** be set to `false`.
|
||||
//
|
||||
// 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()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user