File tree Expand file tree Collapse file tree 1 file changed +9
-19
lines changed Expand file tree Collapse file tree 1 file changed +9
-19
lines changed Original file line number Diff line number Diff line change @@ -152,25 +152,15 @@ impl StorageManager for MemoryStorageManager {
152152 }
153153
154154 async fn get_header ( & self , height : u32 ) -> StorageResult < Option < BlockHeader > > {
155- // Accept blockchain (absolute) height; convert to storage index using base (if any)
156- let base = match self . load_sync_state ( ) . await {
157- Ok ( Some ( state) ) if state. synced_from_checkpoint && state. sync_base_height > 0 => {
158- state. sync_base_height
159- }
160- _ => 0u32 ,
161- } ;
162-
163- // If a base is present and the requested height is below the base, no header exists.
164- if base > 0 && height < base {
165- return Ok ( None ) ;
166- }
167- // Map absolute height to storage index
168- let idx = if base > 0 {
169- ( height - base) as usize
170- } else {
171- height as usize
172- } ;
173- Ok ( self . headers . get ( idx) . copied ( ) )
155+ async fn get_header ( & self , height : u32 ) -> StorageResult < Option < BlockHeader > > {
156+ let sync_base_height = * self . sync_base_height . read ( ) . await ;
157+ if sync_base_height > 0 && height < sync_base_height {
158+ return Ok ( None ) ;
159+ }
160+ // Convert absolute height to storage index (base-inclusive mapping)
161+ let idx = ( height. saturating_sub ( sync_base_height) ) as usize ;
162+ Ok ( self . headers . get ( idx) . cloned ( ) )
163+ }
174164 }
175165
176166 async fn get_tip_height ( & self ) -> StorageResult < Option < u32 > > {
You can’t perform that action at this time.
0 commit comments