@@ -30,8 +30,6 @@ pub struct Checkpoint {
3030 pub chain_work : String ,
3131 /// Masternode list identifier (e.g., "ML1088640__70218")
3232 pub masternode_list_name : Option < String > ,
33- /// Whether to include merkle root in validation
34- pub include_merkle_root : bool ,
3533 /// Protocol version at this checkpoint
3634 pub protocol_version : Option < u32 > ,
3735 /// Nonce value for the block
@@ -59,25 +57,12 @@ impl Checkpoint {
5957 }
6058}
6159
62- /// Checkpoint override settings
63- #[ derive( Debug , Clone , Default ) ]
64- pub struct CheckpointOverride {
65- /// Override checkpoint height for sync chain
66- pub sync_override_height : Option < u32 > ,
67- /// Override checkpoint height for terminal chain
68- pub terminal_override_height : Option < u32 > ,
69- /// Whether to sync from genesis
70- pub sync_from_genesis : bool ,
71- }
72-
7360/// Manages checkpoints for a specific network
7461pub struct CheckpointManager {
7562 /// Checkpoints indexed by height
7663 checkpoints : HashMap < u32 , Checkpoint > ,
7764 /// Sorted list of checkpoint heights for efficient searching
7865 sorted_heights : Vec < u32 > ,
79- /// Checkpoint override settings (not persisted)
80- override_settings : CheckpointOverride ,
8166}
8267
8368impl CheckpointManager {
@@ -96,7 +81,6 @@ impl CheckpointManager {
9681 Self {
9782 checkpoints : checkpoint_map,
9883 sorted_heights : heights,
99- override_settings : CheckpointOverride :: default ( ) ,
10084 }
10185 }
10286
@@ -135,11 +119,6 @@ impl CheckpointManager {
135119 & self . sorted_heights
136120 }
137121
138- /// Check if we're past the last checkpoint
139- pub fn is_past_last_checkpoint ( & self , height : u32 ) -> bool {
140- self . sorted_heights . last ( ) . is_none_or ( |& last| height > last)
141- }
142-
143122 /// Get the last checkpoint before a given timestamp
144123 pub fn last_checkpoint_before_timestamp ( & self , timestamp : u32 ) -> Option < & Checkpoint > {
145124 let mut best_checkpoint = None ;
@@ -155,55 +134,8 @@ impl CheckpointManager {
155134 best_checkpoint
156135 }
157136
158- /// Find the best checkpoint at or before a given height
159- pub fn best_checkpoint_at_or_before_height ( & self , height : u32 ) -> Option < & Checkpoint > {
160- let mut best_checkpoint = None ;
161- let mut best_height = 0 ;
162-
163- for checkpoint in self . checkpoints . values ( ) {
164- if checkpoint. height <= height && checkpoint. height >= best_height {
165- best_height = checkpoint. height ;
166- best_checkpoint = Some ( checkpoint) ;
167- }
168- }
169-
170- best_checkpoint
171- }
172-
173- /// Get the last checkpoint that has a masternode list
174- pub fn last_checkpoint_having_masternode_list ( & self ) -> Option < & Checkpoint > {
175- self . sorted_heights
176- . iter ( )
177- . rev ( )
178- . filter_map ( |height| self . checkpoints . get ( height) )
179- . find ( |checkpoint| checkpoint. has_masternode_list ( ) )
180- }
181-
182- /// Set override checkpoint for sync chain
183- pub fn set_sync_override ( & mut self , height : Option < u32 > ) {
184- self . override_settings . sync_override_height = height;
185- }
186-
187- /// Set override checkpoint for terminal chain
188- pub fn set_terminal_override ( & mut self , height : Option < u32 > ) {
189- self . override_settings . terminal_override_height = height;
190- }
191-
192- /// Set whether to sync from genesis
193- pub fn set_sync_from_genesis ( & mut self , from_genesis : bool ) {
194- self . override_settings . sync_from_genesis = from_genesis;
195- }
196-
197137 /// Get the checkpoint to use for sync chain based on override settings
198138 pub fn get_sync_checkpoint ( & self , wallet_creation_time : Option < u32 > ) -> Option < & Checkpoint > {
199- if self . override_settings . sync_from_genesis {
200- return self . get_checkpoint ( 0 ) ;
201- }
202-
203- if let Some ( override_height) = self . override_settings . sync_override_height {
204- return self . last_checkpoint_before_height ( override_height) ;
205- }
206-
207139 // Default to checkpoint based on wallet creation time
208140 if let Some ( creation_time) = wallet_creation_time {
209141 self . last_checkpoint_before_timestamp ( creation_time)
@@ -212,15 +144,6 @@ impl CheckpointManager {
212144 }
213145 }
214146
215- /// Get the checkpoint to use for terminal chain based on override settings
216- pub fn get_terminal_checkpoint ( & self ) -> Option < & Checkpoint > {
217- if let Some ( override_height) = self . override_settings . terminal_override_height {
218- self . last_checkpoint_before_height ( override_height)
219- } else {
220- self . last_checkpoint ( )
221- }
222- }
223-
224147 /// Check if a fork at the given height should be rejected due to checkpoint
225148 pub fn should_reject_fork ( & self , fork_height : u32 ) -> bool {
226149 if let Some ( last_checkpoint) = self . last_checkpoint ( ) {
@@ -229,32 +152,6 @@ impl CheckpointManager {
229152 false
230153 }
231154 }
232-
233- /// Validate a block header against checkpoints
234- pub fn validate_header (
235- & self ,
236- height : u32 ,
237- block_hash : & BlockHash ,
238- merkle_root : Option < & BlockHash > ,
239- ) -> bool {
240- if let Some ( checkpoint) = self . get_checkpoint ( height) {
241- // Check block hash
242- if checkpoint. block_hash != * block_hash {
243- return false ;
244- }
245-
246- // Check merkle root if required
247- if checkpoint. include_merkle_root {
248- if let ( Some ( expected) , Some ( actual) ) = ( & checkpoint. merkle_root , merkle_root) {
249- if expected != actual {
250- return false ;
251- }
252- }
253- }
254- }
255-
256- true
257- }
258155}
259156
260157/// Create mainnet checkpoints
@@ -445,7 +342,6 @@ fn create_checkpoint(
445342 merkle_root : Some ( parse_block_hash_safe ( merkle_root) ) ,
446343 chain_work : chain_work. to_string ( ) ,
447344 masternode_list_name : masternode_list. map ( |s| s. to_string ( ) ) ,
448- include_merkle_root : true ,
449345 protocol_version : masternode_list. and_then ( |ml| {
450346 // Extract protocol version from masternode list name
451347 ml. split ( "__" ) . nth ( 1 ) . and_then ( |s| s. parse ( ) . ok ( ) )
@@ -481,10 +377,6 @@ mod tests {
481377
482378 // Test no checkpoint at height
483379 assert ! ( manager. validate_block( 1 , & invalid_hash) ) ; // No checkpoint at height 1
484-
485- // Test header validation
486- assert ! ( manager. validate_header( 0 , & genesis_hash, None ) ) ;
487- assert ! ( !manager. validate_header( 0 , & invalid_hash, None ) ) ;
488380 }
489381
490382 #[ test]
@@ -544,27 +436,6 @@ mod tests {
544436 assert ! ( !checkpoint_no_version. has_masternode_list( ) ) ;
545437 }
546438
547- #[ test]
548- fn test_checkpoint_overrides ( ) {
549- let checkpoints = mainnet_checkpoints ( ) ;
550- let mut manager = CheckpointManager :: new ( checkpoints) ;
551-
552- // Test sync override
553- manager. set_sync_override ( Some ( 5000 ) ) ;
554- let sync_checkpoint = manager. get_sync_checkpoint ( None ) ;
555- assert_eq ! ( sync_checkpoint. expect( "Should have sync checkpoint" ) . height, 4991 ) ;
556-
557- // Test terminal override
558- manager. set_terminal_override ( Some ( 800000 ) ) ;
559- let terminal_checkpoint = manager. get_terminal_checkpoint ( ) ;
560- assert_eq ! ( terminal_checkpoint. expect( "Should have terminal checkpoint" ) . height, 750000 ) ;
561-
562- // Test sync from genesis
563- manager. set_sync_from_genesis ( true ) ;
564- let genesis_checkpoint = manager. get_sync_checkpoint ( None ) ;
565- assert_eq ! ( genesis_checkpoint. expect( "Should have genesis checkpoint" ) . height, 0 ) ;
566- }
567-
568439 #[ test]
569440 #[ ignore] // Test depends on specific mainnet checkpoint data
570441 fn test_fork_rejection ( ) {
@@ -579,19 +450,6 @@ mod tests {
579450 assert ! ( !manager. should_reject_fork( 2000000 ) ) ;
580451 }
581452
582- #[ test]
583- #[ ignore] // Test depends on specific mainnet checkpoint data
584- fn test_masternode_list_checkpoint ( ) {
585- let checkpoints = mainnet_checkpoints ( ) ;
586- let manager = CheckpointManager :: new ( checkpoints) ;
587-
588- // Find last checkpoint with masternode list
589- let ml_checkpoint = manager. last_checkpoint_having_masternode_list ( ) ;
590- assert ! ( ml_checkpoint. is_some( ) ) ;
591- assert ! ( ml_checkpoint. expect( "Should have ML checkpoint" ) . has_masternode_list( ) ) ;
592- assert_eq ! ( ml_checkpoint. expect( "Should have ML checkpoint" ) . height, 1900000 ) ;
593- }
594-
595453 #[ test]
596454 fn test_checkpoint_by_timestamp ( ) {
597455 let checkpoints = mainnet_checkpoints ( ) ;
0 commit comments