ab_client_block_verification/
lib.rs1pub mod beacon_chain;
2
3use ab_client_api::BlockOrigin;
4use ab_client_consensus_common::consensus_parameters::{
5 DeriveConsensusParametersChainInfo, ShardMembershipEntropySourceChainInfo,
6 ShardMembershipEntropySourceError,
7};
8use ab_core_primitives::block::body::owned::GenericOwnedBlockBody;
9use ab_core_primitives::block::header::owned::GenericOwnedBlockHeader;
10use ab_core_primitives::block::owned::GenericOwnedBlock;
11use ab_core_primitives::hashes::Blake3Hash;
12use ab_core_primitives::segments::SegmentRoot;
13
14type GenericHeader<'a, Block> =
15 <<Block as GenericOwnedBlock>::Header as GenericOwnedBlockHeader>::Header<'a>;
16type GenericBody<'a, Block> =
17 <<Block as GenericOwnedBlock>::Body as GenericOwnedBlockBody>::Body<'a>;
18
19#[derive(Debug, thiserror::Error)]
21pub enum BlockVerificationError {
22 #[error("Block is below archiving point")]
24 BelowArchivingPoint,
25 #[error("Invalid header prefix")]
27 InvalidHeaderPrefix,
28 #[error("Timestamp too far in the future")]
30 TimestampTooFarInTheFuture,
31 #[error("Invalid seal")]
33 InvalidSeal,
34 #[error("Invalid own segment roots")]
36 InvalidOwnSegmentRoots {
37 expected: Vec<SegmentRoot>,
39 actual: Vec<SegmentRoot>,
41 },
42 #[error("Shard membership entropy source error: {error}")]
44 ShardMembershipEntropySource {
45 #[from]
47 error: ShardMembershipEntropySourceError,
48 },
49 #[error("Custom verification error: {error}")]
51 Custom {
52 #[from]
54 error: anyhow::Error,
55 },
56}
57
58pub trait BlockVerification<Block>: Send + Sync
60where
61 Block: GenericOwnedBlock,
62{
63 fn verify_concurrent<BCI>(
83 &self,
84 parent_header: &GenericHeader<'_, Block>,
85 parent_block_mmr_root: &Blake3Hash,
86 header: &GenericHeader<'_, Block>,
87 body: &GenericBody<'_, Block>,
88 origin: &BlockOrigin,
89 beacon_chain_info: &BCI,
90 ) -> impl Future<Output = Result<(), BlockVerificationError>> + Send
91 where
92 BCI: DeriveConsensusParametersChainInfo + ShardMembershipEntropySourceChainInfo;
93
94 fn verify_sequential(
97 &self,
98 parent_header: &GenericHeader<'_, Block>,
99 parent_block_mmr_root: &Blake3Hash,
100 header: &GenericHeader<'_, Block>,
101 body: &GenericBody<'_, Block>,
102 origin: &BlockOrigin,
103 ) -> impl Future<Output = Result<(), BlockVerificationError>> + Send;
104}