1+ use crate :: sync:: progress:: ProgressPercentage ;
12use crate :: sync:: SyncState ;
23use std:: fmt;
34use std:: time:: Instant ;
@@ -8,7 +9,7 @@ pub struct BlockHeadersProgress {
89 /// Current sync state.
910 state : SyncState ,
1011 /// The tip height of the block-header storage.
11- current_height : u32 ,
12+ tip_height : u32 ,
1213 /// Equals to current_height (blockchain tip) when synced and to the best height of connected peers during initial sync.
1314 target_height : u32 ,
1415 /// Number of block-headers processed (stored) in the current sync session.
@@ -23,7 +24,7 @@ impl Default for BlockHeadersProgress {
2324 fn default ( ) -> Self {
2425 Self {
2526 state : SyncState :: default ( ) ,
26- current_height : 0 ,
27+ tip_height : 0 ,
2728 target_height : 0 ,
2829 processed : 0 ,
2930 buffered : 0 ,
@@ -33,35 +34,18 @@ impl Default for BlockHeadersProgress {
3334}
3435
3536impl BlockHeadersProgress {
36- /// Get completion percentage (0.0 to 1.0).
37- /// Includes buffered headers for more accurate progress during parallel sync.
38- pub fn percentage ( & self ) -> f64 {
39- if self . target_height == 0 {
40- return 1.0 ;
41- }
42- // Include buffered headers in progress calculation
43- ( self . effective_height ( ) as f64 / self . target_height as f64 ) . min ( 1.0 )
44- }
4537 /// Get the current sync state.
4638 pub fn state ( & self ) -> SyncState {
4739 self . state
4840 }
4941 /// Get the current height (last successfully processed height).
50- pub fn current_height ( & self ) -> u32 {
51- self . current_height
52- }
53- /// Get the target height (the best height of the connected peers)
54- pub fn target_height ( & self ) -> u32 {
55- self . target_height
42+ pub fn tip_height ( & self ) -> u32 {
43+ self . tip_height
5644 }
5745 /// Number of block-headers processed (stored) in the current sync session.
5846 pub fn processed ( & self ) -> u32 {
5947 self . processed
6048 }
61- /// Get the effective height (current_height + buffered).
62- pub fn effective_height ( & self ) -> u32 {
63- self . current_height + self . buffered
64- }
6549 /// The last time a block-header was stored to disk or the last manager state change.
6650 pub fn last_activity ( & self ) -> Instant {
6751 self . last_activity
@@ -71,9 +55,9 @@ impl BlockHeadersProgress {
7155 self . state = state;
7256 self . bump_last_activity ( ) ;
7357 }
74- /// Update the current height (last successfully processed height).
75- pub fn update_current_height ( & mut self , height : u32 ) {
76- self . current_height = height;
58+ /// Update the tip height (last successfully processed height).
59+ pub fn update_tip_height ( & mut self , height : u32 ) {
60+ self . tip_height = height;
7761 self . bump_last_activity ( ) ;
7862 }
7963 /// Update the target height (the best height of the connected peers).
@@ -110,7 +94,7 @@ impl fmt::Display for BlockHeadersProgress {
11094 f,
11195 "{:?} {}/{} ({:.1}%) processed: {}, buffered: {}, last_activity: {}s" ,
11296 self . state,
113- self . effective_height ( ) ,
97+ self . current_height ( ) ,
11498 self . target_height,
11599 pct,
116100 self . processed,
@@ -119,3 +103,14 @@ impl fmt::Display for BlockHeadersProgress {
119103 )
120104 }
121105}
106+
107+ impl ProgressPercentage for BlockHeadersProgress {
108+ fn target_height ( & self ) -> u32 {
109+ self . target_height
110+ }
111+ fn current_height ( & self ) -> u32 {
112+ // Use the effective height here for the progress to show more realistic values since
113+ // we download headers in parallel and the tip height is only updated when sequential segments complete.
114+ self . tip_height + self . buffered
115+ }
116+ }
0 commit comments