Skip to content

Commit

Permalink
fix(gc) - fix the chunk_tail <= tail invariant (#12207)
Browse files Browse the repository at this point in the history
According to this line in the storage checker, the chunk tail should
always be less or equal than the tail:

https://github.com/near/nearcore/blob/99ecfa4e8b97eda5e369d82ef00cfc06e5291552/chain/chain/src/store_validator/validate.rs#L146

This invariant is broken, I'm guessing since #12025 as shown by nayduck
gc test failing at this check:
https://nayduck.nearone.org/#/test/108874 - test1 stderr last line

This is a simple mitigation but I'm not 100% sure if correct - please
let me know if it makes sense or not.

Even if not entirely correct it should not cause any problems. At worst
gc will attempt to clean a little bit more data that isn't there. I
hope.

The only real change here is the added `saturating_sub(1)` to the line
where we set the tail.
  • Loading branch information
wacban authored Oct 11, 2024
1 parent 2b022a6 commit 16fd9e8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion chain/chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,13 @@ impl Chain {

tracing::debug!(target: "sync", ?min_height_included, ?new_tail, "adjusting tail for missing chunks");
new_tail = std::cmp::min(new_tail, min_height_included.saturating_sub(1));
let new_chunk_tail = prev_block.chunks().iter().map(|x| x.height_created()).min().unwrap();

// In order to find the right new_chunk_tail we need to find the minimum
// of chunk height_created for chunks in the new tail block.
let new_tail_block = self.get_block_by_height(new_tail)?;
let new_chunk_tail =
new_tail_block.chunks().iter().map(|chunk| chunk.height_created()).min().unwrap();

let tip = Tip::from_header(prev_block.header());
let final_head = Tip::from_header(self.genesis.header());
// Update related heads now.
Expand Down

0 comments on commit 16fd9e8

Please sign in to comment.