diff --git a/chain/chain/src/chain.rs b/chain/chain/src/chain.rs index a371a3c65a1..1f011f7a1a6 100644 --- a/chain/chain/src/chain.rs +++ b/chain/chain/src/chain.rs @@ -768,7 +768,9 @@ impl Chain { // the block might not have been what the block producer originally produced. Either way, it's // OK if we miss some cases here because this is just an optimization to avoid reprocessing // known invalid blocks so the network recovers faster in case of any issues. - if error.is_bad_data() && !matches!(error, Error::InvalidSignature) { + if error.is_bad_data() + && !matches!(error, Error::InvalidSignature | Error::InvalidBlockHeight(_)) + { metrics::NUM_INVALID_BLOCKS.with_label_values(&[error.prometheus_label_value()]).inc(); self.invalid_blocks.put(block_hash, ()); } diff --git a/chain/chain/src/garbage_collection.rs b/chain/chain/src/garbage_collection.rs index 58dc584b615..0f4088e77bc 100644 --- a/chain/chain/src/garbage_collection.rs +++ b/chain/chain/src/garbage_collection.rs @@ -141,6 +141,10 @@ impl ChainStore { let _span = tracing::debug_span!(target: "garbage_collection", "clear_data").entered(); let tries = runtime_adapter.get_tries(); let head = self.head()?; + if head.height == self.get_genesis_height() { + // Nothing to do if head is at genesis. Return early because some of the later queries would fail. + return Ok(()); + } let tail = self.tail()?; let gc_stop_height = runtime_adapter.get_gc_stop_height(&head.last_block_hash); if gc_stop_height > head.height {