Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions bin/client/src/l2/chain_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use async_trait::async_trait;
use kona_derive::traits::L2ChainProvider;
use kona_mpt::{OrderedListWalker, TrieDBFetcher, TrieDBHinter};
use kona_preimage::{CommsClient, PreimageKey, PreimageKeyType};
use kona_primitives::{
L2BlockInfo, L2ExecutionPayloadEnvelope, OpBlock, RollupConfig, SystemConfig,
};
use kona_primitives::{L2BlockInfo, L2ExecutionPayloadEnvelope, RollupConfig, SystemConfig};
use op_alloy_consensus::OpTxEnvelope;

/// The oracle-backed L2 chain provider for the client program.
Expand Down Expand Up @@ -96,13 +94,9 @@ impl<T: CommsClient + Send + Sync> L2ChainProvider for OracleL2ChainProvider<T>
})
.collect::<Result<Vec<_>>>()?;

let optimism_block = OpBlock {
header,
body: transactions,
withdrawals: self.boot_info.rollup_config.is_canyon_active(timestamp).then(Vec::new),
..Default::default()
};
Ok(optimism_block.into())
let withdrawals = self.boot_info.rollup_config.is_canyon_active(timestamp).then(Vec::new);
let payload = L2ExecutionPayloadEnvelope::from_body(header, &transactions, withdrawals);
Ok(payload)
}

async fn system_config_by_number(
Expand Down
28 changes: 25 additions & 3 deletions crates/derive/src/online/alloy_providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use alloc::{boxed::Box, sync::Arc, vec::Vec};
use alloy_consensus::{Header, Receipt, ReceiptWithBloom, TxEnvelope, TxType};
use alloy_eips::eip4895::Withdrawal;
use alloy_primitives::{Bytes, B256, U64};
use alloy_provider::{Provider, ReqwestProvider};
use alloy_rlp::{Buf, Decodable};
Expand All @@ -11,7 +12,7 @@ use anyhow::{anyhow, Result};
use async_trait::async_trait;
use core::num::NonZeroUsize;
use kona_primitives::{
Block, BlockInfo, L2BlockInfo, L2ExecutionPayloadEnvelope, OpBlock, RollupConfig, SystemConfig,
BlockInfo, L2BlockInfo, L2ExecutionPayloadEnvelope, RollupConfig, SystemConfig,
};
use lru::LruCache;

Expand Down Expand Up @@ -71,6 +72,26 @@ impl AlloyChainProvider {
}
}

/// Ethereum full block.
///
/// Withdrawals can be optionally included at the end of the RLP encoded message.
///
/// Taken from [reth-primitives](https://github.com/paradigmxyz/reth)
#[derive(
Debug, Clone, PartialEq, Eq, Default, alloy_rlp::RlpEncodable, alloy_rlp::RlpDecodable,
)]
#[rlp(trailing)]
struct Block {
/// Block header.
pub header: Header,
/// Transactions in this block.
pub body: Vec<TxEnvelope>,
/// Ommers/uncles header.
pub ommers: Vec<Header>,
/// Block withdrawals.
pub withdrawals: Option<Vec<Withdrawal>>,
}

