mirror of
https://github.com/romanz/electrs.git
synced 2025-02-24 06:57:53 +01:00
Fix the error by adding skip processing when incomplete data is included in the RAW block file
If Core's WriteBlockToDisk ftell fails, only the magic byte and size will be written and the block body will be unwritten data. skip that's data.
This commit is contained in:
parent
0858b627e1
commit
536d3362b8
1 changed files with 13 additions and 0 deletions
13
src/bulk.rs
13
src/bulk.rs
|
@ -138,6 +138,19 @@ fn parse_blocks(blob: Vec<u8>, magic: u32) -> Result<Vec<Block>> {
|
|||
.chain_err(|| format!("seek {} failed", block_size))?;
|
||||
let end = cursor.position() as usize;
|
||||
|
||||
// If Core's WriteBlockToDisk ftell fails, only the magic byte and size will be written
|
||||
// and the block body will be unwritten data. skip that's data.
|
||||
let mut tmp_cursor = Cursor::new(&blob[start..(start + 4)]);
|
||||
match u32::consensus_decode(&mut tmp_cursor){
|
||||
Ok(value) => {
|
||||
if magic == value{
|
||||
cursor.set_position(start as u64);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Err(_) => break, // EOF
|
||||
}
|
||||
|
||||
let block: Block = deserialize(&blob[start..end])
|
||||
.chain_err(|| format!("failed to parse block at {}..{}", start, end))?;
|
||||
blocks.push(block);
|
||||
|
|
Loading…
Add table
Reference in a new issue