mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: implement EIP-7685 (#8424)
Co-authored-by: Oliver Nordbjerg <onbjerg@users.noreply.github.com> Co-authored-by: Dan Cline <6798349+Rjected@users.noreply.github.com> Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -9,13 +9,12 @@
|
||||
// The `optimism` feature must be enabled to use this crate.
|
||||
#![cfg(feature = "optimism")]
|
||||
|
||||
use reth_consensus::{Consensus, ConsensusError};
|
||||
use reth_consensus::{Consensus, ConsensusError, PostExecutionInput};
|
||||
use reth_consensus_common::validation::{
|
||||
validate_block_pre_execution, validate_header_extradata, validate_header_standalone,
|
||||
};
|
||||
use reth_primitives::{
|
||||
BlockWithSenders, ChainSpec, Header, Receipt, SealedBlock, SealedHeader, EMPTY_OMMER_ROOT_HASH,
|
||||
U256,
|
||||
BlockWithSenders, ChainSpec, Header, SealedBlock, SealedHeader, EMPTY_OMMER_ROOT_HASH, U256,
|
||||
};
|
||||
use std::{sync::Arc, time::SystemTime};
|
||||
|
||||
@ -111,8 +110,8 @@ impl Consensus for OptimismBeaconConsensus {
|
||||
fn validate_block_post_execution(
|
||||
&self,
|
||||
block: &BlockWithSenders,
|
||||
receipts: &[Receipt],
|
||||
input: PostExecutionInput<'_>,
|
||||
) -> Result<(), ConsensusError> {
|
||||
validate_block_post_execution(block, &self.chain_spec, receipts)
|
||||
validate_block_post_execution(block, &self.chain_spec, input.receipts)
|
||||
}
|
||||
}
|
||||
|
||||
@ -355,7 +355,12 @@ where
|
||||
// NOTE: we need to merge keep the reverts for the bundle retention
|
||||
self.state.merge_transitions(BundleRetention::Reverts);
|
||||
|
||||
Ok(BlockExecutionOutput { state: self.state.take_bundle(), receipts, gas_used })
|
||||
Ok(BlockExecutionOutput {
|
||||
state: self.state.take_bundle(),
|
||||
receipts,
|
||||
requests: vec![],
|
||||
gas_used,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -420,6 +425,7 @@ where
|
||||
BatchBlockExecutionOutput::new(
|
||||
self.executor.state.take_bundle(),
|
||||
self.batch_record.take_receipts(),
|
||||
self.batch_record.take_requests(),
|
||||
self.batch_record.first_block().unwrap_or_default(),
|
||||
)
|
||||
}
|
||||
@ -535,6 +541,7 @@ mod tests {
|
||||
body: vec![tx, tx_deposit],
|
||||
ommers: vec![],
|
||||
withdrawals: None,
|
||||
requests: None,
|
||||
},
|
||||
senders: vec![addr, addr],
|
||||
},
|
||||
@ -616,6 +623,7 @@ mod tests {
|
||||
body: vec![tx, tx_deposit],
|
||||
ommers: vec![],
|
||||
withdrawals: None,
|
||||
requests: None,
|
||||
},
|
||||
senders: vec![addr, addr],
|
||||
},
|
||||
|
||||
@ -280,6 +280,7 @@ mod tests {
|
||||
body: vec![l1_info_tx],
|
||||
ommers: Vec::default(),
|
||||
withdrawals: None,
|
||||
requests: None,
|
||||
};
|
||||
|
||||
let l1_info: L1BlockInfo = extract_l1_info(&mock_block).unwrap();
|
||||
@ -301,6 +302,7 @@ mod tests {
|
||||
body: vec![l1_info_tx],
|
||||
ommers: Vec::default(),
|
||||
withdrawals: None,
|
||||
requests: None,
|
||||
};
|
||||
|
||||
let l1_info: L1BlockInfo = extract_l1_info(&mock_block).unwrap();
|
||||
|
||||
@ -7,7 +7,8 @@ use reth_optimism_payload_builder::{OptimismBuiltPayload, OptimismPayloadBuilder
|
||||
use reth_primitives::{ChainSpec, Hardfork};
|
||||
use reth_rpc_types::{
|
||||
engine::{
|
||||
ExecutionPayloadEnvelopeV2, OptimismExecutionPayloadEnvelopeV3, OptimismPayloadAttributes,
|
||||
ExecutionPayloadEnvelopeV2, OptimismExecutionPayloadEnvelopeV3,
|
||||
OptimismExecutionPayloadEnvelopeV4, OptimismPayloadAttributes,
|
||||
},
|
||||
ExecutionPayloadV1,
|
||||
};
|
||||
@ -24,6 +25,7 @@ impl EngineTypes for OptimismEngineTypes {
|
||||
type ExecutionPayloadV1 = ExecutionPayloadV1;
|
||||
type ExecutionPayloadV2 = ExecutionPayloadEnvelopeV2;
|
||||
type ExecutionPayloadV3 = OptimismExecutionPayloadEnvelopeV3;
|
||||
type ExecutionPayloadV4 = OptimismExecutionPayloadEnvelopeV4;
|
||||
|
||||
fn validate_version_specific_fields(
|
||||
chain_spec: &ChainSpec,
|
||||
|
||||
@ -34,13 +34,13 @@ pub struct OptimismPayloadBuilder<EvmConfig> {
|
||||
compute_pending_block: bool,
|
||||
/// The rollup's chain spec.
|
||||
chain_spec: Arc<ChainSpec>,
|
||||
|
||||
/// The type responsible for creating the evm.
|
||||
evm_config: EvmConfig,
|
||||
}
|
||||
|
||||
impl<EvmConfig> OptimismPayloadBuilder<EvmConfig> {
|
||||
/// OptimismPayloadBuilder constructor.
|
||||
pub fn new(chain_spec: Arc<ChainSpec>, evm_config: EvmConfig) -> Self {
|
||||
pub const fn new(chain_spec: Arc<ChainSpec>, evm_config: EvmConfig) -> Self {
|
||||
Self { compute_pending_block: true, chain_spec, evm_config }
|
||||
}
|
||||
|
||||
@ -217,9 +217,10 @@ where
|
||||
blob_gas_used,
|
||||
excess_blob_gas,
|
||||
parent_beacon_block_root: attributes.payload_attributes.parent_beacon_block_root,
|
||||
requests_root: None,
|
||||
};
|
||||
|
||||
let block = Block { header, body: vec![], ommers: vec![], withdrawals };
|
||||
let block = Block { header, body: vec![], ommers: vec![], withdrawals, requests: None };
|
||||
let sealed_block = block.seal_slow();
|
||||
|
||||
Ok(OptimismBuiltPayload::new(
|
||||
@ -577,10 +578,11 @@ where
|
||||
parent_beacon_block_root: attributes.payload_attributes.parent_beacon_block_root,
|
||||
blob_gas_used,
|
||||
excess_blob_gas,
|
||||
requests_root: None,
|
||||
};
|
||||
|
||||
// seal the block
|
||||
let block = Block { header, body: executed_txs, ommers: vec![], withdrawals };
|
||||
let block = Block { header, body: executed_txs, ommers: vec![], withdrawals, requests: None };
|
||||
|
||||
let sealed_block = block.seal_slow();
|
||||
debug!(target: "payload_builder", ?sealed_block, "sealed built block");
|
||||
|
||||
@ -13,10 +13,11 @@ use reth_primitives::{
|
||||
};
|
||||
use reth_rpc_types::engine::{
|
||||
ExecutionPayloadEnvelopeV2, ExecutionPayloadV1, OptimismExecutionPayloadEnvelopeV3,
|
||||
OptimismPayloadAttributes, PayloadId,
|
||||
OptimismExecutionPayloadEnvelopeV4, OptimismPayloadAttributes, PayloadId,
|
||||
};
|
||||
use reth_rpc_types_compat::engine::payload::{
|
||||
block_to_payload_v1, block_to_payload_v3, convert_block_to_payload_field_v2,
|
||||
block_to_payload_v1, block_to_payload_v3, block_to_payload_v4,
|
||||
convert_block_to_payload_field_v2,
|
||||
};
|
||||
use revm::primitives::HandlerCfg;
|
||||
use std::sync::Arc;
|
||||
@ -272,6 +273,33 @@ impl From<OptimismBuiltPayload> for OptimismExecutionPayloadEnvelopeV3 {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<OptimismBuiltPayload> for OptimismExecutionPayloadEnvelopeV4 {
|
||||
fn from(value: OptimismBuiltPayload) -> Self {
|
||||
let OptimismBuiltPayload { block, fees, sidecars, chain_spec, attributes, .. } = value;
|
||||
|
||||
let parent_beacon_block_root =
|
||||
if chain_spec.is_cancun_active_at_timestamp(attributes.timestamp()) {
|
||||
attributes.parent_beacon_block_root().unwrap_or(B256::ZERO)
|
||||
} else {
|
||||
B256::ZERO
|
||||
};
|
||||
OptimismExecutionPayloadEnvelopeV4 {
|
||||
execution_payload: block_to_payload_v4(block),
|
||||
block_value: fees,
|
||||
// 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: false,
|
||||
blobs_bundle: sidecars.into_iter().map(Into::into).collect::<Vec<_>>().into(),
|
||||
parent_beacon_block_root,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Generates the payload id for the configured payload from the [OptimismPayloadAttributes].
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user