Do not spawn additional task for on-demand relays (#933)

* do not spawn additional task for on-demand relays

* compilation
This commit is contained in:
Svyatoslav Nikolsky
2021-04-26 16:05:02 +03:00
committed by Bastian Köcher
parent 0e34a11309
commit 38cd3a328d
6 changed files with 46 additions and 12 deletions
@@ -102,6 +102,7 @@ impl RelayHeaders {
Finality::new(target_client.clone(), target_sign),
source_client,
target_client,
false,
metrics_params,
)
.await
@@ -112,6 +112,7 @@ pub async fn run<SourceChain, TargetChain, P>(
pipeline: P,
source_client: Client<SourceChain>,
target_client: Client<TargetChain>,
is_on_demand_task: bool,
metrics_params: MetricsParams,
) -> anyhow::Result<()>
where
@@ -137,6 +138,7 @@ where
FinalitySource::new(source_client),
SubstrateFinalityTarget::new(target_client, pipeline),
FinalitySyncParams {
is_on_demand_task,
tick: std::cmp::max(SourceChain::AVERAGE_BLOCK_INTERVAL, TargetChain::AVERAGE_BLOCK_INTERVAL),
recent_finality_proofs_limit: RECENT_FINALITY_PROOFS_LIMIT,
stall_timeout: STALL_TIMEOUT,
@@ -300,15 +300,20 @@ fn select_on_demand_relay_action<C: Chain>(
.checked_sub(&best_finalized_source_header_at_target)
.unwrap_or_else(Zero::zero);
if current_headers_difference > maximal_headers_difference {
log::trace!(
target: "bridge",
"Too many {} headers missing at target in {} relay. Going to sync up to the {}",
C::NAME,
relay_task_name,
best_finalized_source_header_at_source,
);
required_source_header_at_target = best_finalized_source_header_at_source;
// don't log if relay is already running
if !is_active {
log::trace!(
target: "bridge",
"Too many {} headers missing at target in {} relay ({} vs {}). Going to sync up to the {}",
C::NAME,
relay_task_name,
best_finalized_source_header_at_source,
best_finalized_source_header_at_target,
best_finalized_source_header_at_source,
);
}
}
// now let's select what to do with relay
@@ -345,7 +350,7 @@ where
TargetSign: 'static,
{
let headers_relay_future =
crate::finality_pipeline::run(pipeline, source_client, target_client, MetricsParams::disabled());
crate::finality_pipeline::run(pipeline, source_client, target_client, true, MetricsParams::disabled());
let closure_task_name = task_name.clone();
async_std::task::Builder::new()
.name(task_name.clone())