mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 00:31:02 +00:00
Changed how relay loops are started (#840)
* slightly changed relay loop initialization * git mv * clippy * more clippy * loop_run -> run_loop * review and clippy * clippy
This commit is contained in:
committed by
Bastian Köcher
parent
8d122b03f1
commit
a17c7eb80c
@@ -26,7 +26,7 @@ use backoff::backoff::Backoff;
|
||||
use futures::{future::FutureExt, select};
|
||||
use num_traits::One;
|
||||
use relay_utils::{
|
||||
metrics::{start as metrics_start, GlobalMetrics, MetricsParams},
|
||||
metrics::{GlobalMetrics, MetricsParams},
|
||||
retry_backoff, FailedClient, MaybeConnectionError,
|
||||
};
|
||||
use std::future::Future;
|
||||
@@ -85,42 +85,25 @@ pub async fn run<P: TransactionProofPipeline>(
|
||||
target_client: impl TargetClient<P>,
|
||||
metrics_params: Option<MetricsParams>,
|
||||
exit_signal: impl Future<Output = ()>,
|
||||
) {
|
||||
) -> Result<(), String> {
|
||||
let exit_signal = exit_signal.shared();
|
||||
let metrics_global = GlobalMetrics::default();
|
||||
let metrics_exch = ExchangeLoopMetrics::default();
|
||||
let metrics_enabled = metrics_params.is_some();
|
||||
metrics_start(
|
||||
format!("{}_to_{}_Exchange", P::SOURCE_NAME, P::TARGET_NAME),
|
||||
metrics_params,
|
||||
&metrics_global,
|
||||
&metrics_exch,
|
||||
);
|
||||
|
||||
relay_utils::relay_loop::run(
|
||||
relay_utils::relay_loop::RECONNECT_DELAY,
|
||||
source_client,
|
||||
target_client,
|
||||
|source_client, target_client| {
|
||||
relay_utils::relay_loop(source_client, target_client)
|
||||
.with_metrics(format!("{}_to_{}_Exchange", P::SOURCE_NAME, P::TARGET_NAME))
|
||||
.loop_metric(ExchangeLoopMetrics::default())?
|
||||
.standalone_metric(GlobalMetrics::default())?
|
||||
.expose(metrics_params)
|
||||
.await?
|
||||
.run(|source_client, target_client, metrics| {
|
||||
run_until_connection_lost(
|
||||
storage.clone(),
|
||||
source_client,
|
||||
target_client,
|
||||
if metrics_enabled {
|
||||
Some(metrics_global.clone())
|
||||
} else {
|
||||
None
|
||||
},
|
||||
if metrics_enabled {
|
||||
Some(metrics_exch.clone())
|
||||
} else {
|
||||
None
|
||||
},
|
||||
metrics,
|
||||
exit_signal.clone(),
|
||||
)
|
||||
},
|
||||
)
|
||||
.await;
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
/// Run proofs synchronization.
|
||||
@@ -128,7 +111,6 @@ async fn run_until_connection_lost<P: TransactionProofPipeline>(
|
||||
mut storage: impl TransactionProofsRelayStorage<BlockNumber = BlockNumberOf<P>>,
|
||||
source_client: impl SourceClient<P>,
|
||||
target_client: impl TargetClient<P>,
|
||||
metrics_global: Option<GlobalMetrics>,
|
||||
metrics_exch: Option<ExchangeLoopMetrics>,
|
||||
exit_signal: impl Future<Output = ()>,
|
||||
) -> Result<(), FailedClient> {
|
||||
@@ -151,10 +133,6 @@ async fn run_until_connection_lost<P: TransactionProofPipeline>(
|
||||
)
|
||||
.await;
|
||||
|
||||
if let Some(ref metrics_global) = metrics_global {
|
||||
metrics_global.update().await;
|
||||
}
|
||||
|
||||
if let Err((is_connection_error, failed_client)) = iteration_result {
|
||||
if is_connection_error {
|
||||
return Err(failed_client);
|
||||
@@ -321,7 +299,7 @@ mod tests {
|
||||
}
|
||||
}));
|
||||
|
||||
async_std::task::block_on(run(
|
||||
let _ = async_std::task::block_on(run(
|
||||
storage,
|
||||
source,
|
||||
target,
|
||||
|
||||
Reference in New Issue
Block a user