Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(protocol): BatchValidationProvider #189

Merged
merged 3 commits into from
Oct 27, 2024
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 @@ -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
Loading