ab_client_block_import/
lib.rs1pub mod beacon_chain;
2mod importing_blocks;
3#[cfg(test)]
4mod test_utils;
5
6use ab_client_api::{BlockOrigin, PersistBlockError};
7use ab_core_primitives::block::BlockRoot;
8use ab_core_primitives::hashes::Blake3Hash;
9
10#[derive(Debug, thiserror::Error)]
12pub enum BlockImportError {
13 #[error("Already importing")]
15 AlreadyImporting,
16 #[error("Already imported")]
18 AlreadyImported,
19 #[error("Unknown parent block: {block_root}")]
21 UnknownParentBlock {
22 block_root: BlockRoot,
24 },
25 #[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("Invalid state root: expected {expected}, actual {actual}")]
44 InvalidStateRoot {
45 expected: Blake3Hash,
46 actual: Blake3Hash,
47 },
48 #[error("Block persisting error: {error}")]
50 PersistBlockError {
51 #[from]
53 error: PersistBlockError,
54 },
55 #[error("Custom import error: {error}")]
57 Custom {
58 #[from]
60 error: anyhow::Error,
61 },
62}
63
64pub trait BlockImport<Block>: Send + Sync {
66 fn import(
72 &self,
73 block: Block,
75 origin: BlockOrigin,
76 ) -> Result<impl Future<Output = Result<(), BlockImportError>> + Send, BlockImportError>;
77}