diff --git a/Cargo.toml b/Cargo.toml index 5ea3804..19871c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/src/payload/exec.rs b/src/payload/exec.rs index 6137d05..6d9ba54 100644 --- a/src/payload/exec.rs +++ b/src/payload/exec.rs @@ -428,15 +428,15 @@ impl IntoExecutable> #[derive(Debug, Clone, PartialEq)] pub struct ExecutionResult { /// The executable used to produce this result. - source: Executable

, + pub(crate) source: Executable

, /// 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>, + pub(crate) results: Vec>, /// The aggregated state executing all transactions from the source. - state: BundleState, + pub(crate) state: BundleState, } impl ExecutionResult

{ diff --git a/src/platform/optimism/ext.rs b/src/platform/optimism/ext.rs new file mode 100644 index 0000000..b84ca23 --- /dev/null +++ b/src/platform/optimism/ext.rs @@ -0,0 +1,84 @@ +use { + crate::{alloy, prelude::*, reth}, + alloy::eips::Encodable2718, + op_alloy_flz, + reth::api::NodeTypes, +}; + +pub trait ExecutionResultOpExt { + /// Data availability bytes used by this execution. + fn da_bytes_used(&self) -> u64; +} + +impl ExecutionResultOpExt

for ExecutionResult

+where + P: Platform< + NodeTypes: NodeTypes< + ChainSpec = types::ChainSpec, + Primitives = types::Primitives, + Payload = types::PayloadTypes, + >, + >, +{ + 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 { + /// Returns the total data availability bytes used by all checkpoints in this + /// span + fn da_bytes_used(&self) -> u64; +} + +impl SpanOpExt

for Span

+where + P: Platform< + NodeTypes: NodeTypes< + ChainSpec = types::ChainSpec, + Primitives = types::Primitives, + Payload = types::PayloadTypes, + >, + >, +{ + fn da_bytes_used(&self) -> u64 { + self.iter().map(CheckpointOpExt::da_bytes_used).sum() + } +} + +pub trait CheckpointOpExt { + /// 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 CheckpointOpExt

for Checkpoint

+where + P: Platform< + NodeTypes: NodeTypes< + ChainSpec = types::ChainSpec, + Primitives = types::Primitives, + Payload = types::PayloadTypes, + >, + >, +{ + 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() + } +} diff --git a/src/platform/optimism/mod.rs b/src/platform/optimism/mod.rs index 5f63d33..9fd16e9 100644 --- a/src/platform/optimism/mod.rs +++ b/src/platform/optimism/mod.rs @@ -20,6 +20,7 @@ use { serde::{Deserialize, Serialize}, }; +pub mod ext; mod limits; pub use limits::OptimismDefaultLimits;