ab_client_block_import/
lib.rs1pub mod beacon_chain;
2mod importing_blocks;
3
4use ab_client_api::{BlockOrigin, PersistBlockError};
5use ab_core_primitives::block::BlockRoot;
6use ab_core_primitives::hashes::Blake3Hash;
7
8#[derive(Debug, thiserror::Error)]
10pub enum BlockImportError {
11 #[error("Already importing")]
13 AlreadyImporting,
14 #[error("Already imported")]
16 AlreadyImported,
17 #[error("Unknown parent block: {block_root}")]
19 UnknownParentBlock {
20 block_root: BlockRoot,
22 },
23 #[error("Invalid parent MMR; this is an implementation bug and must never happen")]
31 ParentBlockMmrInvalid,
32 #[error(
34 "Can't extend MMR, too many blocks; this is an implementation bug and must never happen"
35 )]
36 CantExtendMmr,
37 #[error("Parent block import failed")]
39 ParentBlockImportFailed,
40 #[error("Invalid state root: expected {expected}, actual {actual}")]
42 InvalidStateRoot {
43 expected: Blake3Hash,
44 actual: Blake3Hash,
45 },
46 #[error("Block persisting error: {error}")]
48 PersistBlockError {
49 #[from]
51 error: PersistBlockError,
52 },
53 #[error("Custom import error: {error}")]
55 Custom {
56 #[from]
58 error: anyhow::Error,
59 },
60}
61
62pub trait BlockImport<Block>: Send + Sync {
64 fn import(
70 &self,
71 block: Block,
73 origin: BlockOrigin,
74 ) -> Result<impl Future<Output = Result<(), BlockImportError>> + Send, BlockImportError>;
75}