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")]
27 ParentBlockMmrInvalid,
28 #[error(
30 "Can't extend MMR, too many blocks; this is an implementation bug and must never happen"
31 )]
32 CantExtendMmr,
33 #[error("Parent block import failed")]
35 ParentBlockImportFailed,
36 #[error("Invalid state root: expected {expected}, actual {actual}")]
38 InvalidStateRoot {
39 expected: Blake3Hash,
40 actual: Blake3Hash,
41 },
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
58#[derive(Debug, Clone)]
60pub struct BlockImportedNotification<Block> {
61 pub block: Block,
63 pub is_new_best: bool,
68}
69
70pub trait BlockImport<Block>: Send + Sync {
72 fn import(
78 &self,
79 block: Block,
81 origin: BlockOrigin,
82 ) -> Result<impl Future<Output = Result<(), BlockImportError>> + Send, BlockImportError>;
83}