@@ -127,7 +127,14 @@ impl MasternodeSyncManager {
127127 // Check if the terminal block exists in our chain
128128 match storage. get_header ( terminal_height) . await {
129129 Ok ( Some ( header) ) => {
130- if header. block_hash ( ) == expected_hash {
130+ let actual_hash = header. block_hash ( ) ;
131+ tracing:: info!(
132+ "Terminal block validation at height {}: expected hash {}, actual hash {}" ,
133+ terminal_height,
134+ expected_hash,
135+ actual_hash
136+ ) ;
137+ if actual_hash == expected_hash {
131138 if has_precalculated_data {
132139 tracing:: info!(
133140 "Using terminal block at height {} with pre-calculated masternode data as base for sync" ,
@@ -184,34 +191,40 @@ impl MasternodeSyncManager {
184191 return Ok ( 0 ) ;
185192 }
186193
187- // Convert blockchain height to storage height
188- let storage_height = terminal_height - sync_base_height;
194+ // When syncing from checkpoint, storage uses absolute blockchain heights
195+ // No need to convert - just use terminal_height directly
196+ let storage_height = terminal_height;
189197
190198 // Check if the terminal block exists in our chain
191199 match storage. get_header ( storage_height) . await {
192200 Ok ( Some ( header) ) => {
193- if header. block_hash ( ) == expected_hash {
201+ let actual_hash = header. block_hash ( ) ;
202+ tracing:: info!(
203+ "Terminal block validation at height {}: expected hash {}, actual hash {}" ,
204+ terminal_height,
205+ expected_hash,
206+ actual_hash
207+ ) ;
208+ if actual_hash == expected_hash {
194209 if has_precalculated_data {
195210 tracing:: info!(
196- "Using terminal block at blockchain height {} (storage height {}) with pre-calculated masternode data as base for sync" ,
197- terminal_height,
198- storage_height
211+ "Using terminal block at height {} with pre-calculated masternode data as base for sync" ,
212+ terminal_height
199213 ) ;
200214 } else {
201215 tracing:: info!(
202- "Using terminal block at blockchain height {} (storage height {}) as base for masternode sync (no pre-calculated data)" ,
203- terminal_height,
204- storage_height
216+ "Using terminal block at height {} as base for masternode sync (no pre-calculated data)" ,
217+ terminal_height
205218 ) ;
206219 }
207220 Ok ( terminal_height)
208221 } else {
209222 let msg = if has_precalculated_data {
210- "Terminal block hash mismatch at blockchain height {} (storage height {}) (with pre-calculated data) - falling back to genesis"
223+ "Terminal block hash mismatch at height {} (with pre-calculated data) - falling back to genesis"
211224 } else {
212- "Terminal block hash mismatch at blockchain height {} (storage height {}) (without pre-calculated data) - falling back to genesis"
225+ "Terminal block hash mismatch at height {} (without pre-calculated data) - falling back to genesis"
213226 } ;
214- tracing:: warn!( msg, terminal_height, storage_height ) ;
227+ tracing:: warn!( msg, terminal_height) ;
215228 Ok ( 0 )
216229 }
217230 }
@@ -1053,21 +1066,10 @@ impl MasternodeSyncManager {
10531066 current_height : u32 ,
10541067 sync_base_height : u32 ,
10551068 ) -> SyncResult < ( ) > {
1056- // Convert blockchain heights to storage heights
1057- let storage_base_height = if base_height >= sync_base_height {
1058- base_height - sync_base_height
1059- } else {
1060- 0
1061- } ;
1062-
1063- let storage_current_height = if current_height >= sync_base_height {
1064- current_height - sync_base_height
1065- } else {
1066- return Err ( SyncError :: InvalidState ( format ! (
1067- "Current height {} is less than sync base height {}" ,
1068- current_height, sync_base_height
1069- ) ) ) ;
1070- } ;
1069+ // When syncing from checkpoint, storage uses absolute blockchain heights
1070+ // No need to convert
1071+ let storage_base_height = base_height;
1072+ let storage_current_height = current_height;
10711073
10721074 // Verify the storage height actually exists
10731075 let storage_tip = storage
@@ -1086,7 +1088,7 @@ impl MasternodeSyncManager {
10861088
10871089 // Use the storage tip as the current height
10881090 let adjusted_storage_height = storage_tip;
1089- let adjusted_blockchain_height = storage_tip + sync_base_height ;
1091+ let adjusted_blockchain_height = storage_tip; // Storage already uses blockchain heights
10901092
10911093 // Update the heights to use what's actually available
10921094 // Don't recurse - just continue with adjusted values
@@ -1402,8 +1404,8 @@ impl MasternodeSyncManager {
14021404 . await
14031405 . map_err ( |e| SyncError :: Storage ( format ! ( "Failed to lookup target hash: {}" , e) ) ) ?
14041406 {
1405- // Convert storage height to blockchain height
1406- let blockchain_target_height = storage_target_height + self . sync_base_height ;
1407+ // Storage already uses blockchain heights when syncing from checkpoint
1408+ let blockchain_target_height = storage_target_height;
14071409 engine. feed_block_height ( blockchain_target_height, target_block_hash) ;
14081410 tracing:: debug!(
14091411 "Fed target block hash {} at blockchain height {} (storage height {})" ,
@@ -1437,8 +1439,8 @@ impl MasternodeSyncManager {
14371439 . await
14381440 . map_err ( |e| SyncError :: Storage ( format ! ( "Failed to lookup base hash: {}" , e) ) ) ?
14391441 {
1440- // Convert storage height to blockchain height
1441- let blockchain_base_height = storage_base_height + self . sync_base_height ;
1442+ // Storage already uses blockchain heights when syncing from checkpoint
1443+ let blockchain_base_height = storage_base_height;
14421444 engine. feed_block_height ( blockchain_base_height, base_block_hash) ;
14431445 tracing:: debug!(
14441446 "Fed base block hash {} at blockchain height {} (storage height {})" ,
@@ -1479,9 +1481,8 @@ impl MasternodeSyncManager {
14791481 {
14801482 // Only feed blocks at or after start_height to avoid redundant submissions
14811483 if storage_quorum_height >= storage_start_height {
1482- // Convert storage height to blockchain height
1483- let blockchain_quorum_height =
1484- storage_quorum_height + self . sync_base_height ;
1484+ // Storage already uses blockchain heights when syncing from checkpoint
1485+ let blockchain_quorum_height = storage_quorum_height;
14851486
14861487 // Check if this block hash is already known to avoid duplicate feeds
14871488 if !engine. block_container . contains_hash ( & quorum. quorum_hash ) {
@@ -1525,8 +1526,8 @@ impl MasternodeSyncManager {
15251526 ) ?;
15261527
15271528 for ( storage_height, header) in headers {
1528- // Convert storage height to blockchain height
1529- let blockchain_height = storage_height + self . sync_base_height ;
1529+ // Storage already uses blockchain heights when syncing from checkpoint
1530+ let blockchain_height = storage_height;
15301531 let block_hash = header. block_hash ( ) ;
15311532
15321533 // Only feed if not already known
0 commit comments