@@ -218,26 +218,27 @@ impl<S: StorageManager + Send + Sync + 'static, N: NetworkManager + Send + Sync
218218 }
219219
220220 /// Convert absolute blockchain height to block header storage index.
221- /// In checkpoint sync, headers storage starts at (base + 1) .
221+ /// Storage indexing is base-inclusive: at checkpoint base B, storage index 0 == absolute height B .
222222 fn header_abs_to_storage_index ( & self , height : u32 ) -> Option < u32 > {
223223 if self . sync_base_height > 0 {
224- height. checked_sub ( self . sync_base_height + 1 )
224+ height. checked_sub ( self . sync_base_height )
225225 } else {
226226 Some ( height)
227227 }
228228 }
229229
230230 /// Convert block header storage index to absolute blockchain height.
231+ /// Storage indexing is base-inclusive: at checkpoint base B, absolute height == B + index.
231232 fn header_storage_to_abs_height ( & self , index : u32 ) -> u32 {
232233 if self . sync_base_height > 0 {
233- self . sync_base_height + 1 + index
234+ self . sync_base_height + index
234235 } else {
235236 index
236237 }
237238 }
238239
239240 /// Convert absolute blockchain height to filter header storage index.
240- /// In checkpoint sync, filter headers storage starts at base (checkpoint height) .
241+ /// Storage indexing is base-inclusive for filter headers as well .
241242 fn filter_abs_to_storage_index ( & self , height : u32 ) -> Option < u32 > {
242243 if self . sync_base_height > 0 {
243244 height. checked_sub ( self . sync_base_height )
@@ -2062,18 +2063,16 @@ impl<S: StorageManager + Send + Sync + 'static, N: NetworkManager + Send + Sync
20622063 start_height : u32 ,
20632064 end_height : u32 ,
20642065 ) -> SyncResult < Option < u32 > > {
2065- // Use the efficient reverse index first. Note: storage returns STORAGE height (index),
2066- // we must convert it to BLOCKCHAIN (absolute) height when comparing with [start,end] .
2067- if let Some ( storage_height ) =
2066+ // Use the efficient reverse index first.
2067+ // Contract: StorageManager::get_header_height_by_hash returns ABSOLUTE blockchain height.
2068+ if let Some ( abs_height ) =
20682069 storage. get_header_height_by_hash ( block_hash) . await . map_err ( |e| {
20692070 SyncError :: Storage ( format ! ( "Failed to get header height by hash: {}" , e) )
20702071 } ) ?
20712072 {
2072- // Convert storage-relative height to blockchain height (accounts for checkpoint base)
2073- let absolute_height = self . header_storage_to_abs_height ( storage_height) ;
20742073 // Check if the absolute height is within the requested range
2075- if absolute_height >= start_height && absolute_height <= end_height {
2076- return Ok ( Some ( absolute_height ) ) ;
2074+ if abs_height >= start_height && abs_height <= end_height {
2075+ return Ok ( Some ( abs_height ) ) ;
20772076 }
20782077 }
20792078 Ok ( None )
0 commit comments