Skip to content

Commit

Permalink
feat: add counter for failed witness validations (near#12318)
Browse files Browse the repository at this point in the history
  • Loading branch information
pugachAG authored Oct 25, 2024
1 parent 2c95769 commit 10463b2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion chain/chain/src/stateless_validation/chunk_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,8 @@ impl Chain {
);
}
Err(err) => {
crate::stateless_validation::metrics::SHADOW_CHUNK_VALIDATION_FAILED_TOTAL
crate::stateless_validation::metrics::CHUNK_WITNESS_VALIDATION_FAILED_TOTAL
.with_label_values(&[&shard_id.to_string(), err.prometheus_label_value()])
.inc();
tracing::error!(
parent: &parent_span,
Expand Down
12 changes: 11 additions & 1 deletion chain/chain/src/stateless_validation/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use near_o11y::metrics::{
exponential_buckets, linear_buckets, try_create_histogram_vec, try_create_int_counter,
try_create_int_gauge, HistogramVec, IntCounter, IntGauge,
try_create_int_counter_vec, try_create_int_gauge, HistogramVec, IntCounter, IntCounterVec,
IntGauge,
};
use near_primitives::stateless_validation::state_witness::ChunkStateWitness;
use std::sync::LazyLock;
Expand Down Expand Up @@ -59,6 +60,15 @@ pub static SHADOW_CHUNK_VALIDATION_FAILED_TOTAL: LazyLock<IntCounter> = LazyLock
.unwrap()
});

pub static CHUNK_WITNESS_VALIDATION_FAILED_TOTAL: LazyLock<IntCounterVec> = LazyLock::new(|| {
try_create_int_counter_vec(
"near_chunk_witness_validation_failed_total",
"Witnesss validation failure count",
&["shard_id", "error"],
)
.unwrap()
});

pub(crate) static CHUNK_STATE_WITNESS_VALIDATION_TIME: LazyLock<HistogramVec> =
LazyLock::new(|| {
try_create_histogram_vec(
Expand Down
4 changes: 4 additions & 0 deletions chain/client/src/stateless_validation/chunk_validator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl ChunkValidator {
signer: &Arc<ValidatorSigner>,
) -> Result<(), Error> {
let prev_block_hash = state_witness.chunk_header.prev_block_hash();
let shard_id = state_witness.chunk_header.shard_id();
let epoch_id = self.epoch_manager.get_epoch_id_from_prev_block(prev_block_hash)?;
if epoch_id != state_witness.epoch_id {
return Err(Error::InvalidChunkStateWitness(format!(
Expand Down Expand Up @@ -183,6 +184,9 @@ impl ChunkValidator {
);
}
Err(err) => {
near_chain::stateless_validation::metrics::CHUNK_WITNESS_VALIDATION_FAILED_TOTAL
.with_label_values(&[&shard_id.to_string(), err.prometheus_label_value()])
.inc();
if panic_on_validation_error {
panic!("Failed to validate chunk: {:?}", err);
} else {
Expand Down

0 comments on commit 10463b2

Please sign in to comment.