#[async_trait]
impl ChainProvider for AlloyChainProvider {
async fn header_by_hash(&mut self, hash: B256) -> Result<Header> {
Expand Down Expand Up @@ -381,15 +402,16 @@ impl L2ChainProvider for AlloyL2ChainProvider {
return Err(e);
}
};
let block = match OpBlock::decode(&mut raw_block.as_ref()).map_err(|e| anyhow!(e)) {
let payload_envelope = match L2ExecutionPayloadEnvelope::try_from_bytes(raw_block.as_ref())
.map_err(|e| anyhow!(e))
{
Ok(b) => b,
Err(e) => {
crate::timer!(DISCARD, timer);
crate::inc!(PROVIDER_ERRORS, &["l2_chain_provider", "payload_by_number", "decode"]);
return Err(e);
}
};
let payload_envelope: L2ExecutionPayloadEnvelope = block.into();

self.payload_by_number_cache.put(number, payload_envelope.clone());
Ok(payload_envelope)
Expand Down
63 changes: 0 additions & 63 deletions crates/primitives/src/block.rs

This file was deleted.

3 changes: 0 additions & 3 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ pub use alloy_eips::eip4844::{Blob, BYTES_PER_BLOB, VERSIONED_HASH_VERSION_KZG};
/// [Withdrawal]: alloy_eips::eip4895::Withdrawal
pub use alloy_eips::eip4895::Withdrawal;

pub mod block;
pub use block::{Block, BlockKind, OpBlock};

pub mod block_info;
pub use block_info::{L1BlockInfoBedrock, L1BlockInfoEcotone, L1BlockInfoTx};

Expand Down
55 changes: 46 additions & 9 deletions crates/primitives/src/payload.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
//! Contains the execution payload type.

use alloc::vec::Vec;
use alloy_eips::eip2718::{Decodable2718, Encodable2718};
use alloy_consensus::Header;
use alloy_eips::{
eip2718::{Decodable2718, Encodable2718},
eip4895::Withdrawal,
};
use alloy_primitives::{Address, Bloom, Bytes, B256};
use alloy_rlp::{RlpDecodable, RlpEncodable};
use anyhow::Result;
use op_alloy_consensus::{OpTxEnvelope, OpTxType};

Expand All @@ -15,8 +20,8 @@ pub const PAYLOAD_MEM_FIXED_COST: u64 = 1000;
pub const PAYLOAD_TX_MEM_OVERHEAD: u64 = 24;

use super::{
BlockInfo, L1BlockInfoBedrock, L1BlockInfoEcotone, L1BlockInfoTx, L2BlockInfo, OpBlock,
RollupConfig, SystemConfig, Withdrawal,
BlockInfo, L1BlockInfoBedrock, L1BlockInfoEcotone, L1BlockInfoTx, L2BlockInfo, RollupConfig,
SystemConfig,
};
use alloy_rlp::Encodable;

Expand Down Expand Up @@ -228,9 +233,41 @@ impl L2ExecutionPayloadEnvelope {
}
}

impl From<OpBlock> for L2ExecutionPayloadEnvelope {
fn from(block: OpBlock) -> Self {
let OpBlock { header, body, withdrawals, .. } = block;
// TODO: Below is a temporary conversion utility to rlp decode the block.
// Once alloy-consensus has a block type with rlp encoding/decoding,
// this can be removed and replaced with an op-alloy-consensus type
// that specifies the tx as an OpTxEnvelope.

/// OP Stack full block.
///
/// Withdrawals can be optionally included at the end of the RLP encoded message.
///
/// Taken from [reth-primitives](https://github.com/paradigmxyz/reth)
#[derive(Debug, Clone, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)]
#[rlp(trailing)]
pub struct OpBlock {
/// Block header.
pub header: Header,
/// Transactions in this block.
pub body: Vec<OpTxEnvelope>,
/// Ommers/uncles header.
pub ommers: Vec<Header>,
/// Block withdrawals.
pub withdrawals: Option<Vec<Withdrawal>>,
}

impl L2ExecutionPayloadEnvelope {
/// Tries to convert the bytes into an [L2ExecutionPayloadEnvelope].
pub fn try_from_bytes(mut bytes: &[u8]) -> Result<Self> {
use alloy_rlp::Decodable;
let op_block = OpBlock::decode(&mut bytes).map_err(|e| anyhow::anyhow!(e))?;
let OpBlock { header, body, withdrawals, .. } = op_block;
Ok(Self::from_body(header, &body, withdrawals))
}

/// Constructs a new [L2ExecutionPayloadEnvelope] from the given header, transactions, and
/// withdrawals.
pub fn from_body(header: Header, body: &[OpTxEnvelope], w: Option<Vec<Withdrawal>>) -> Self {
Self {
execution_payload: L2ExecutionPayload {
parent_hash: header.parent_hash,
Expand All @@ -246,16 +283,16 @@ impl From<OpBlock> for L2ExecutionPayloadEnvelope {
extra_data: header.extra_data.clone(),
base_fee_per_gas: header.base_fee_per_gas,
block_hash: header.hash_slow(),
deserialized_transactions: body.clone(),
deserialized_transactions: body.to_vec(),
transactions: body
.into_iter()
.iter()
.map(|tx| {
let mut buf = Vec::with_capacity(tx.length());
tx.encode_2718(&mut buf);
buf.into()
})
.collect(),
withdrawals,
withdrawals: w,
blob_gas_used: header.blob_gas_used,
excess_blob_gas: header.excess_blob_gas,
},
Expand Down