Skip to content

Commit

Permalink
feat(protocol): BatchValidationProvider (#189)
Browse files Browse the repository at this point in the history
### Description

Part of a port migrating the batch types from `kona-derive` to
`op-alloy`. See
[`kona#695`](anton-rs/kona#695).

This PR introduces a validation trait that is used for span batch
validity checks.
  • Loading branch information
refcell authored Oct 27, 2024
1 parent 96666d1 commit f831e15
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jsonrpsee-core = "0.24"
jsonrpsee-types = "0.24"

# misc
async-trait = "0.1.83"
cfg-if = "1"
spin = { version = "0.9.8", features = ["mutex"] }
derive_more = { version = "1.0", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions crates/protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ alloy-consensus.workspace = true

# Misc
derive_more.workspace = true
async-trait.workspace = true

# `arbitrary` feature
arbitrary = { workspace = true, features = ["derive"], optional = true }
Expand Down
3 changes: 3 additions & 0 deletions crates/protocol/src/batch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ pub use validity::BatchValidity;

mod single;
pub use single::SingleBatch;

mod traits;
pub use traits::BatchValidationProvider;
25 changes: 25 additions & 0 deletions crates/protocol/src/batch/traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! Traits for working with protocol types.

use alloc::{boxed::Box, string::ToString};
use async_trait::async_trait;
use core::fmt::Display;
use op_alloy_consensus::OpBlock;

use crate::L2BlockInfo;

/// Describes the functionality of a data source that fetches safe blocks.
#[async_trait]
pub trait BatchValidationProvider {
/// The error type for the [BatchValidationProvider].
type Error: Display + ToString;

/// Returns the [L2BlockInfo] given a block number.
///
/// Errors if the block does not exist.
async fn l2_block_info_by_number(&mut self, number: u64) -> Result<L2BlockInfo, Self::Error>;

/// Returns the [OpBlock] for a given number.
///
/// Errors if no block is available for the given block number.
async fn block_by_number(&mut self, number: u64) -> Result<OpBlock, Self::Error>;
}
5 changes: 4 additions & 1 deletion crates/protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
extern crate alloc;

mod batch;
pub use batch::{BatchType, BatchValidity, SingleBatch, SINGLE_BATCH_TYPE, SPAN_BATCH_TYPE};
pub use batch::{
BatchType, BatchValidationProvider, BatchValidity, SingleBatch, SINGLE_BATCH_TYPE,
SPAN_BATCH_TYPE,
};

mod block;
pub use block::{BlockInfo, FromBlockError, L2BlockInfo};
Expand Down

0 comments on commit f831e15

Please sign in to comment.