|
| 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 | +} |
0 commit comments