ab_client_block_import/
lib.rs1#![feature(map_try_insert)]
2#![expect(incomplete_features, reason = "generic_const_exprs")]
3#![feature(generic_const_exprs)]
6
7pub mod beacon_chain;
8mod importing_blocks;
9
10use ab_client_api::{BlockOrigin, PersistBlockError};
11use ab_core_primitives::block::BlockRoot;
12
13#[derive(Debug, thiserror::Error)]
15pub enum BlockImportError {
16 #[error("Already importing")]
18 AlreadyImporting,
19 #[error("Already imported")]
21 AlreadyImported,
22 #[error("Unknown parent block: {block_root}")]
24 UnknownParentBlock {
25 block_root: BlockRoot,
27 },
28 #[error("Parent block MMR missing; this is an implementation bug and must never happen")]
30 ParentBlockMmrMissing,
31 #[error("Invalid parent MMR; this is an implementation bug and must never happen")]
33 ParentBlockMmrInvalid,
34 #[error(
36 "Can't extend MMR, too many blocks; this is an implementation bug and must never happen"
37 )]
38 CantExtendMmr,
39 #[error("Parent block import failed")]
41 ParentBlockImportFailed,
42 #[error("Block persisting error: {error}")]
44 PersistBlockError {
45 #[from]
47 error: PersistBlockError,
48 },
49 #[error("Custom import error: {error}")]
51 Custom {
52 #[from]
54 error: anyhow::Error,
55 },
56}
57
58pub trait BlockImport<Block>: Send + Sync {
60 fn import(
66 &self,
67 block: Block,
69 origin: BlockOrigin,
70 ) -> Result<impl Future<Output = Result<(), BlockImportError>> + Send, BlockImportError>;
71}