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    // TODO: Non-zero block number would be nice
35    /// Period of time in blocks after which the solution range is adjusted
36    pub retarget_interval: BlockNumber,
37    /// Slot probability
38    pub slot_probability: (u64, u64),
39    /// The slot duration in milliseconds
40    pub slot_duration: SlotDuration,
41    /// Number of latest archived segments that are considered "recent history"
42    pub recent_segments: HistorySize,
43    /// Fraction of pieces from the "recent history" (`recent_segments`) in each sector
44    pub recent_history_fraction: (HistorySize, HistorySize),
45    /// Minimum lifetime of a plotted sector, measured in archived segments
46    pub min_sector_lifetime: HistorySize,
47    /// Max block timestamp drift allowed
48    pub max_block_timestamp_drift: BlockTimestamp,
49    // TODO: Non-zero block number would be nice
50    /// Number of beacon chain blocks between shard rotations.
51    ///
52    /// Every this number of beacon chain blocks PoT entropy is taken to calculate the next shard
53    /// assignment.
54    pub shard_rotation_interval: BlockNumber,
55    /// Delay in beacon chain blocks for the next shard rotation.
56    ///
57    /// Delay after shard assignment is revealed before it actually takes effect (essentially the
58    /// amount of time for a node to sync the corresponding shard).
59    pub shard_rotation_delay: BlockNumber,
60}
61
62/// Notification with information about the block that is about to be imported and acknowledgement
63/// sender that can be used to pause block production if necessary
64#[derive(Debug, Clone)]
65pub struct BlockImportingNotification {
66    /// Block number
67    pub block_number: BlockNumber,
68    /// Sender for pausing the block import for archiving purposes is not fast enough to process
69    /// the consensus block
70    pub acknowledgement_sender: mpsc::Sender<()>,
71}