At dash-spv/src/storage/disk/state.rs line 66 we can see the following:
let mut state = ChainState::default(); // This state has a sync_base_height of 0
// Load all headers
if let Some(tip_height) = self.get_tip_height().await? {
let range_start = state.sync_base_height; // = 0
state.headers = self.load_headers(range_start..tip_height + 1).await?; // Panics bcs the test that is executing this with sync_base_height = 12345
}
This logic is executed when state/chain.json exists and we try to load all headers to store them in ChainState. Some lines below same happends with the FilterHeaders
Maybe is time to refactor the ChainState behaviour or just remove the fields where we store this headers, doesn't make sense having them stored in two different ways in runtime.
Other way to solve this would be to allow load_headers to recieve height lower than sync_base_height and retrieve all the headers stored