@@ -16,6 +16,7 @@ pub mod protocol;
1616pub mod rank_search;
1717pub mod tie_breaking;
1818pub mod umc_cascade;
19+ pub mod umc_cascade_persistence;
1920
2021pub struct GroupMetadata {
2122 conflict_genesis : Hash ,
@@ -34,6 +35,16 @@ pub struct DagknightCounters {
3435 total_cascade_flips : AtomicU64 ,
3536 /// Maximum flips in a single cascade run
3637 max_cascade_flips : AtomicU64 ,
38+ /// Number of UMC cascade calls that started from a persisted checkpoint
39+ checkpoint_from_checkpoint : AtomicU64 ,
40+ /// Number of UMC cascade calls that started from scratch
41+ checkpoint_from_scratch : AtomicU64 ,
42+ /// Total estimated effort saved across all checkpoint loads,
43+ /// representing estimated blue blocks skipped by checkpointing
44+ checkpoint_estimated_effort_saved : AtomicU64 ,
45+ /// Total estimated effort across all UMC calls (sum of virtual_gd.blue_score).
46+ /// Used as denominator for effort_saved percentage.
47+ checkpoint_estimated_effort_total : AtomicU64 ,
3748 /// Baseline true, cascade false
3849 #[ cfg( feature = "baseline-debugging" ) ]
3950 baseline_true_cascade_false : AtomicU64 ,
@@ -55,6 +66,10 @@ impl DagknightCounters {
5566 total_voting_blocks : AtomicU64 :: new ( 0 ) ,
5667 total_cascade_flips : AtomicU64 :: new ( 0 ) ,
5768 max_cascade_flips : AtomicU64 :: new ( 0 ) ,
69+ checkpoint_from_checkpoint : AtomicU64 :: new ( 0 ) ,
70+ checkpoint_from_scratch : AtomicU64 :: new ( 0 ) ,
71+ checkpoint_estimated_effort_saved : AtomicU64 :: new ( 0 ) ,
72+ checkpoint_estimated_effort_total : AtomicU64 :: new ( 0 ) ,
5873 #[ cfg( feature = "baseline-debugging" ) ]
5974 baseline_true_cascade_false : AtomicU64 :: new ( 0 ) ,
6075 #[ cfg( feature = "baseline-debugging" ) ]
@@ -90,13 +105,28 @@ impl DagknightCounters {
90105 }
91106 }
92107
108+ /// Record checkpoint persistence statistics from a single run_cascade call.
109+ pub fn record_checkpoint_stats ( & self , from_checkpoint : bool , estimated_effort_saved : u64 , estimated_effort_total : u64 ) {
110+ if from_checkpoint {
111+ self . checkpoint_from_checkpoint . fetch_add ( 1 , Ordering :: Relaxed ) ;
112+ } else {
113+ self . checkpoint_from_scratch . fetch_add ( 1 , Ordering :: Relaxed ) ;
114+ }
115+ self . checkpoint_estimated_effort_saved . fetch_add ( estimated_effort_saved, Ordering :: Relaxed ) ;
116+ self . checkpoint_estimated_effort_total . fetch_add ( estimated_effort_total, Ordering :: Relaxed ) ;
117+ }
118+
93119 /// Take a point-in-time snapshot of all counters.
94120 pub fn snapshot ( & self ) -> DagknightCountersSnapshot {
95121 DagknightCountersSnapshot {
96122 total_calls : self . total_calls . load ( Ordering :: Relaxed ) ,
97123 total_voting_blocks : self . total_voting_blocks . load ( Ordering :: Relaxed ) ,
98124 total_cascade_flips : self . total_cascade_flips . load ( Ordering :: Relaxed ) ,
99125 max_cascade_flips : self . max_cascade_flips . load ( Ordering :: Relaxed ) ,
126+ checkpoint_from_checkpoint : self . checkpoint_from_checkpoint . load ( Ordering :: Relaxed ) ,
127+ checkpoint_from_scratch : self . checkpoint_from_scratch . load ( Ordering :: Relaxed ) ,
128+ checkpoint_estimated_effort_saved : self . checkpoint_estimated_effort_saved . load ( Ordering :: Relaxed ) ,
129+ checkpoint_estimated_effort_total : self . checkpoint_estimated_effort_total . load ( Ordering :: Relaxed ) ,
100130 #[ cfg( feature = "baseline-debugging" ) ]
101131 baseline_true_cascade_false : self . baseline_true_cascade_false . load ( Ordering :: Relaxed ) ,
102132 #[ cfg( feature = "baseline-debugging" ) ]
@@ -112,6 +142,14 @@ pub struct DagknightCountersSnapshot {
112142 pub total_voting_blocks : u64 ,
113143 pub total_cascade_flips : u64 ,
114144 pub max_cascade_flips : u64 ,
145+ /// Number of UMC cascade calls that started from a persisted checkpoint
146+ pub checkpoint_from_checkpoint : u64 ,
147+ /// Number of UMC cascade calls that started from scratch
148+ pub checkpoint_from_scratch : u64 ,
149+ /// Total estimated effort saved across all checkpoint loads
150+ pub checkpoint_estimated_effort_saved : u64 ,
151+ /// Total estimated effort across all UMC calls (sum of virtual_gd.blue_score)
152+ pub checkpoint_estimated_effort_total : u64 ,
115153 #[ cfg( feature = "baseline-debugging" ) ]
116154 pub baseline_true_cascade_false : u64 ,
117155 #[ cfg( feature = "baseline-debugging" ) ]
@@ -129,6 +167,21 @@ impl DagknightCountersSnapshot {
129167 if self . total_calls == 0 { 0.0 } else { self . total_cascade_flips as f64 / self . total_calls as f64 }
130168 }
131169
170+ /// Percentage of UMC calls that used a checkpoint.
171+ pub fn checkpoint_hit_rate ( & self ) -> f64 {
172+ let total = self . checkpoint_from_checkpoint + self . checkpoint_from_scratch ;
173+ if total == 0 { 0.0 } else { self . checkpoint_from_checkpoint as f64 / total as f64 * 100.0 }
174+ }
175+
176+ /// Percentage of blue work saved by checkpointing relative to total blue work in conflict zones.
177+ pub fn checkpoint_effort_saved ( & self ) -> f64 {
178+ if self . checkpoint_estimated_effort_total == 0 {
179+ 0.0
180+ } else {
181+ self . checkpoint_estimated_effort_saved as f64 / self . checkpoint_estimated_effort_total as f64 * 100.0
182+ }
183+ }
184+
132185 /// Percentage of calls where baseline accepted and cascade rejected.
133186 #[ cfg( feature = "baseline-debugging" ) ]
134187 pub fn baseline_true_cascade_false_percentage ( & self ) -> f64 {
@@ -151,6 +204,14 @@ impl std::ops::Sub for &DagknightCountersSnapshot {
151204 total_voting_blocks : self . total_voting_blocks . saturating_sub ( rhs. total_voting_blocks ) ,
152205 total_cascade_flips : self . total_cascade_flips . saturating_sub ( rhs. total_cascade_flips ) ,
153206 max_cascade_flips : 0 , // max doesn't subtract meaningfully
207+ checkpoint_from_checkpoint : self . checkpoint_from_checkpoint . saturating_sub ( rhs. checkpoint_from_checkpoint ) ,
208+ checkpoint_from_scratch : self . checkpoint_from_scratch . saturating_sub ( rhs. checkpoint_from_scratch ) ,
209+ checkpoint_estimated_effort_saved : self
210+ . checkpoint_estimated_effort_saved
211+ . saturating_sub ( rhs. checkpoint_estimated_effort_saved ) ,
212+ checkpoint_estimated_effort_total : self
213+ . checkpoint_estimated_effort_total
214+ . saturating_sub ( rhs. checkpoint_estimated_effort_total ) ,
154215 #[ cfg( feature = "baseline-debugging" ) ]
155216 baseline_true_cascade_false : self . baseline_true_cascade_false . saturating_sub ( rhs. baseline_true_cascade_false ) ,
156217 #[ cfg( feature = "baseline-debugging" ) ]
0 commit comments