mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Feat: Extend BuiltPayload type (#10583)
Co-authored-by: Oliver <onbjerg@users.noreply.github.com>
This commit is contained in:
@ -6,7 +6,7 @@ use reth_evm_ethereum::revm_spec_by_timestamp_after_merge;
|
||||
use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes};
|
||||
use reth_primitives::{
|
||||
constants::EIP1559_INITIAL_BASE_FEE, Address, BlobTransactionSidecar, EthereumHardfork, Header,
|
||||
SealedBlock, Withdrawals, B256, U256,
|
||||
Receipt, SealedBlock, Withdrawals, B256, U256,
|
||||
};
|
||||
use reth_rpc_types::engine::{
|
||||
ExecutionPayloadEnvelopeV2, ExecutionPayloadEnvelopeV3, ExecutionPayloadEnvelopeV4,
|
||||
@ -35,14 +35,21 @@ pub struct EthBuiltPayload {
|
||||
/// The blobs, proofs, and commitments in the block. If the block is pre-cancun, this will be
|
||||
/// empty.
|
||||
pub(crate) sidecars: Vec<BlobTransactionSidecar>,
|
||||
/// The receipts of the block
|
||||
pub(crate) receipts: Vec<Receipt>,
|
||||
}
|
||||
|
||||
// === impl BuiltPayload ===
|
||||
|
||||
impl EthBuiltPayload {
|
||||
/// Initializes the payload with the given initial block.
|
||||
pub const fn new(id: PayloadId, block: SealedBlock, fees: U256) -> Self {
|
||||
Self { id, block, fees, sidecars: Vec::new() }
|
||||
pub const fn new(
|
||||
id: PayloadId,
|
||||
block: SealedBlock,
|
||||
fees: U256,
|
||||
receipts: Vec<Receipt>,
|
||||
) -> Self {
|
||||
Self { id, block, fees, sidecars: Vec::new(), receipts }
|
||||
}
|
||||
|
||||
/// Returns the identifier of the payload.
|
||||
@ -79,6 +86,10 @@ impl BuiltPayload for EthBuiltPayload {
|
||||
fn fees(&self) -> U256 {
|
||||
self.fees
|
||||
}
|
||||
|
||||
fn receipts(&self) -> &[Receipt] {
|
||||
&self.receipts
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> BuiltPayload for &'a EthBuiltPayload {
|
||||
@ -89,6 +100,10 @@ impl<'a> BuiltPayload for &'a EthBuiltPayload {
|
||||
fn fees(&self) -> U256 {
|
||||
(**self).fees()
|
||||
}
|
||||
|
||||
fn receipts(&self) -> &[Receipt] {
|
||||
&self.receipts
|
||||
}
|
||||
}
|
||||
|
||||
// V1 engine_getPayloadV1 response
|
||||
|
||||
@ -109,6 +109,7 @@ where
|
||||
);
|
||||
err
|
||||
})?;
|
||||
|
||||
let mut db = State::builder()
|
||||
.with_database(StateProviderDatabase::new(state))
|
||||
.with_bundle_update()
|
||||
@ -254,7 +255,7 @@ where
|
||||
let block = Block { header, body: vec![], ommers: vec![], withdrawals, requests };
|
||||
let sealed_block = block.seal_slow();
|
||||
|
||||
Ok(EthBuiltPayload::new(attributes.payload_id(), sealed_block, U256::ZERO))
|
||||
Ok(EthBuiltPayload::new(attributes.payload_id(), sealed_block, U256::ZERO, Vec::new()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -490,7 +491,7 @@ where
|
||||
|
||||
let execution_outcome = ExecutionOutcome::new(
|
||||
db.take_bundle(),
|
||||
vec![receipts].into(),
|
||||
vec![receipts.clone()].into(),
|
||||
block_number,
|
||||
vec![requests.clone().unwrap_or_default()],
|
||||
);
|
||||
@ -564,7 +565,8 @@ where
|
||||
let sealed_block = block.seal_slow();
|
||||
debug!(target: "payload_builder", ?sealed_block, "sealed built block");
|
||||
|
||||
let mut payload = EthBuiltPayload::new(attributes.id, sealed_block, total_fees);
|
||||
let receipts_pay: Vec<Receipt> = receipts.into_iter().flatten().collect();
|
||||
let mut payload = EthBuiltPayload::new(attributes.id, sealed_block, total_fees, receipts_pay);
|
||||
|
||||
// extend the payload with the blob sidecars from the executed txs
|
||||
payload.extend_sidecars(blob_sidecars);
|
||||
|
||||
@ -209,6 +209,8 @@ where
|
||||
let block = Block { header, body: vec![], ommers: vec![], withdrawals, requests: None };
|
||||
let sealed_block = block.seal_slow();
|
||||
|
||||
let receipts = Vec::new();
|
||||
|
||||
Ok(OptimismBuiltPayload::new(
|
||||
attributes.payload_attributes.payload_id(),
|
||||
sealed_block,
|
||||
@ -216,6 +218,7 @@ where
|
||||
chain_spec,
|
||||
attributes,
|
||||
None,
|
||||
receipts,
|
||||
))
|
||||
}
|
||||
}
|
||||
@ -515,8 +518,12 @@ where
|
||||
// and 4788 contract call
|
||||
db.merge_transitions(BundleRetention::PlainState);
|
||||
|
||||
let execution_outcome =
|
||||
ExecutionOutcome::new(db.take_bundle(), vec![receipts].into(), block_number, Vec::new());
|
||||
let execution_outcome = ExecutionOutcome::new(
|
||||
db.take_bundle(),
|
||||
vec![receipts.clone()].into(),
|
||||
block_number,
|
||||
Vec::new(),
|
||||
);
|
||||
let receipts_root = execution_outcome
|
||||
.optimism_receipts_root_slow(
|
||||
block_number,
|
||||
@ -601,6 +608,7 @@ where
|
||||
trie: Arc::new(trie_output),
|
||||
};
|
||||
|
||||
let receipts_pay: Vec<Receipt> = receipts.into_iter().flatten().collect();
|
||||
let mut payload = OptimismBuiltPayload::new(
|
||||
attributes.payload_attributes.id,
|
||||
sealed_block,
|
||||
@ -608,6 +616,7 @@ where
|
||||
chain_spec,
|
||||
attributes,
|
||||
Some(executed),
|
||||
receipts_pay,
|
||||
);
|
||||
|
||||
// extend the payload with the blob sidecars from the executed txs
|
||||
|
||||
@ -11,8 +11,8 @@ use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes};
|
||||
use reth_primitives::{
|
||||
revm_primitives::{BlobExcessGasAndPrice, BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, SpecId},
|
||||
transaction::WithEncoded,
|
||||
Address, BlobTransactionSidecar, Header, SealedBlock, TransactionSigned, Withdrawals, B256,
|
||||
U256,
|
||||
Address, BlobTransactionSidecar, Header, Receipt, SealedBlock, TransactionSigned, Withdrawals,
|
||||
B256, U256,
|
||||
};
|
||||
/// Re-export for use in downstream arguments.
|
||||
pub use reth_rpc_types::optimism::OptimismPayloadAttributes;
|
||||
@ -179,6 +179,8 @@ pub struct OptimismBuiltPayload {
|
||||
pub(crate) chain_spec: Arc<ChainSpec>,
|
||||
/// The payload attributes.
|
||||
pub(crate) attributes: OptimismPayloadBuilderAttributes,
|
||||
/// The receipts of the block
|
||||
pub(crate) receipts: Vec<Receipt>,
|
||||
}
|
||||
|
||||
// === impl BuiltPayload ===
|
||||
@ -192,8 +194,18 @@ impl OptimismBuiltPayload {
|
||||
chain_spec: Arc<ChainSpec>,
|
||||
attributes: OptimismPayloadBuilderAttributes,
|
||||
executed_block: Option<ExecutedBlock>,
|
||||
receipts: Vec<Receipt>,
|
||||
) -> Self {
|
||||
Self { id, block, executed_block, fees, sidecars: Vec::new(), chain_spec, attributes }
|
||||
Self {
|
||||
id,
|
||||
block,
|
||||
executed_block,
|
||||
fees,
|
||||
sidecars: Vec::new(),
|
||||
chain_spec,
|
||||
attributes,
|
||||
receipts,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the identifier of the payload.
|
||||
@ -229,6 +241,10 @@ impl BuiltPayload for OptimismBuiltPayload {
|
||||
fn executed_block(&self) -> Option<ExecutedBlock> {
|
||||
self.executed_block.clone()
|
||||
}
|
||||
|
||||
fn receipts(&self) -> &[Receipt] {
|
||||
&self.receipts
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> BuiltPayload for &'a OptimismBuiltPayload {
|
||||
@ -243,6 +259,10 @@ impl<'a> BuiltPayload for &'a OptimismBuiltPayload {
|
||||
fn executed_block(&self) -> Option<ExecutedBlock> {
|
||||
self.executed_block.clone()
|
||||
}
|
||||
|
||||
fn receipts(&self) -> &[Receipt] {
|
||||
&self.receipts
|
||||
}
|
||||
}
|
||||
|
||||
// V1 engine_getPayloadV1 response
|
||||
|
||||
@ -65,7 +65,7 @@
|
||||
//! },
|
||||
//! ..Default::default()
|
||||
//! };
|
||||
//! let payload = EthBuiltPayload::new(self.attributes.id, payload.seal_slow(), U256::ZERO);
|
||||
//! let payload = EthBuiltPayload::new(self.attributes.id, payload.seal_slow(), U256::ZERO, Vec::new());
|
||||
//! Ok(payload)
|
||||
//! }
|
||||
//!
|
||||
|
||||
@ -82,7 +82,12 @@ impl PayloadJob for TestPayloadJob {
|
||||
type BuiltPayload = EthBuiltPayload;
|
||||
|
||||
fn best_payload(&self) -> Result<EthBuiltPayload, PayloadBuilderError> {
|
||||
Ok(EthBuiltPayload::new(self.attr.payload_id(), Block::default().seal_slow(), U256::ZERO))
|
||||
Ok(EthBuiltPayload::new(
|
||||
self.attr.payload_id(),
|
||||
Block::default().seal_slow(),
|
||||
U256::ZERO,
|
||||
Vec::new(),
|
||||
))
|
||||
}
|
||||
|
||||
fn payload_attributes(&self) -> Result<EthPayloadBuilderAttributes, PayloadBuilderError> {
|
||||
|
||||
@ -2,7 +2,7 @@ use reth_chain_state::ExecutedBlock;
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_primitives::{
|
||||
revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg},
|
||||
Address, Header, SealedBlock, Withdrawals, B256, U256,
|
||||
Address, Header, Receipt, SealedBlock, Withdrawals, B256, U256,
|
||||
};
|
||||
use reth_rpc_types::{
|
||||
engine::{PayloadAttributes as EthPayloadAttributes, PayloadId},
|
||||
@ -23,6 +23,9 @@ pub trait BuiltPayload: Send + Sync + std::fmt::Debug {
|
||||
/// Returns the fees collected for the built block
|
||||
fn fees(&self) -> U256;
|
||||
|
||||
/// Returns the Receipts
|
||||
fn receipts(&self) -> &[Receipt];
|
||||
|
||||
/// Returns the entire execution data for the built block, if available.
|
||||
fn executed_block(&self) -> Option<ExecutedBlock> {
|
||||
None
|
||||
|
||||
Reference in New Issue
Block a user