1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//! # `arithmetic` — pure height-to-epoch mapping functions
//!
//! **Introduced by:** `STR-002` — Module hierarchy (SPEC §13).
//!
//! **Owners:** HEA-001 through HEA-004 (Phase 4).
//!
//! **Spec reference:** [`SPEC.md` §5](../../docs/resources/SPEC.md)
/// Sentinel marker proving the module exists and is reachable at
/// `dig_epoch::arithmetic::STR_002_MODULE_PRESENT`.
pub const STR_002_MODULE_PRESENT: = ;
use crate;
use crateEpochError;
// -----------------------------------------------------------------------------
// HEA-001 — epoch_for_block_height
// -----------------------------------------------------------------------------
/// Maps an L2 block height to its epoch number.
///
/// Formula: `(height - 1) / BLOCKS_PER_EPOCH`
///
/// Height 1 is genesis (epoch 0). Requires `height >= 1`.
// -----------------------------------------------------------------------------
// HEA-002 — first_height_in_epoch / epoch_checkpoint_height
// -----------------------------------------------------------------------------
/// Returns the first L2 block height in the given epoch.
///
/// Formula: `epoch * BLOCKS_PER_EPOCH + 1`
/// Returns the checkpoint (last) L2 block height in the given epoch.
///
/// Formula: `(epoch + 1) * BLOCKS_PER_EPOCH`
// -----------------------------------------------------------------------------
// HEA-003 — Checkpoint block detection
// -----------------------------------------------------------------------------
/// Returns true if `height` is the genesis checkpoint block (height == GENESIS_HEIGHT).
/// Returns true if `height` is an epoch checkpoint block (divisible by BLOCKS_PER_EPOCH).
/// Returns true if `height` is genesis or an epoch checkpoint block.
/// Enforces the empty-checkpoint-block invariant.
///
/// Returns `Ok(())` for non-checkpoint heights regardless of parameters.
/// Returns `Err(EpochError::CheckpointBlockNotEmpty)` if any count is non-zero
/// at a checkpoint-class height.
// -----------------------------------------------------------------------------
// HEA-004 — l1_range_for_epoch
// -----------------------------------------------------------------------------
/// Returns the `(start_l1_height, end_l1_height)` for a given epoch.
///
/// The range is inclusive. Each epoch's L1 window is `EPOCH_L1_BLOCKS` wide.
// -----------------------------------------------------------------------------
// HEA-006 — last_committed_height_in_epoch
// -----------------------------------------------------------------------------
/// Returns the last L2 height included in this epoch's checkpoint.
///
/// Caps at `epoch_checkpoint_height(epoch)` even if `tip_height` is higher.
// -----------------------------------------------------------------------------
// HEA-007 — is_first_block_after_epoch_checkpoint
// -----------------------------------------------------------------------------
/// Returns true if `height` is the first block after an epoch checkpoint.
///
/// True at h=33, 65, 97, … — each epoch's opening block after epoch 0.