Skip to content

Commit 0c12e18

Browse files
authored
feat(op): checkpoint/span ext for da bytes (#80)
1 parent e71e401 commit 0c12e18

File tree

4 files changed

+89
-3
lines changed

4 files changed

+89
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ reth-ipc = { git = "https://github.com/paradigmxyz/reth", tag = "v1.8.2", option
141141

142142
# Reth-optimism dependencies (optional)
143143
op-alloy = { version = "0.20.0", features = ["full"], optional = true }
144+
op-alloy-flz = "0.13.1"
144145
reth-optimism-node = { git = "https://github.com/paradigmxyz/reth", tag = "v1.8.2", optional = true }
145146
reth-optimism-chainspec = { git = "https://github.com/paradigmxyz/reth", tag = "v1.8.2", optional = true }
146147
reth-optimism-forks = { git = "https://github.com/paradigmxyz/reth", tag = "v1.8.2", optional = true }

src/payload/exec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,15 +428,15 @@ impl<P: PlatformWithRpcTypes> IntoExecutable<P, Variant<7>>
428428
#[derive(Debug, Clone, PartialEq)]
429429
pub struct ExecutionResult<P: Platform> {
430430
/// The executable used to produce this result.
431-
source: Executable<P>,
431+
pub(crate) source: Executable<P>,
432432

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

438438
/// The aggregated state executing all transactions from the source.
439-
state: BundleState,
439+
pub(crate) state: BundleState,
440440
}
441441

442442
impl<P: Platform> ExecutionResult<P> {

src/platform/optimism/ext.rs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
use {
2+
crate::{alloy, prelude::*, reth},
3+
alloy::eips::Encodable2718,
4+
op_alloy_flz,
5+
reth::api::NodeTypes,
6+
};
7+
8+
pub trait ExecutionResultOpExt<P: Platform> {
9+
/// Data availability bytes used by this execution.
10+
fn da_bytes_used(&self) -> u64;
11+
}
12+
13+
impl<P: Platform> ExecutionResultOpExt<P> for ExecutionResult<P>
14+
where
15+
P: Platform<
16+
NodeTypes: NodeTypes<
17+
ChainSpec = types::ChainSpec<Optimism>,
18+
Primitives = types::Primitives<Optimism>,
19+
Payload = types::PayloadTypes<Optimism>,
20+
>,
21+
>,
22+
{
23+
fn da_bytes_used(&self) -> u64 {
24+
self
25+
.source
26+
.transactions()
27+
.iter()
28+
.map(|tx| {
29+
op_alloy_flz::tx_estimated_size_fjord_bytes(
30+
tx.encoded_2718().as_slice(),
31+
)
32+
})
33+
.sum()
34+
}
35+
}
36+
37+
pub trait SpanOpExt<P: Platform> {
38+
/// Returns the total data availability bytes used by all checkpoints in this
39+
/// span
40+
fn da_bytes_used(&self) -> u64;
41+
}
42+
43+
impl<P: Platform> SpanOpExt<P> for Span<P>
44+
where
45+
P: Platform<
46+
NodeTypes: NodeTypes<
47+
ChainSpec = types::ChainSpec<Optimism>,
48+
Primitives = types::Primitives<Optimism>,
49+
Payload = types::PayloadTypes<Optimism>,
50+
>,
51+
>,
52+
{
53+
fn da_bytes_used(&self) -> u64 {
54+
self.iter().map(CheckpointOpExt::da_bytes_used).sum()
55+
}
56+
}
57+
58+
pub trait CheckpointOpExt<P: Platform> {
59+
/// Data availability bytes used by this checkpoint.
60+
fn da_bytes_used(&self) -> u64;
61+
62+
/// Returns the cumulative data availability bytes used by all checkpoints in
63+
/// the history of this checkpoint, including this checkpoint itself.
64+
fn cumulative_da_bytes_used(&self) -> u64;
65+
}
66+
67+
impl<P: Platform> CheckpointOpExt<P> for Checkpoint<P>
68+
where
69+
P: Platform<
70+
NodeTypes: NodeTypes<
71+
ChainSpec = types::ChainSpec<Optimism>,
72+
Primitives = types::Primitives<Optimism>,
73+
Payload = types::PayloadTypes<Optimism>,
74+
>,
75+
>,
76+
{
77+
fn da_bytes_used(&self) -> u64 {
78+
self.result().map_or(0, |result| result.da_bytes_used())
79+
}
80+
81+
fn cumulative_da_bytes_used(&self) -> u64 {
82+
self.history().da_bytes_used()
83+
}
84+
}

src/platform/optimism/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use {
2020
serde::{Deserialize, Serialize},
2121
};
2222

23+
pub mod ext;
2324
mod limits;
2425
pub use limits::OptimismDefaultLimits;
2526

0 commit comments

Comments
 (0)