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::{LocalSegmentIndex, 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 segments")]
36 InvalidOwnSegments {
37 expected_first_local_segment_index: Option<LocalSegmentIndex>,
39 expected_segment_roots: Vec<SegmentRoot>,
41 actual_first_local_segment_index: Option<LocalSegmentIndex>,
43 actual_segment_roots: Vec<SegmentRoot>,
45 },
46 #[error("Shard membership entropy source error: {error}")]
48 ShardMembershipEntropySource {
49 #[from]
51 error: ShardMembershipEntropySourceError,
52 },
53 #[error("Custom verification error: {error}")]
55 Custom {
56 #[from]
58 error: anyhow::Error,
59 },
60}
61
62pub trait BlockVerification<Block>: Send + Sync
64where
65 Block: GenericOwnedBlock,
66{
67 fn verify_concurrent<BCI>(
87 &self,
88 parent_header: &GenericHeader<'_, Block>,
89 parent_block_mmr_root: &Blake3Hash,
90 header: &GenericHeader<'_, Block>,
91 body: &GenericBody<'_, Block>,
92 origin: &BlockOrigin,
93 beacon_chain_info: &BCI,
94 ) -> impl Future<Output = Result<(), BlockVerificationError>> + Send
95 where
96 BCI: DeriveConsensusParametersChainInfo + ShardMembershipEntropySourceChainInfo;
97
98 fn verify_sequential(
101 &self,
102 parent_header: &GenericHeader<'_, Block>,
103 parent_block_mmr_root: &Blake3Hash,
104 header: &GenericHeader<'_, Block>,
105 body: &GenericBody<'_, Block>,
106 origin: &BlockOrigin,
107 ) -> impl Future<Output = Result<(), BlockVerificationError>> + Send;
108}