mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 18:01:03 +00:00
Shared reference to conversion rate metric value (#1034)
* shared conversion rate metric value * clippy
This commit is contained in:
committed by
Bastian Köcher
parent
db0216dabb
commit
ecd20d9d24
@@ -17,7 +17,8 @@
|
||||
//! Millau-to-Rialto messages sync entrypoint.
|
||||
|
||||
use crate::messages_lane::{
|
||||
select_delivery_transaction_limits, MessagesRelayParams, SubstrateMessageLane, SubstrateMessageLaneToSubstrate,
|
||||
select_delivery_transaction_limits, MessagesRelayParams, StandaloneMessagesMetrics, SubstrateMessageLane,
|
||||
SubstrateMessageLaneToSubstrate,
|
||||
};
|
||||
use crate::messages_source::SubstrateMessagesSource;
|
||||
use crate::messages_target::SubstrateMessagesTarget;
|
||||
@@ -30,10 +31,8 @@ use frame_support::dispatch::GetDispatchInfo;
|
||||
use messages_relay::message_lane::MessageLane;
|
||||
use relay_millau_client::{HeaderId as MillauHeaderId, Millau, SigningParams as MillauSigningParams};
|
||||
use relay_rialto_client::{HeaderId as RialtoHeaderId, Rialto, SigningParams as RialtoSigningParams};
|
||||
use relay_substrate_client::{
|
||||
metrics::{FloatStorageValueMetric, StorageProofOverheadMetric},
|
||||
Chain, TransactionSignScheme,
|
||||
};
|
||||
use relay_substrate_client::{Chain, Client, TransactionSignScheme};
|
||||
use relay_utils::metrics::MetricsParams;
|
||||
use sp_core::{Bytes, Pair};
|
||||
use std::{ops::RangeInclusive, time::Duration};
|
||||
|
||||
@@ -136,7 +135,7 @@ type RialtoTargetClient =
|
||||
/// Run Millau-to-Rialto messages sync.
|
||||
pub async fn run(
|
||||
params: MessagesRelayParams<Millau, MillauSigningParams, Rialto, RialtoSigningParams>,
|
||||
) -> Result<(), String> {
|
||||
) -> anyhow::Result<()> {
|
||||
let stall_timeout = Duration::from_secs(5 * 60);
|
||||
let relayer_id_at_millau = (*params.source_sign.public().as_array_ref()).into();
|
||||
|
||||
@@ -172,6 +171,7 @@ pub async fn run(
|
||||
max_messages_weight_in_single_batch,
|
||||
);
|
||||
|
||||
let (metrics_params, _) = add_standalone_metrics(params.metrics_params, source_client.clone())?;
|
||||
messages_relay::message_lane_loop::run(
|
||||
messages_relay::message_lane_loop::Params {
|
||||
lane: lane_id,
|
||||
@@ -202,36 +202,25 @@ pub async fn run(
|
||||
MILLAU_CHAIN_ID,
|
||||
params.source_to_target_headers_relay,
|
||||
),
|
||||
relay_utils::relay_metrics(
|
||||
Some(messages_relay::message_lane_loop::metrics_prefix::<
|
||||
MillauMessagesToRialto,
|
||||
>(&lane_id)),
|
||||
params.metrics_params,
|
||||
)
|
||||
.standalone_metric(|registry, prefix| {
|
||||
StorageProofOverheadMetric::new(
|
||||
registry,
|
||||
prefix,
|
||||
source_client.clone(),
|
||||
"millau_storage_proof_overhead".into(),
|
||||
"Millau storage proof overhead".into(),
|
||||
)
|
||||
})?
|
||||
.standalone_metric(|registry, prefix| {
|
||||
FloatStorageValueMetric::<_, sp_runtime::FixedU128>::new(
|
||||
registry,
|
||||
prefix,
|
||||
source_client,
|
||||
sp_core::storage::StorageKey(
|
||||
millau_runtime::rialto_messages::RialtoToMillauConversionRate::key().to_vec(),
|
||||
),
|
||||
Some(millau_runtime::rialto_messages::INITIAL_RIALTO_TO_MILLAU_CONVERSION_RATE),
|
||||
"millau_rialto_to_millau_conversion_rate".into(),
|
||||
"Rialto to Millau tokens conversion rate (used by Rialto)".into(),
|
||||
)
|
||||
})?
|
||||
.into_params(),
|
||||
metrics_params,
|
||||
futures::future::pending(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Add standalone metrics for the Millau -> Rialto messages loop.
|
||||
pub(crate) fn add_standalone_metrics(
|
||||
metrics_params: MetricsParams,
|
||||
source_client: Client<Millau>,
|
||||
) -> anyhow::Result<(MetricsParams, StandaloneMessagesMetrics)> {
|
||||
crate::messages_lane::add_standalone_metrics::<MillauMessagesToRialto>(
|
||||
metrics_params,
|
||||
source_client,
|
||||
None,
|
||||
None,
|
||||
Some((
|
||||
sp_core::storage::StorageKey(millau_runtime::rialto_messages::RialtoToMillauConversionRate::key().to_vec()),
|
||||
millau_runtime::rialto_messages::INITIAL_RIALTO_TO_MILLAU_CONVERSION_RATE,
|
||||
)),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -32,38 +32,38 @@ mod rococo;
|
||||
mod westend;
|
||||
mod wococo;
|
||||
|
||||
use relay_utils::metrics::{FloatJsonValueMetric, MetricsParams};
|
||||
use relay_utils::metrics::{FloatJsonValueMetric, MetricsParams, PrometheusError, Registry};
|
||||
|
||||
pub(crate) fn add_polkadot_kusama_price_metrics<T: finality_relay::FinalitySyncPipeline>(
|
||||
params: MetricsParams,
|
||||
) -> anyhow::Result<MetricsParams> {
|
||||
Ok(
|
||||
relay_utils::relay_metrics(Some(finality_relay::metrics_prefix::<T>()), params)
|
||||
// Polkadot/Kusama prices are added as metrics here, because atm we don't have Polkadot <-> Kusama
|
||||
// relays, but we want to test metrics/dashboards in advance
|
||||
.standalone_metric(|registry, prefix| {
|
||||
FloatJsonValueMetric::new(
|
||||
registry,
|
||||
prefix,
|
||||
"https://api.coingecko.com/api/v3/simple/price?ids=Polkadot&vs_currencies=btc".into(),
|
||||
"$.polkadot.btc".into(),
|
||||
"polkadot_to_base_conversion_rate".into(),
|
||||
"Rate used to convert from DOT to some BASE tokens".into(),
|
||||
)
|
||||
})
|
||||
.map_err(|e| anyhow::format_err!("{}", e))?
|
||||
.standalone_metric(|registry, prefix| {
|
||||
FloatJsonValueMetric::new(
|
||||
registry,
|
||||
prefix,
|
||||
"https://api.coingecko.com/api/v3/simple/price?ids=Kusama&vs_currencies=btc".into(),
|
||||
"$.kusama.btc".into(),
|
||||
"kusama_to_base_conversion_rate".into(),
|
||||
"Rate used to convert from KSM to some BASE tokens".into(),
|
||||
)
|
||||
})
|
||||
.map_err(|e| anyhow::format_err!("{}", e))?
|
||||
.into_params(),
|
||||
// Polkadot/Kusama prices are added as metrics here, because atm we don't have Polkadot <-> Kusama
|
||||
// relays, but we want to test metrics/dashboards in advance
|
||||
Ok(relay_utils::relay_metrics(None, params)
|
||||
.standalone_metric(|registry, prefix| token_price_metric(registry, prefix, "polkadot"))?
|
||||
.standalone_metric(|registry, prefix| token_price_metric(registry, prefix, "kusama"))?
|
||||
.into_params())
|
||||
}
|
||||
|
||||
/// Creates standalone token price metric.
|
||||
pub(crate) fn token_price_metric(
|
||||
registry: &Registry,
|
||||
prefix: Option<&str>,
|
||||
token_id: &str,
|
||||
) -> Result<FloatJsonValueMetric, PrometheusError> {
|
||||
FloatJsonValueMetric::new(
|
||||
registry,
|
||||
prefix,
|
||||
format!(
|
||||
"https://api.coingecko.com/api/v3/simple/price?ids={}&vs_currencies=btc",
|
||||
token_id
|
||||
),
|
||||
format!("$.{}.btc", token_id),
|
||||
format!("{}_to_base_conversion_rate", token_id.replace("-", "_")),
|
||||
format!(
|
||||
"Rate used to convert from {} to some BASE tokens",
|
||||
token_id.to_uppercase()
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
//! Rialto-to-Millau messages sync entrypoint.
|
||||
|
||||
use crate::messages_lane::{
|
||||
select_delivery_transaction_limits, MessagesRelayParams, SubstrateMessageLane, SubstrateMessageLaneToSubstrate,
|
||||
select_delivery_transaction_limits, MessagesRelayParams, StandaloneMessagesMetrics, SubstrateMessageLane,
|
||||
SubstrateMessageLaneToSubstrate,
|
||||
};
|
||||
use crate::messages_source::SubstrateMessagesSource;
|
||||
use crate::messages_target::SubstrateMessagesTarget;
|
||||
@@ -30,10 +31,8 @@ use frame_support::dispatch::GetDispatchInfo;
|
||||
use messages_relay::message_lane::MessageLane;
|
||||
use relay_millau_client::{HeaderId as MillauHeaderId, Millau, SigningParams as MillauSigningParams};
|
||||
use relay_rialto_client::{HeaderId as RialtoHeaderId, Rialto, SigningParams as RialtoSigningParams};
|
||||
use relay_substrate_client::{
|
||||
metrics::{FloatStorageValueMetric, StorageProofOverheadMetric},
|
||||
Chain, TransactionSignScheme,
|
||||
};
|
||||
use relay_substrate_client::{Chain, Client, TransactionSignScheme};
|
||||
use relay_utils::metrics::MetricsParams;
|
||||
use sp_core::{Bytes, Pair};
|
||||
use std::{ops::RangeInclusive, time::Duration};
|
||||
|
||||
@@ -136,7 +135,7 @@ type MillauTargetClient =
|
||||
/// Run Rialto-to-Millau messages sync.
|
||||
pub async fn run(
|
||||
params: MessagesRelayParams<Rialto, RialtoSigningParams, Millau, MillauSigningParams>,
|
||||
) -> Result<(), String> {
|
||||
) -> anyhow::Result<()> {
|
||||
let stall_timeout = Duration::from_secs(5 * 60);
|
||||
let relayer_id_at_rialto = (*params.source_sign.public().as_array_ref()).into();
|
||||
|
||||
@@ -171,6 +170,7 @@ pub async fn run(
|
||||
max_messages_weight_in_single_batch,
|
||||
);
|
||||
|
||||
let (metrics_params, _) = add_standalone_metrics(params.metrics_params, source_client.clone())?;
|
||||
messages_relay::message_lane_loop::run(
|
||||
messages_relay::message_lane_loop::Params {
|
||||
lane: lane_id,
|
||||
@@ -201,36 +201,25 @@ pub async fn run(
|
||||
RIALTO_CHAIN_ID,
|
||||
params.source_to_target_headers_relay,
|
||||
),
|
||||
relay_utils::relay_metrics(
|
||||
Some(messages_relay::message_lane_loop::metrics_prefix::<
|
||||
RialtoMessagesToMillau,
|
||||
>(&lane_id)),
|
||||
params.metrics_params,
|
||||
)
|
||||
.standalone_metric(|registry, prefix| {
|
||||
StorageProofOverheadMetric::new(
|
||||
registry,
|
||||
prefix,
|
||||
source_client.clone(),
|
||||
"rialto_storage_proof_overhead".into(),
|
||||
"Rialto storage proof overhead".into(),
|
||||
)
|
||||
})?
|
||||
.standalone_metric(|registry, prefix| {
|
||||
FloatStorageValueMetric::<_, sp_runtime::FixedU128>::new(
|
||||
registry,
|
||||
prefix,
|
||||
source_client,
|
||||
sp_core::storage::StorageKey(
|
||||
rialto_runtime::millau_messages::MillauToRialtoConversionRate::key().to_vec(),
|
||||
),
|
||||
Some(rialto_runtime::millau_messages::INITIAL_MILLAU_TO_RIALTO_CONVERSION_RATE),
|
||||
"rialto_millau_to_rialto_conversion_rate".into(),
|
||||
"Millau to Rialto tokens conversion rate (used by Millau)".into(),
|
||||
)
|
||||
})?
|
||||
.into_params(),
|
||||
metrics_params,
|
||||
futures::future::pending(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Add standalone metrics for the Rialto -> Millau messages loop.
|
||||
pub(crate) fn add_standalone_metrics(
|
||||
metrics_params: MetricsParams,
|
||||
source_client: Client<Rialto>,
|
||||
) -> anyhow::Result<(MetricsParams, StandaloneMessagesMetrics)> {
|
||||
crate::messages_lane::add_standalone_metrics::<RialtoMessagesToMillau>(
|
||||
metrics_params,
|
||||
source_client,
|
||||
None,
|
||||
None,
|
||||
Some((
|
||||
sp_core::storage::StorageKey(rialto_runtime::millau_messages::MillauToRialtoConversionRate::key().to_vec()),
|
||||
rialto_runtime::millau_messages::INITIAL_MILLAU_TO_RIALTO_CONVERSION_RATE,
|
||||
)),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
//! Rococo-to-Wococo messages sync entrypoint.
|
||||
|
||||
use crate::messages_lane::{
|
||||
select_delivery_transaction_limits, MessagesRelayParams, SubstrateMessageLane, SubstrateMessageLaneToSubstrate,
|
||||
select_delivery_transaction_limits, MessagesRelayParams, StandaloneMessagesMetrics, SubstrateMessageLane,
|
||||
SubstrateMessageLaneToSubstrate,
|
||||
};
|
||||
use crate::messages_source::SubstrateMessagesSource;
|
||||
use crate::messages_target::SubstrateMessagesTarget;
|
||||
@@ -28,7 +29,8 @@ use bridge_runtime_common::messages::target::FromBridgedChainMessagesProof;
|
||||
use codec::Encode;
|
||||
use messages_relay::message_lane::MessageLane;
|
||||
use relay_rococo_client::{HeaderId as RococoHeaderId, Rococo, SigningParams as RococoSigningParams};
|
||||
use relay_substrate_client::{metrics::StorageProofOverheadMetric, Chain, TransactionSignScheme};
|
||||
use relay_substrate_client::{Chain, Client, TransactionSignScheme};
|
||||
use relay_utils::metrics::MetricsParams;
|
||||
use relay_wococo_client::{HeaderId as WococoHeaderId, SigningParams as WococoSigningParams, Wococo};
|
||||
use sp_core::{Bytes, Pair};
|
||||
use std::{ops::RangeInclusive, time::Duration};
|
||||
@@ -142,7 +144,7 @@ type WococoTargetClient = SubstrateMessagesTarget<
|
||||
/// Run Rococo-to-Wococo messages sync.
|
||||
pub async fn run(
|
||||
params: MessagesRelayParams<Rococo, RococoSigningParams, Wococo, WococoSigningParams>,
|
||||
) -> Result<(), String> {
|
||||
) -> anyhow::Result<()> {
|
||||
let stall_timeout = Duration::from_secs(5 * 60);
|
||||
let relayer_id_at_rococo = (*params.source_sign.public().as_array_ref()).into();
|
||||
|
||||
@@ -183,6 +185,7 @@ pub async fn run(
|
||||
max_messages_weight_in_single_batch,
|
||||
);
|
||||
|
||||
let (metrics_params, _) = add_standalone_metrics(params.metrics_params, source_client.clone())?;
|
||||
messages_relay::message_lane_loop::run(
|
||||
messages_relay::message_lane_loop::Params {
|
||||
lane: lane_id,
|
||||
@@ -213,23 +216,22 @@ pub async fn run(
|
||||
ROCOCO_CHAIN_ID,
|
||||
params.source_to_target_headers_relay,
|
||||
),
|
||||
relay_utils::relay_metrics(
|
||||
Some(messages_relay::message_lane_loop::metrics_prefix::<
|
||||
RococoMessagesToWococo,
|
||||
>(&lane_id)),
|
||||
params.metrics_params,
|
||||
)
|
||||
.standalone_metric(|registry, prefix| {
|
||||
StorageProofOverheadMetric::new(
|
||||
registry,
|
||||
prefix,
|
||||
source_client.clone(),
|
||||
"rococo_storage_proof_overhead".into(),
|
||||
"Rococo storage proof overhead".into(),
|
||||
)
|
||||
})?
|
||||
.into_params(),
|
||||
metrics_params,
|
||||
futures::future::pending(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Add standalone metrics for the Rococo -> Wococo messages loop.
|
||||
pub(crate) fn add_standalone_metrics(
|
||||
metrics_params: MetricsParams,
|
||||
source_client: Client<Rococo>,
|
||||
) -> anyhow::Result<(MetricsParams, StandaloneMessagesMetrics)> {
|
||||
crate::messages_lane::add_standalone_metrics::<RococoMessagesToWococo>(
|
||||
metrics_params,
|
||||
source_client,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
//! Wococo-to-Rococo messages sync entrypoint.
|
||||
|
||||
use crate::messages_lane::{
|
||||
select_delivery_transaction_limits, MessagesRelayParams, SubstrateMessageLane, SubstrateMessageLaneToSubstrate,
|
||||
select_delivery_transaction_limits, MessagesRelayParams, StandaloneMessagesMetrics, SubstrateMessageLane,
|
||||
SubstrateMessageLaneToSubstrate,
|
||||
};
|
||||
use crate::messages_source::SubstrateMessagesSource;
|
||||
use crate::messages_target::SubstrateMessagesTarget;
|
||||
@@ -28,7 +29,8 @@ use bridge_runtime_common::messages::target::FromBridgedChainMessagesProof;
|
||||
use codec::Encode;
|
||||
use messages_relay::message_lane::MessageLane;
|
||||
use relay_rococo_client::{HeaderId as RococoHeaderId, Rococo, SigningParams as RococoSigningParams};
|
||||
use relay_substrate_client::{metrics::StorageProofOverheadMetric, Chain, TransactionSignScheme};
|
||||
use relay_substrate_client::{Chain, Client, TransactionSignScheme};
|
||||
use relay_utils::metrics::MetricsParams;
|
||||
use relay_wococo_client::{HeaderId as WococoHeaderId, SigningParams as WococoSigningParams, Wococo};
|
||||
use sp_core::{Bytes, Pair};
|
||||
use std::{ops::RangeInclusive, time::Duration};
|
||||
@@ -142,7 +144,7 @@ type RococoTargetClient = SubstrateMessagesTarget<
|
||||
/// Run Wococo-to-Rococo messages sync.
|
||||
pub async fn run(
|
||||
params: MessagesRelayParams<Wococo, WococoSigningParams, Rococo, RococoSigningParams>,
|
||||
) -> Result<(), String> {
|
||||
) -> anyhow::Result<()> {
|
||||
let stall_timeout = Duration::from_secs(5 * 60);
|
||||
let relayer_id_at_wococo = (*params.source_sign.public().as_array_ref()).into();
|
||||
|
||||
@@ -183,6 +185,7 @@ pub async fn run(
|
||||
max_messages_weight_in_single_batch,
|
||||
);
|
||||
|
||||
let (metrics_params, _) = add_standalone_metrics(params.metrics_params, source_client.clone())?;
|
||||
messages_relay::message_lane_loop::run(
|
||||
messages_relay::message_lane_loop::Params {
|
||||
lane: lane_id,
|
||||
@@ -213,23 +216,22 @@ pub async fn run(
|
||||
WOCOCO_CHAIN_ID,
|
||||
params.source_to_target_headers_relay,
|
||||
),
|
||||
relay_utils::relay_metrics(
|
||||
Some(messages_relay::message_lane_loop::metrics_prefix::<
|
||||
WococoMessagesToRococo,
|
||||
>(&lane_id)),
|
||||
params.metrics_params,
|
||||
)
|
||||
.standalone_metric(|registry, prefix| {
|
||||
StorageProofOverheadMetric::new(
|
||||
registry,
|
||||
prefix,
|
||||
source_client.clone(),
|
||||
"wococo_storage_proof_overhead".into(),
|
||||
"Wococo storage proof overhead".into(),
|
||||
)
|
||||
})?
|
||||
.into_params(),
|
||||
metrics_params,
|
||||
futures::future::pending(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Add standalone metrics for the Wococo -> Rococo messages loop.
|
||||
pub(crate) fn add_standalone_metrics(
|
||||
metrics_params: MetricsParams,
|
||||
source_client: Client<Wococo>,
|
||||
) -> anyhow::Result<(MetricsParams, StandaloneMessagesMetrics)> {
|
||||
crate::messages_lane::add_standalone_metrics::<WococoMessagesToRococo>(
|
||||
metrics_params,
|
||||
source_client,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user