Skip to main content

ab_client_consensus_common/
lib.rs

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