Skip to content

Commit

Permalink
use OptimismExecutionPayloadEnvelopeV3
Browse files Browse the repository at this point in the history
  • Loading branch information
fgimenez committed Mar 3, 2024
1 parent 58cee4e commit 1d4ea00
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 31 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ reth-trie = { path = "crates/trie" }
# revm
revm = { version = "6.1.0", features = ["std", "secp256k1"], default-features = false }
revm-primitives = { version = "2.1.0", features = ["std"], default-features = false }
revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", rev = "75a187b" }
revm-inspectors = { git = "https://github.com/fgimenez/evm-inspectors", rev = "98b88ff" }

# eth
alloy-chains = { version = "0.1", feature = ["serde", "rlp", "arbitrary"] }
Expand All @@ -187,12 +187,12 @@ alloy-dyn-abi = "0.6"
alloy-sol-types = "0.6"
alloy-rlp = "0.3"
alloy-trie = "0.3"
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "76c70fb" }
alloy-rpc-trace-types = { git = "https://github.com/alloy-rs/alloy", rev = "76c70fb" }
alloy-rpc-engine-types = { git = "https://github.com/alloy-rs/alloy", rev = "76c70fb" }
alloy-genesis = { git = "https://github.com/alloy-rs/alloy", rev = "76c70fb" }
alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy", rev = "76c70fb" }
alloy-eips = { git = "https://github.com/alloy-rs/alloy", rev = "76c70fb" }
alloy-rpc-types = { git = "https://github.com/fgimenez/alloy", rev = "1985f36" }
alloy-rpc-trace-types = { git = "https://github.com/fgimenez/alloy", rev = "1985f36" }
alloy-rpc-engine-types = { git = "https://github.com/fgimenez/alloy", rev = "1985f36" }
alloy-genesis = { git = "https://github.com/fgimenez/alloy", rev = "1985f36" }
alloy-node-bindings = { git = "https://github.com/fgimenez/alloy", rev = "1985f36" }
alloy-eips = { git = "https://github.com/fgimenez/alloy", rev = "1985f36" }
ethers-core = { version = "2.0", default-features = false }
ethers-providers = { version = "2.0", default-features = false }
ethers-signers = { version = "2.0", default-features = false }
Expand Down
6 changes: 4 additions & 2 deletions crates/node-optimism/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use reth_node_api::{
use reth_payload_builder::{OptimismBuiltPayload, OptimismPayloadBuilderAttributes};
use reth_primitives::{ChainSpec, Hardfork};
use reth_rpc_types::{
engine::{ExecutionPayloadEnvelopeV2, ExecutionPayloadEnvelopeV3, OptimismPayloadAttributes},
engine::{
ExecutionPayloadEnvelopeV2, OptimismExecutionPayloadEnvelopeV3, OptimismPayloadAttributes,
},
ExecutionPayloadV1,
};

Expand All @@ -20,7 +22,7 @@ impl EngineTypes for OptimismEngineTypes {
type BuiltPayload = OptimismBuiltPayload;
type ExecutionPayloadV1 = ExecutionPayloadV1;
type ExecutionPayloadV2 = ExecutionPayloadEnvelopeV2;
type ExecutionPayloadV3 = ExecutionPayloadEnvelopeV3;
type ExecutionPayloadV3 = OptimismExecutionPayloadEnvelopeV3;

fn validate_version_specific_fields(
chain_spec: &ChainSpec,
Expand Down
34 changes: 25 additions & 9 deletions crates/payload/builder/src/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ use reth_primitives::{
Withdrawals, B256, U256,
};
use reth_rpc_types::engine::{
ExecutionPayloadEnvelopeV2, ExecutionPayloadEnvelopeV3, ExecutionPayloadV1,
ExecutionPayloadEnvelopeV2, ExecutionPayloadV1, OptimismExecutionPayloadEnvelopeV3,
OptimismPayloadAttributes, PayloadId,
};
use reth_rpc_types_compat::engine::payload::{
block_to_payload_v3, convert_block_to_payload_field_v2,
convert_standalone_withdraw_to_withdrawal, try_block_to_payload_v1,
};
use revm_primitives::FixedBytes;

/// Optimism Payload Builder Attributes
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct OptimismPayloadBuilderAttributes {
/// Inner ethereum payload builder attributes
pub payload_attributes: EthPayloadBuilderAttributes,
Expand Down Expand Up @@ -175,6 +176,8 @@ pub struct OptimismBuiltPayload {
pub(crate) sidecars: Vec<BlobTransactionSidecar>,
/// The rollup's chainspec.
pub(crate) chain_spec: Arc<ChainSpec>,
/// The payload attributes.
pub(crate) attributes: OptimismPayloadBuilderAttributes,
}

impl From<EthBuiltPayload> for OptimismBuiltPayload {
Expand All @@ -185,6 +188,7 @@ impl From<EthBuiltPayload> for OptimismBuiltPayload {
fees: value.fees,
sidecars: value.sidecars,
chain_spec: Arc::new(ChainSpec::default()),
attributes: OptimismPayloadBuilderAttributes::default(),
}
}
}
Expand All @@ -193,8 +197,14 @@ impl From<EthBuiltPayload> for OptimismBuiltPayload {

impl OptimismBuiltPayload {
/// Initializes the payload with the given initial block.
pub fn new(id: PayloadId, block: SealedBlock, fees: U256, chain_spec: Arc<ChainSpec>) -> Self {
Self { id, block, fees, sidecars: Vec::new(), chain_spec }
pub fn new(
id: PayloadId,
block: SealedBlock,
fees: U256,
chain_spec: Arc<ChainSpec>,
attributes: OptimismPayloadBuilderAttributes,
) -> Self {
Self { id, block, fees, sidecars: Vec::new(), chain_spec, attributes }
}

/// Returns the identifier of the payload.
Expand Down Expand Up @@ -257,12 +267,18 @@ impl From<OptimismBuiltPayload> for ExecutionPayloadEnvelopeV2 {
}
}

impl From<OptimismBuiltPayload> for ExecutionPayloadEnvelopeV3 {
impl From<OptimismBuiltPayload> for OptimismExecutionPayloadEnvelopeV3 {
fn from(value: OptimismBuiltPayload) -> Self {
let OptimismBuiltPayload { block, fees, sidecars, .. } = value;
let OptimismBuiltPayload { block, fees, sidecars, chain_spec, attributes, .. } = value;

ExecutionPayloadEnvelopeV3 {
execution_payload: block_to_payload_v3(block),
let parent_beacon_block_root =
if chain_spec.is_cancun_active_at_timestamp(attributes.timestamp()) {
attributes.parent_beacon_block_root().unwrap()
} else {
FixedBytes::<32>::default()
};
OptimismExecutionPayloadEnvelopeV3 {
execution_payload: block_to_payload_v3(block.clone()),
block_value: fees,
// From the engine API spec:
//
Expand All @@ -274,7 +290,7 @@ impl From<OptimismBuiltPayload> for ExecutionPayloadEnvelopeV3 {
// <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: None,
parent_beacon_block_root,
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions crates/payload/builder/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,12 @@ impl From<EthBuiltPayload> for ExecutionPayloadEnvelopeV3 {
// <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(),
// Optimism-specific: Post-cancun, the parent beacon block root is included in the
// enveloped payload. We set this as `None` here so that optimism-specific
// handling can fill the value.
parent_beacon_block_root: None,
}
}
}

/// Container type for all components required to build a payload.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct EthPayloadBuilderAttributes {
/// Id of the payload
pub id: PayloadId,
Expand Down
4 changes: 3 additions & 1 deletion crates/payload/optimism/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ mod builder {
sealed_block,
U256::ZERO,
chain_spec,
attributes,
))
}
}
Expand Down Expand Up @@ -511,7 +512,7 @@ mod builder {
&mut db,
&chain_spec,
attributes.payload_attributes.timestamp,
attributes.payload_attributes.withdrawals,
attributes.clone().payload_attributes.withdrawals,
)?;

// merge all transitions into bundle state, this would apply the withdrawal balance changes
Expand Down Expand Up @@ -592,6 +593,7 @@ mod builder {
sealed_block,
total_fees,
chain_spec,
attributes,
);

// extend the payload with the blob sidecars from the executed txs
Expand Down

0 comments on commit 1d4ea00

Please sign in to comment.