Skip to content

Commit

Permalink
loooooooooooooooooooooooooooooooooooooooooooooooogs taiboku
Browse files Browse the repository at this point in the history
  • Loading branch information
junderw committed Sep 4, 2024
1 parent 58337f6 commit d4efede
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/new_index/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,10 @@ fn parse_blocks(blob: Vec<u8>, magic: u32) -> Result<Vec<SizedBlock>> {

while cursor.position() < max_pos {
let offset = cursor.position();
warn!("offset: {offset}");
match u32::consensus_decode(&mut cursor) {
Ok(value) => {
warn!("Magic: {magic}, Actual: {value}");
if magic != value {
cursor.set_position(offset + 1);
continue;
Expand All @@ -207,15 +209,18 @@ fn parse_blocks(blob: Vec<u8>, magic: u32) -> Result<Vec<SizedBlock>> {
Err(_) => break, // EOF
};
let block_size = u32::consensus_decode(&mut cursor).chain_err(|| "no block size")?;
warn!("Block size {block_size}");
let start = cursor.position();
let end = start + block_size as u64;
warn!("start {start}, end {end}");

// If Core's WriteBlockToDisk ftell fails, only the magic bytes and size will be written
// and the block body won't be written to the blk*.dat file.
// Since the first 4 bytes should contain the block's version, we can skip such blocks
// by peeking the cursor (and skipping previous `magic` and `block_size`).
match u32::consensus_decode(&mut cursor) {
Ok(value) => {
warn!("(edge case magic check) Magic: {magic}, Actual: {value}");
if magic == value {
cursor.set_position(start);
continue;
Expand All @@ -224,6 +229,7 @@ fn parse_blocks(blob: Vec<u8>, magic: u32) -> Result<Vec<SizedBlock>> {
Err(_) => break, // EOF
}
slices.push((&blob[start as usize..end as usize], block_size));
warn!("slices size: {}", slices.len());
cursor.set_position(end);
}

Expand Down

0 comments on commit d4efede

Please sign in to comment.