Skip to main content

ab_client_consensus_common/
lib.rs

1#![feature(option_into_flat_iter)]
2#![expect(incomplete_features, reason = "generic_const_exprs")]
3// TODO: This feature is not actually used in this crate, but is added as a workaround for
4//  https://github.com/rust-lang/rust/issues/141492
5#![feature(generic_const_exprs, get_mut_unchecked)]
6
7pub mod consensus_parameters;
8pub mod state;
9
10use ab_core_primitives::block::{BlockNumber, BlockTimestamp};
11use ab_core_primitives::pot::{SlotDuration, SlotNumber};
12use ab_core_primitives::segments::HistorySize;
13use futures::channel::mpsc;
14
15/// Proof-of-time consensus constants
16#[derive(Debug, PartialEq, Eq, Clone, Copy)]
17pub struct PotConsensusConstants {
18    /// Interval, in blocks, between blockchain entropy injection into the proof of time chain
19    pub entropy_injection_interval: BlockNumber,
20    /// Interval, in entropy injection intervals, where to take entropy for injection from
21    pub entropy_injection_lookback_depth: u8,
22    /// Delay after block, in slots, when entropy injection takes effect
23    pub entropy_injection_delay: SlotNumber,
24}
25
26/// Consensus constants
27#[derive(Debug, PartialEq, Eq, Clone, Copy)]
28pub struct ConsensusConstants {
29    /// Depth after which a block enters the recorded history.
30    ///
31    /// This is from the perspective of the individual shard, with additional confirmation on the
32    /// beacon chain required for intermediate and leaf shards (see `shard_confirmation_depth`).
33    pub block_confirmation_depth: BlockNumber,
34    /// Depth on the beacon chain in addition to `block_confirmation_depth` after intermediate or
35    /// leaf shard information on the beacon chain is confirmed and corresponding segment roots
36    /// become a part of the super segment.
37    ///
38    /// This is separate from the block confirmation on the corresponding shard itself, which
39    /// happens much sooner (see `block_confirmation_depth`), but can't be immediately trusted by
40    /// the beacon chain.
41    pub shard_confirmation_depth: BlockNumber,
42    /// Number of slots between slot arrival and when the corresponding block can be produced
43    pub block_authoring_delay: SlotNumber,
44    /// Proof-of-time consensus constants
45    pub pot: PotConsensusConstants,
46    // TODO: Non-zero block number would be nice
47    /// Period of time in blocks after which the solution range is adjusted
48    pub retarget_interval: BlockNumber,
49    /// Slot probability
50    pub slot_probability: (u64, u64),
51    /// The slot duration in milliseconds
52    pub slot_duration: SlotDuration,
53    /// Number of latest archived segments that are considered "recent history"
54    pub recent_segments: HistorySize,
55    /// Fraction of pieces from the "recent history" (`recent_segments`) in each sector
56    pub recent_history_fraction: (HistorySize, HistorySize),
57    /// Minimum lifetime of a plotted sector, measured in archived segments
58    pub min_sector_lifetime: HistorySize,
59    /// Max block timestamp drift allowed
60    pub max_block_timestamp_drift: BlockTimestamp,
61    // TODO: Non-zero block number would be nice
62    /// Number of beacon chain blocks between shard rotations.
63    ///
64    /// Every this number of beacon chain blocks PoT entropy is taken to calculate the next shard
65    /// assignment.
66    pub shard_rotation_interval: BlockNumber,
67    /// Delay in beacon chain blocks for the next shard rotation.
68    ///
69    /// Delay after shard assignment is revealed before it actually takes effect (essentially the
70    /// amount of time for a node to sync the corresponding shard).
71    pub shard_rotation_delay: BlockNumber,
72}
73
74/// Notification with information about the block that is about to be imported and acknowledgement
75/// sender that can be used to pause block production if necessary
76#[derive(Debug, Clone)]
77pub struct BlockImportingNotification {
78    /// Block number
79    pub block_number: BlockNumber,
80    /// Sender for pausing the block import for archiving purposes is not fast enough to process
81    /// the consensus block
82    pub acknowledgement_sender: mpsc::Sender<()>,
83}