Skip to content

Commit

Permalink
Merge branch 'master' into automated-update-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiEres authored Aug 1, 2024
2 parents 113831d + e1fc26b commit 648182b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ futures = "0.3.30"
futures-util = "0.3.27"
hex = "0.4.3"
itertools = "0.12.1"
log = "0.4.21"
log = "0.4.22"
mockall = "0.11.4"
parity-db = "0.4.13"
prometheus-endpoint = { package = "substrate-prometheus-endpoint", git = "https://github.com/paritytech/polkadot-sdk", branch = "master" }
Expand All @@ -42,7 +42,7 @@ rasciigraph = "0.2.0"
reqwest = { version = "0.11.27" }
rocksdb = "0.21.0"
serde = "1.0.203"
serde_bytes = "0.11.14"
serde_bytes = "0.11.15"
serde_derive = "1.0.138"
serde_json = "1.0.117"
serde_urlencoded = "0.7.1"
Expand Down
14 changes: 13 additions & 1 deletion parachain-tracer/src/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ pub struct ParachainTracerPrometheusOptions {
struct DisputesMetrics {
/// Number of candidates disputed.
disputed_count: IntCounterVec,
/// Average count of validators that voted in favor of supermajority
concluded_valid: IntCounterVec,
concluded_invalid: IntCounterVec,
/// Average count of validators that voted against supermajority
concluded_invalid: IntCounterVec,
/// Average resolution time in blocks
resolution_time: HistogramVec,
}
Expand Down Expand Up @@ -179,10 +180,21 @@ impl PrometheusMetrics for Metrics {
}
}

// Sets metrics to 0 at the beginning to show proper charts in Prometheus
fn init_disputes(&self, para_id: u32) {
if let Some(metrics) = &self.0 {
let para_string = para_id.to_string();
metrics.disputes_stats.disputed_count.with_label_values(&[&para_string]).reset();
metrics
.disputes_stats
.concluded_valid
.with_label_values(&[&para_string])
.reset();
metrics
.disputes_stats
.concluded_invalid
.with_label_values(&[&para_string])
.reset();
}
}

Expand Down
15 changes: 10 additions & 5 deletions parachain-tracer/src/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub struct SubxtTracker {
/// Previous relay chain block.
previous_relay_block: Option<Block>,

/// A timestamp of a current relay chain block which is not a fork.
current_non_fork_relay_block_ts: Option<Timestamp>,
/// A timestamp of a last relay chain block which is not a fork.
last_non_fork_relay_block_ts: Option<Timestamp>,
/// The relay chain block number at which the last candidate was backed.
Expand Down Expand Up @@ -94,6 +96,7 @@ impl SubxtTracker {
finality_lag: None,
disputes: Vec::new(),
last_backed_at_block_number: None,
current_non_fork_relay_block_ts: None,
last_non_fork_relay_block_ts: None,
last_included_at: None,
previous_included_at: None,
Expand Down Expand Up @@ -145,10 +148,9 @@ impl SubxtTracker {
storage: &TrackerStorage,
) -> Option<ParachainProgressUpdate> {
if let Some(block) = self.current_relay_block {
let prev_timestamp = self.last_non_fork_relay_block_ts.unwrap_or(block.ts);
let mut progress = ParachainProgressUpdate {
timestamp: block.ts,
prev_timestamp,
prev_timestamp: self.last_non_fork_relay_block_ts.unwrap_or(block.ts),
block_number: block.num,
block_hash: block.hash,
para_id: self.para_id,
Expand Down Expand Up @@ -219,7 +221,8 @@ impl SubxtTracker {
self.current_relay_block = Some(Block { num: block_number, ts, hash: block_hash });

if !self.is_fork() {
self.last_non_fork_relay_block_ts = Some(ts);
self.last_non_fork_relay_block_ts = self.current_non_fork_relay_block_ts;
self.current_non_fork_relay_block_ts = Some(ts);
}

self.finality_lag = storage
Expand Down Expand Up @@ -765,7 +768,8 @@ mod test_inject_block {
let current = tracker.current_relay_block.unwrap();
assert!(tracker.previous_relay_block.is_none());
assert_eq!(current.hash, first_hash);
assert_eq!(tracker.last_non_fork_relay_block_ts, Some(1_u64));
assert_eq!(tracker.current_non_fork_relay_block_ts, Some(1_u64));
assert_eq!(tracker.last_non_fork_relay_block_ts, None);
assert!(tracker.finality_lag.is_none());

// Inject a fork and relevant finalized block number
Expand Down Expand Up @@ -795,7 +799,8 @@ mod test_inject_block {
let current = tracker.current_relay_block.unwrap();
assert_eq!(previous.hash, first_hash);
assert_eq!(current.hash, second_hash);
assert_eq!(tracker.last_non_fork_relay_block_ts, Some(1));
assert_eq!(tracker.current_non_fork_relay_block_ts, Some(1));
assert_eq!(tracker.last_non_fork_relay_block_ts, None);
assert_eq!(tracker.finality_lag, Some(2));
}

Expand Down

0 comments on commit 648182b

Please sign in to comment.