mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-25 12:55:48 +00:00
f87053c1cb
* finality proofs relay * SyncHeader::is_mandatory * empty ancestry proof * logs * fixed submit condition * fixed wrong split index * tick comment * recent_finality_proofs * basic finality loop tests * removed obsolete files * rename files in substrate relay * fmt * clippy * fixed TODOs * clippy * stop syncing if target node is out of sync * more clippy * more clippy * Update relays/finality-relay/src/finality_loop.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * Update relays/finality-relay/src/finality_loop.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * Update relays/finality-relay/src/finality_loop.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * docs * moved doc * typo * Update relays/finality-relay/src/finality_loop_tests.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * Update relays/finality-relay/src/finality_loop_tests.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * header_and_finality_proof_by_number -> header_and_finality_proof * VecDeque isn't required (because of make_contiguous) * fixed wrong expect * Update relays/finality-relay/src/finality_loop.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * Update relays/substrate/src/rialto_headers_to_millau.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * Update relays/substrate/src/rialto_headers_to_millau.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * RialtoSyncHeader * Update relays/finality-relay/src/finality_loop.rs Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * Update relays/finality-relay/src/finality_loop.rs Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * removed wrong comment * Update relays/finality-relay/src/finality_loop.rs Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * fix used runtime methods names * fix for new jsonrpsee * fix comment * initialize finality verifier pallet * fmt Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
106 lines
3.7 KiB
Rust
106 lines
3.7 KiB
Rust
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
|
|
// This file is part of Parity Bridges Common.
|
|
|
|
// Parity Bridges Common is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Parity Bridges Common is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//! Metrics for headers synchronization relay loop.
|
|
|
|
use crate::sync::HeadersSync;
|
|
use crate::sync_types::{HeaderStatus, HeadersSyncPipeline};
|
|
|
|
use num_traits::Zero;
|
|
use relay_utils::metrics::{register, GaugeVec, Metrics, Opts, Registry, U64};
|
|
|
|
/// Headers sync metrics.
|
|
#[derive(Clone)]
|
|
pub struct SyncLoopMetrics {
|
|
/// Best syncing headers at "source" and "target" nodes.
|
|
best_block_numbers: GaugeVec<U64>,
|
|
/// Number of headers in given states (see `HeaderStatus`).
|
|
blocks_in_state: GaugeVec<U64>,
|
|
}
|
|
|
|
impl Metrics for SyncLoopMetrics {
|
|
fn register(&self, registry: &Registry) -> Result<(), String> {
|
|
register(self.best_block_numbers.clone(), registry).map_err(|e| e.to_string())?;
|
|
register(self.blocks_in_state.clone(), registry).map_err(|e| e.to_string())?;
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
impl Default for SyncLoopMetrics {
|
|
fn default() -> Self {
|
|
SyncLoopMetrics {
|
|
best_block_numbers: GaugeVec::new(
|
|
Opts::new("best_block_numbers", "Best block numbers on source and target nodes"),
|
|
&["node"],
|
|
)
|
|
.expect("metric is static and thus valid; qed"),
|
|
blocks_in_state: GaugeVec::new(
|
|
Opts::new("blocks_in_state", "Number of blocks in given state"),
|
|
&["state"],
|
|
)
|
|
.expect("metric is static and thus valid; qed"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl SyncLoopMetrics {
|
|
/// Update best block number at source.
|
|
pub fn update_best_block_at_source<Number: Into<u64>>(&self, source_best_number: Number) {
|
|
self.best_block_numbers
|
|
.with_label_values(&["source"])
|
|
.set(source_best_number.into());
|
|
}
|
|
|
|
/// Update best block number at target.
|
|
pub fn update_best_block_at_target<Number: Into<u64>>(&self, target_best_number: Number) {
|
|
self.best_block_numbers
|
|
.with_label_values(&["target"])
|
|
.set(target_best_number.into());
|
|
}
|
|
|
|
/// Update metrics.
|
|
pub fn update<P: HeadersSyncPipeline>(&self, sync: &HeadersSync<P>) {
|
|
let headers = sync.headers();
|
|
let source_best_number = sync.source_best_number().unwrap_or_else(Zero::zero);
|
|
let target_best_number = sync.target_best_header().map(|id| id.0).unwrap_or_else(Zero::zero);
|
|
|
|
self.update_best_block_at_source(source_best_number);
|
|
self.update_best_block_at_target(target_best_number);
|
|
|
|
self.blocks_in_state
|
|
.with_label_values(&["maybe_orphan"])
|
|
.set(headers.headers_in_status(HeaderStatus::MaybeOrphan) as _);
|
|
self.blocks_in_state
|
|
.with_label_values(&["orphan"])
|
|
.set(headers.headers_in_status(HeaderStatus::Orphan) as _);
|
|
self.blocks_in_state
|
|
.with_label_values(&["maybe_extra"])
|
|
.set(headers.headers_in_status(HeaderStatus::MaybeExtra) as _);
|
|
self.blocks_in_state
|
|
.with_label_values(&["extra"])
|
|
.set(headers.headers_in_status(HeaderStatus::Extra) as _);
|
|
self.blocks_in_state
|
|
.with_label_values(&["ready"])
|
|
.set(headers.headers_in_status(HeaderStatus::Ready) as _);
|
|
self.blocks_in_state
|
|
.with_label_values(&["incomplete"])
|
|
.set(headers.headers_in_status(HeaderStatus::Incomplete) as _);
|
|
self.blocks_in_state
|
|
.with_label_values(&["submitted"])
|
|
.set(headers.headers_in_status(HeaderStatus::Submitted) as _);
|
|
}
|
|
}
|