@@ -498,23 +498,18 @@ impl<S: StorageManager + Send + Sync + 'static, N: NetworkManager + Send + Sync
498498 let stop_hash = if next_batch_end_height < header_tip_height {
499499 // Try to get the header at the calculated height
500500 // Convert blockchain height to storage height
501- let storage_height = match self
501+ let storage_height = self
502502 . header_abs_to_storage_index ( next_batch_end_height)
503- {
504- Some ( v) => v,
505- None => {
503+ . unwrap_or_else ( || {
506504 tracing:: warn!(
507505 "next_batch_end_height {} is at or before checkpoint base {}" ,
508506 next_batch_end_height,
509507 self . sync_base_height
510508 ) ;
511509 // Fallback to current_sync_height
512- match self . header_abs_to_storage_index ( self . current_sync_height ) {
513- Some ( v) => v,
514- None => 0 ,
515- }
516- }
517- } ;
510+ self . header_abs_to_storage_index ( self . current_sync_height )
511+ . unwrap_or_default ( )
512+ } ) ;
518513 match storage. get_header ( storage_height) . await {
519514 Ok ( Some ( header) ) => header. block_hash ( ) ,
520515 Ok ( None ) => {
@@ -617,10 +612,7 @@ impl<S: StorageManager + Send + Sync + 'static, N: NetworkManager + Send + Sync
617612 // Special handling for chain tip: if we can't find the exact tip header,
618613 // try the previous header as we might be at the actual chain tip
619614 let tip_storage_height =
620- match self . header_abs_to_storage_index ( header_tip_height) {
621- Some ( v) => v,
622- None => 0 ,
623- } ;
615+ self . header_abs_to_storage_index ( header_tip_height) . unwrap_or_default ( ) ;
624616 match storage. get_header ( tip_storage_height) . await {
625617 Ok ( Some ( header) ) => header. block_hash ( ) ,
626618 Ok ( None ) if header_tip_height > 0 => {
@@ -630,11 +622,9 @@ impl<S: StorageManager + Send + Sync + 'static, N: NetworkManager + Send + Sync
630622 header_tip_height
631623 ) ;
632624 // Try previous header when at chain tip
633- let prev_storage_height =
634- match self . header_abs_to_storage_index ( header_tip_height - 1 ) {
635- Some ( v) => v,
636- None => 0 ,
637- } ;
625+ let prev_storage_height = self
626+ . header_abs_to_storage_index ( header_tip_height - 1 )
627+ . unwrap_or_default ( ) ;
638628 storage
639629 . get_header ( prev_storage_height)
640630 . await
@@ -1577,10 +1567,7 @@ impl<S: StorageManager + Send + Sync + 'static, N: NetworkManager + Send + Sync
15771567 let batch_end = ( current_height + batch_size - 1 ) . min ( end) ;
15781568
15791569 // Get stop hash for this batch - convert blockchain height to storage index
1580- let storage_height = match self . header_abs_to_storage_index ( batch_end) {
1581- Some ( v) => v,
1582- None => 0 ,
1583- } ;
1570+ let storage_height = self . header_abs_to_storage_index ( batch_end) . unwrap_or_default ( ) ;
15841571 let stop_hash = storage
15851572 . get_header ( storage_height)
15861573 . await
@@ -1907,10 +1894,7 @@ impl<S: StorageManager + Send + Sync + 'static, N: NetworkManager + Send + Sync
19071894 }
19081895
19091896 // Calculate stop hash for retry - convert blockchain height to storage index
1910- let storage_height = match self . header_abs_to_storage_index ( end) {
1911- Some ( v) => v,
1912- None => 0 ,
1913- } ;
1897+ let storage_height = self . header_abs_to_storage_index ( end) . unwrap_or_default ( ) ;
19141898 match storage. get_header ( storage_height) . await {
19151899 Ok ( Some ( header) ) => {
19161900 let stop_hash = header. block_hash ( ) ;
@@ -3349,10 +3333,7 @@ impl<S: StorageManager + Send + Sync + 'static, N: NetworkManager + Send + Sync
33493333 }
33503334
33513335 // Calculate stop hash for this range - convert blockchain height to storage index
3352- let storage_height = match self . header_abs_to_storage_index ( end) {
3353- Some ( v) => v,
3354- None => 0 ,
3355- } ;
3336+ let storage_height = self . header_abs_to_storage_index ( end) . unwrap_or_default ( ) ;
33563337 match storage. get_header ( storage_height) . await {
33573338 Ok ( Some ( header) ) => {
33583339 let stop_hash = header. block_hash ( ) ;
@@ -3389,10 +3370,7 @@ impl<S: StorageManager + Send + Sync + 'static, N: NetworkManager + Send + Sync
33893370
33903371 // Get stop hash for this batch - convert blockchain height to storage index
33913372 let batch_storage_height =
3392- match self . header_abs_to_storage_index ( batch_end) {
3393- Some ( v) => v,
3394- None => 0 ,
3395- } ;
3373+ self . header_abs_to_storage_index ( batch_end) . unwrap_or_default ( ) ;
33963374 match storage. get_header ( batch_storage_height) . await {
33973375 Ok ( Some ( batch_header) ) => {
33983376 let batch_stop_hash = batch_header. block_hash ( ) ;
0 commit comments