Skip to content
Merged
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ reth-ipc = { git = "https://github.com/paradigmxyz/reth", tag = "v1.8.2", option

# Reth-optimism dependencies (optional)
op-alloy = { version = "0.20.0", features = ["full"], optional = true }
op-alloy-flz = "0.13.1"
reth-optimism-node = { git = "https://github.com/paradigmxyz/reth", tag = "v1.8.2", optional = true }
reth-optimism-chainspec = { git = "https://github.com/paradigmxyz/reth", tag = "v1.8.2", optional = true }
reth-optimism-forks = { git = "https://github.com/paradigmxyz/reth", tag = "v1.8.2", optional = true }
Expand Down
6 changes: 3 additions & 3 deletions src/payload/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,15 @@ impl<P: PlatformWithRpcTypes> IntoExecutable<P, Variant<7>>
#[derive(Debug, Clone, PartialEq)]
pub struct ExecutionResult<P: Platform> {
/// The executable used to produce this result.
source: Executable<P>,
pub(crate) source: Executable<P>,

/// For transactions this is guaranteed to be a single-element vector,
/// for bundles this is guaranteed to be a vector of results for each
/// transaction in the bundle.
results: Vec<types::TransactionExecutionResult<P>>,
pub(crate) results: Vec<types::TransactionExecutionResult<P>>,

/// The aggregated state executing all transactions from the source.
state: BundleState,
pub(crate) state: BundleState,
}

impl<P: Platform> ExecutionResult<P> {
Expand Down
84 changes: 84 additions & 0 deletions src/platform/optimism/ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use {
crate::{alloy, prelude::*, reth},
alloy::eips::Encodable2718,
op_alloy_flz,
reth::api::NodeTypes,
};

pub trait ExecutionResultOpExt<P: Platform> {
/// Data availability bytes used by this execution.
fn da_bytes_used(&self) -> u64;
}

impl<P: Platform> ExecutionResultOpExt<P> for ExecutionResult<P>
where
P: Platform<
NodeTypes: NodeTypes<
ChainSpec = types::ChainSpec<Optimism>,
Primitives = types::Primitives<Optimism>,
Payload = types::PayloadTypes<Optimism>,
>,
>,
{
fn da_bytes_used(&self) -> u64 {
self
.source
.transactions()
.iter()
.map(|tx| {
op_alloy_flz::tx_estimated_size_fjord_bytes(
tx.encoded_2718().as_slice(),
)
})
.sum()
}
}

pub trait SpanOpExt<P: Platform> {
/// Returns the total data availability bytes used by all checkpoints in this
/// span
fn da_bytes_used(&self) -> u64;
}

impl<P: Platform> SpanOpExt<P> for Span<P>
where
P: Platform<
NodeTypes: NodeTypes<
ChainSpec = types::ChainSpec<Optimism>,
Primitives = types::Primitives<Optimism>,
Payload = types::PayloadTypes<Optimism>,
>,
>,
{
fn da_bytes_used(&self) -> u64 {
self.iter().map(CheckpointOpExt::da_bytes_used).sum()
}
}

pub trait CheckpointOpExt<P: Platform> {
/// Data availability bytes used by this checkpoint.
fn da_bytes_used(&self) -> u64;

/// Returns the cumulative data availability bytes used by all checkpoints in
/// the history of this checkpoint, including this checkpoint itself.
fn cumulative_da_bytes_used(&self) -> u64;
}

impl<P: Platform> CheckpointOpExt<P> for Checkpoint<P>
where
P: Platform<
NodeTypes: NodeTypes<
ChainSpec = types::ChainSpec<Optimism>,
Primitives = types::Primitives<Optimism>,
Payload = types::PayloadTypes<Optimism>,
>,
>,
{
fn da_bytes_used(&self) -> u64 {
self.result().map_or(0, |result| result.da_bytes_used())
}

fn cumulative_da_bytes_used(&self) -> u64 {
self.history().da_bytes_used()
}
}
1 change: 1 addition & 0 deletions src/platform/optimism/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use {
serde::{Deserialize, Serialize},
};

pub mod ext;
mod limits;
pub use limits::OptimismDefaultLimits;

Expand Down
Loading