Skip to content

Commit aab45b9

Browse files
authored
Merge pull request #23 from hl-archive-node/fix/handle-hl-node-termination
fix: Handle incomplete line when handling local-block-ingest
2 parents f6cea35 + 0ce6b81 commit aab45b9

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

bin/reth/src/block_ingest.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,23 @@ fn scan_hour_file(path: &Path, last_line: &mut usize, start_height: u64) -> Scan
7373
continue;
7474
}
7575

76-
let LocalBlockAndReceipts(_block_timestamp, parsed_block): LocalBlockAndReceipts =
77-
serde_json::from_str(&line).expect("Failed to parse local block and receipts");
76+
let (_block_timestamp, parsed_block) = match serde_json::from_str(&line) {
77+
Ok(LocalBlockAndReceipts(_block_timestamp, parsed_block)) => {
78+
(_block_timestamp, parsed_block)
79+
}
80+
Err(_) => {
81+
// Possible scenarios:
82+
let is_last_line = line_idx == lines.len() - 1;
83+
if is_last_line {
84+
// 1. It's not written fully yet - in this case, just wait for the next line
85+
break;
86+
} else {
87+
// 2. hl-node previously terminated while writing the lines
88+
// In this case, try to skip this line
89+
continue;
90+
}
91+
}
92+
};
7893

7994
let height = match &parsed_block.block {
8095
EvmBlock::Reth115(b) => {

0 commit comments

Comments
 (0)