Skip to content

Commit 5fe1e83

Browse files
Update dash-spv/src/storage/memory.rs
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent ae8a1fa commit 5fe1e83

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

dash-spv/src/storage/memory.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff 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>> {

0 commit comments

Comments
 (0)