Skip to content

Commit

Permalink
Remove unused relays/headers (paritytech#1216)
Browse files Browse the repository at this point in the history
* Decouple `relays/client-substrate` from `headers_relay`
* Remove `blocks_in_state` from `SyncLoopMetrics`
    This metric was only relevant for PoA <> Substrate bridge.
* Move `sync_loop_metrics.rs` to `relays/finality`
* Remove unused `SyncLoopMetrics::update()`
* Hook up SyncLoopMetrics to finality_loop
* Delete now unused `relays/headers`

Signed-off-by: acatangiu <[email protected]>
  • Loading branch information
acatangiu authored and serban300 committed Apr 9, 2024
1 parent 2d023d8 commit 7ac859b
Show file tree
Hide file tree
Showing 15 changed files with 5 additions and 3,914 deletions.
1 change: 0 additions & 1 deletion bridges/relays/client-substrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ thiserror = "1.0.26"
bp-header-chain = { path = "../../primitives/header-chain" }
bp-runtime = { path = "../../primitives/runtime" }
finality-relay = { path = "../finality" }
headers-relay = { path = "../headers" }
relay-utils = { path = "../utils" }

# Substrate Dependencies
Expand Down
108 changes: 0 additions & 108 deletions bridges/relays/client-substrate/src/headers_source.rs

This file was deleted.

1 change: 0 additions & 1 deletion bridges/relays/client-substrate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ mod sync_header;

pub mod finality_source;
pub mod guard;
pub mod headers_source;
pub mod metrics;

use std::time::Duration;
Expand Down
20 changes: 1 addition & 19 deletions bridges/relays/client-substrate/src/sync_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@

use bp_header_chain::find_grandpa_authorities_scheduled_change;
use finality_relay::SourceHeader as FinalitySourceHeader;
use headers_relay::sync_types::SourceHeader;
use num_traits::{CheckedSub, One};
use relay_utils::HeaderId;
use sp_runtime::traits::Header as HeaderT;

/// Generic wrapper for `sp_runtime::traits::Header` based headers, that
/// implements `headers_relay::sync_types::SourceHeader` and may be used in headers sync directly.
/// implements `finality_relay::SourceHeader` and may be used in headers sync directly.
#[derive(Clone, Debug, PartialEq)]
pub struct SyncHeader<Header>(Header);

Expand All @@ -47,21 +44,6 @@ impl<Header> From<Header> for SyncHeader<Header> {
}
}

impl<Header: HeaderT> SourceHeader<Header::Hash, Header::Number> for SyncHeader<Header> {
fn id(&self) -> HeaderId<Header::Hash, Header::Number> {
relay_utils::HeaderId(*self.0.number(), self.hash())
}

fn parent_id(&self) -> HeaderId<Header::Hash, Header::Number> {
relay_utils::HeaderId(
self.number()
.checked_sub(&One::one())
.expect("should never be called for genesis header"),
*self.parent_hash(),
)
}
}

impl<Header: HeaderT> FinalitySourceHeader<Header::Number> for SyncHeader<Header> {
fn number(&self) -> Header::Number {
*self.0.number()
Expand Down
1 change: 0 additions & 1 deletion bridges/relays/finality/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ async-trait = "0.1.40"
backoff = "0.2"
bp-header-chain = { path = "../../primitives/header-chain" }
futures = "0.3.5"
headers-relay = { path = "../headers" }
log = "0.4.11"
num-traits = "0.2"
relay-utils = { path = "../utils" }
Expand Down
5 changes: 3 additions & 2 deletions bridges/relays/finality/src/finality_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
//! is the mandatory headers, which we always submit to the target node. For such headers, we
//! assume that the persistent proof either exists, or will eventually become available.

use crate::{FinalityProof, FinalitySyncPipeline, SourceHeader};
use crate::{
sync_loop_metrics::SyncLoopMetrics, FinalityProof, FinalitySyncPipeline, SourceHeader,
};

use async_trait::async_trait;
use backoff::backoff::Backoff;
use futures::{select, Future, FutureExt, Stream, StreamExt};
use headers_relay::sync_loop_metrics::SyncLoopMetrics;
use num_traits::{One, Saturating};
use relay_utils::{
metrics::{GlobalMetrics, MetricsParams},
Expand Down
1 change: 1 addition & 0 deletions bridges/relays/finality/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use std::fmt::Debug;

mod finality_loop;
mod finality_loop_tests;
mod sync_loop_metrics;

/// Finality proofs synchronization pipeline.
pub trait FinalitySyncPipeline: 'static + Clone + Debug + Send + Sync {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,13 @@

//! Metrics for headers synchronization relay loop.

use crate::{
sync::HeadersSync,
sync_types::{HeaderStatus, HeadersSyncPipeline},
};

use num_traits::Zero;
use relay_utils::metrics::{metric_name, register, GaugeVec, Opts, PrometheusError, 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 SyncLoopMetrics {
Expand All @@ -47,16 +39,6 @@ impl SyncLoopMetrics {
)?,
registry,
)?,
blocks_in_state: register(
GaugeVec::new(
Opts::new(
metric_name(prefix, "blocks_in_state"),
"Number of blocks in given state",
),
&["state"],
)?,
registry,
)?,
})
}
}
Expand All @@ -75,37 +57,4 @@ impl SyncLoopMetrics {
.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 _);
}
}
17 changes: 0 additions & 17 deletions bridges/relays/headers/Cargo.toml

This file was deleted.

Loading

0 comments on commit 7ac859b

Please sign in to comment.