ab_client_consensus_common/
lib.rs

1#![expect(incomplete_features, reason = "generic_const_exprs")]
2// TODO: This feature is not actually used in this crate, but is added as a workaround for
3//  https://github.com/rust-lang/rust/issues/141492
4#![feature(generic_const_exprs, get_mut_unchecked)]
5
6pub mod consensus_parameters;
7pub mod state;
8
9use ab_core_primitives::block::{BlockNumber, BlockTimestamp};
10use ab_core_primitives::pot::{SlotDuration, SlotNumber};
11use ab_core_primitives::segments::HistorySize;
12use futures::channel::mpsc;
13
14/// Proof-of-time consensus constants
15#[derive(Debug, PartialEq, Eq, Clone, Copy)]
16pub struct PotConsensusConstants {
17    /// Interval, in blocks, between blockchain entropy injection into the proof of time chain
18    pub entropy_injection_interval: BlockNumber,
19    /// Interval, in entropy injection intervals, where to take entropy for injection from
20    pub entropy_injection_lookback_depth: u8,
21    /// Delay after block, in slots, when entropy injection takes effect
22    pub entropy_injection_delay: SlotNumber,
23}
24
25/// Consensus constants
26#[derive(Debug, PartialEq, Eq, Clone, Copy)]
27pub struct ConsensusConstants {
28    /// Depth `K` after which a block enters the recorded history
29    pub confirmation_depth_k: BlockNumber,
30    /// Number of slots between slot arrival and when the corresponding block can be produced
31    pub block_authoring_delay: SlotNumber,
32    /// Proof-of-time consensus constants
33    pub pot: PotConsensusConstants,
34    /// Period of time in blocks after which the solution range is adjusted
35    pub retarget_interval: BlockNumber,
36    /// Slot probability
37    pub slot_probability: (u64, u64),
38    /// The slot duration in milliseconds
39    pub slot_duration: SlotDuration,
40    /// Number of latest archived segments that are considered "recent history"
41    pub recent_segments: HistorySize,
42    /// Fraction of pieces from the "recent history" (`recent_segments`) in each sector
43    pub recent_history_fraction: (HistorySize, HistorySize),
44    /// Minimum lifetime of a plotted sector, measured in archived segments
45    pub min_sector_lifetime: HistorySize,
46    /// Max block timestamp drift allowed
47    pub max_block_timestamp_drift: BlockTimestamp,
48}
49
50/// Notification with information about the block that is about to be imported and acknowledgement
51/// sender that can be used to pause block production if necessary
52#[derive(Debug, Clone)]
53pub struct BlockImportingNotification {
54    /// Block number
55    pub block_number: BlockNumber,
56    /// Sender for pausing the block import for archiving purposes is not fast enough to process
57    /// the consensus block
58    pub acknowledgement_sender: mpsc::Sender<()>,
59}