Skip to content

Commit

Permalink
Fix rewind code. The order of operations was an issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bayk committed Mar 20, 2021
1 parent cb05d9d commit be2836f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,9 @@ impl Chain {
// Cleanup all subsequent bad blocks (back from old head).
let mut current = batch.get_block_header(&old_head.hash())?;
while current.height > new_head.height {
let prev_block = batch.get_previous_header(&current)?;
let _ = batch.delete_block(&current.hash());
current = batch.get_previous_header(&current)?;
current = prev_block;
}

batch.commit()?;
Expand All @@ -329,8 +330,9 @@ impl Chain {
// cleanup all subsequent bad headers (back from old header_head).
let mut current = batch.get_block_header(&old_header_head.hash())?;
while current.height > new_head.height {
let prev_hdr = batch.get_previous_header(&current)?;
let _ = batch.delete_block_header(&current.hash());
current = batch.get_previous_header(&current)?;
current = prev_hdr;
}

batch.commit()?;
Expand Down

0 comments on commit be2836f

Please sign in to comment.