Skip to main content

dig_epoch/
lib.rs

1//! # dig-epoch
2//!
3//! Epoch geometry, phase machine, manager, and checkpoint-competition types
4//! for the DIG L2.
5//!
6//! ## Status of this file
7//!
8//! The crate was first stubbed by
9//! [`STR-001`](../docs/requirements/domains/crate_structure/specs/STR-001.md)
10//! (Cargo.toml dependency set only). The module tree below is introduced
11//! by [`STR-002`](../docs/requirements/domains/crate_structure/specs/STR-002.md)
12//! per [`SPEC.md § 13`](../docs/resources/SPEC.md) — each module is a stub
13//! whose real contents arrive in the per-domain requirements listed in
14//! [`IMPLEMENTATION_ORDER.md`](../docs/requirements/IMPLEMENTATION_ORDER.md).
15//!
16//! ## Philosophy
17//!
18//! `dig-epoch` is intentionally thin: all primitive types (blocks,
19//! checkpoints, hashes, BLS signatures, Merkle roots) come from the shared
20//! DIG / Chia ecosystem crates listed in `Cargo.toml`. This crate
21//! contributes the epoch-level *structure* (phases, arithmetic, reward
22//! splits, the checkpoint competition) that sits above those primitives.
23//!
24//! See [`docs/resources/SPEC.md`](../docs/resources/SPEC.md) for the
25//! authoritative crate specification.
26//!
27//! ## Module map (STR-002)
28//!
29//! The crate exposes a flat module tree with a single `types/` subdirectory:
30//!
31//! | Module              | Future owner        | Responsibility                               |
32//! |---------------------|---------------------|----------------------------------------------|
33//! | [`constants`]       | CON-001 … CON-006   | Compile-time epoch constants                 |
34//! | [`arithmetic`]      | HEA-001 … HEA-005   | Pure height-epoch mapping functions          |
35//! | [`phase`]           | PHS-001 … PHS-004   | L1-progress phase calculation                |
36//! | [`rewards`]         | REW-001 … REW-006   | Block-reward / distribution computation      |
37//! | [`manager`]         | STR-004, MGR-001…   | `EpochManager` struct + methods              |
38//! | [`verification`]    | VER-*               | Root-level verification free functions       |
39//! | [`dfsp`]            | DFS-*               | Root-level DFSP processing free functions    |
40//! | [`error`]           | ERR-001 … ERR-003   | `EpochError`, `CheckpointCompetitionError`   |
41//! | [`types`]           | TYP-*, CKP-*, REW-4 | Data types (see `types/mod.rs` for submods)  |
42//!
43//! Every module declared here is currently empty apart from a
44//! `#[doc(hidden)]` `STR_002_MODULE_PRESENT` sentinel; real content arrives
45//! one requirement at a time per `docs/requirements/IMPLEMENTATION_ORDER.md`.
46//!
47//! ## Re-exports
48//!
49//! None yet. Public re-exports arrive in
50//! [`STR-003`](../docs/requirements/domains/crate_structure/specs/STR-003.md),
51//! after the module hierarchy is in place. Consumers of STR-002 access
52//! items via their full path (e.g. `dig_epoch::constants::FOO`); the
53//! convenience `use dig_epoch::*` idiom becomes available only at STR-003.
54
55// `deny(missing_docs)` would be ideal for a public API crate, but turning it
56// on right now would force boilerplate docs on every subsequent requirement.
57// We instead enable the softer `warn` so that CI surfaces missing docs without
58// breaking the build while the module tree is still being fleshed out. This
59// is consistent with the rest of the DIG/Chia ecosystem where crate-level
60// docs are gated to the library target.
61#![warn(missing_docs)]
62
63// -----------------------------------------------------------------------------
64// Module declarations — STR-002 (SPEC §13)
65// -----------------------------------------------------------------------------
66//
67// Ordering rationale: the modules are declared in **responsibility order**
68// rather than alphabetical order so that a reader scanning `lib.rs` sees
69// the crate's data-flow narrative:
70//
71//   constants  → primitive compile-time values
72//   types      → data shapes that operate over those values
73//   arithmetic → pure height/epoch math on those shapes
74//   phase      → state machine derived from arithmetic
75//   rewards    → economic derivations (uses arithmetic + constants)
76//   manager    → stateful orchestrator that wires everything together
77//   verification, dfsp — cryptographic / protocol layers built on the
78//                        stateful manager
79//   error      — last so the error enum can reference the other modules
80//                without forward references
81//
82// Per STR-002, these are declarations only — no `pub use` re-exports yet.
83// Re-exports are the subject of STR-003, and adding them here would
84// foreshadow that requirement.
85
86/// Compile-time epoch constants. Filled by the `constants` domain (CON-*).
87pub mod constants;
88
89/// Data-type definitions for epochs, phases, events, rewards, and checkpoints.
90/// Filled by the `epoch_types` domain (TYP-*) and adjacent type-owning
91/// requirements (CKP-001 for the competition types, REW-004 for
92/// `RewardDistribution`).
93pub mod types;
94
95/// Pure height-to-epoch arithmetic. Filled by the `height_epoch_arithmetic`
96/// domain (HEA-*).
97pub mod arithmetic;
98
99/// L1-progress phase calculation. Filled by the `phase_state_machine`
100/// domain (PHS-*).
101pub mod phase;
102
103/// Block-reward and distribution computation. Filled by the
104/// `reward_economics` domain (REW-*).
105pub mod rewards;
106
107/// `EpochManager` struct and methods. Filled by STR-004 (constructor) and
108/// the `epoch_manager` domain (MGR-*).
109pub mod manager;
110
111/// Root-level verification free functions (epoch block root, inclusion
112/// proofs, checkpoint signing material). Filled by the `verification`
113/// domain (VER-*). **Note:** distinct from `types::verification`, which
114/// hosts the data types these functions produce/consume.
115pub mod verification;
116
117/// Root-level DFSP processing free functions (burn policy, digests,
118/// rollup, tail roots, activation control). Filled by the `dfsp_processing`
119/// domain (DFS-*). **Note:** distinct from `types::dfsp`, which hosts the
120/// seven DFSP data types from SPEC §3.14.
121pub mod dfsp;
122
123/// Crate-wide error enums (`EpochError`, `CheckpointCompetitionError`).
124/// Filled by the `error_types` domain (ERR-*).
125pub mod error;
126
127/// Reusable test fixtures (STR-005). Exposed as a public module so
128/// integration tests under `tests/` can use them. Not for production use —
129/// synthetic signatures and public keys do not verify cryptographically.
130pub mod test_helpers;
131
132// -----------------------------------------------------------------------------
133// STR-003 — flat public re-exports
134// -----------------------------------------------------------------------------
135//
136// Scope: every symbol reachable at `dig_epoch::<name>` corresponds to an
137// implemented requirement. DFSP processing (DFS-*) is deferred per
138// IMPLEMENTATION_ORDER.md, so its free functions are not re-exported here;
139// the `DfspCloseSnapshot` type (TYP-004) is exposed because it's referenced
140// by MGR-006 / the EpochInfo surface.
141
142// -- Manager (MGR-001, STR-004) ----------------------------------------------
143pub use manager::EpochManager;
144
145// -- Data types (TYP-*, CKP-001, REW-007, VER-004) ---------------------------
146pub use types::{
147    CheckpointCompetition, CompetitionStatus, DfspCloseSnapshot, EpochBlockLink,
148    EpochCheckpointData, EpochCheckpointSignMaterial, EpochEvent, EpochInfo, EpochPhase,
149    EpochStats, EpochSummary, PhaseTransition, RewardDistribution,
150};
151
152// -- Constants (CON-001..006) -------------------------------------------------
153pub use constants::*;
154
155// -- Height-epoch arithmetic (HEA-001..007) ----------------------------------
156pub use arithmetic::{
157    ensure_checkpoint_block_empty, epoch_checkpoint_height, epoch_for_block_height,
158    first_height_in_epoch, is_checkpoint_class_block, is_epoch_checkpoint_block,
159    is_first_block_after_epoch_checkpoint, is_genesis_checkpoint_block, l1_range_for_epoch,
160    last_committed_height_in_epoch,
161};
162
163// -- Phase machine (PHS-001) -------------------------------------------------
164pub use phase::l1_progress_phase_for_network_epoch;
165
166// -- Reward economics (REW-001..005) -----------------------------------------
167pub use rewards::{
168    block_reward_at_height, burned_fee_remainder, compute_reward_distribution,
169    epoch_reward_with_floor, proposer_fee_share, total_block_reward,
170};
171
172// -- Verification (VER-001..005) ---------------------------------------------
173pub use verification::{
174    compute_epoch_block_root, compute_epoch_withdrawals_root, epoch_block_inclusion_proof,
175    epoch_checkpoint_sign_material_from_l2_blocks,
176    stored_checkpoint_from_epoch_sign_material_with_aggregate_v1, verify_block_inclusion_proof,
177};
178
179// -- Errors (ERR-001..003) ---------------------------------------------------
180pub use error::{CheckpointCompetitionError, EpochError};
181
182// -- Ecosystem types used in public signatures -------------------------------
183//
184// Re-exported so consumers have a single-crate import surface. Start.md
185// Hard Requirement 1 forbids redefining these — we re-export the canonical
186// items from their owning crates instead.
187pub use chia_protocol::Bytes32;
188pub use dig_block::{Checkpoint, CheckpointSubmission};