Skip to content

Commit

Permalink
nit(stateless_validation) - Gracefully handle genesis in orphan witne…
Browse files Browse the repository at this point in the history
…ss cleanup (near#11483)

This error is annoying in integration tests and localnet.
  • Loading branch information
wacban authored Jun 6, 2024
1 parent 82e9c62 commit cceb7b5
Showing 1 changed file with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use crate::Client;
use near_chain::Block;
use near_chain_primitives::Error;
use near_primitives::hash::CryptoHash;
use near_primitives::stateless_validation::ChunkStateWitness;
use near_primitives::types::BlockHeight;
use std::ops::Range;
Expand Down Expand Up @@ -101,21 +102,23 @@ impl Client {

// Remove all orphan witnesses that are below the last final block of the new block.
// They won't be used, so we can remove them from the pool to save memory.
let last_final_block =
match self.chain.get_block_header(new_block.header().last_final_block()) {
Ok(block_header) => block_header,
Err(err) => {
// TODO(wacban) this error happens often in integration
// tests when the last final block is genesis / genesis.prev.
tracing::error!(
target: "client",
last_final_block = ?new_block.header().last_final_block(),
?err,
"Error getting last final block of the new block"
);
return;
}
};
let last_final_block = new_block.header().last_final_block();
// Handle genesis gracefully.
if last_final_block == &CryptoHash::default() {
return;
}
let last_final_block = match self.chain.get_block_header(last_final_block) {
Ok(block_header) => block_header,
Err(err) => {
tracing::error!(
target: "client",
?last_final_block,
?err,
"Error getting last final block of the new block"
);
return;
}
};
self.chunk_validator
.orphan_witness_pool
.remove_witnesses_below_final_height(last_final_block.height());
Expand Down

0 comments on commit cceb7b5

Please sign in to comment.