Browse Source

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.
chaintope/fix-wrong-block-pos
azuchi 6 years ago
parent
commit
536d3362b8
  1. 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…
Cancel
Save