diff --git a/bridges/relays/messages-relay/src/message_race_delivery.rs b/bridges/relays/messages-relay/src/message_race_delivery.rs index a5d096b7710b..90345f8c6157 100644 --- a/bridges/relays/messages-relay/src/message_race_delivery.rs +++ b/bridges/relays/messages-relay/src/message_race_delivery.rs @@ -212,6 +212,14 @@ impl RaceStrategy, TargetHeaderIdOf

, P::M self.strategy.is_empty() } + fn best_at_source(&self) -> P::MessageNonce { + self.strategy.best_at_source() + } + + fn best_at_target(&self) -> P::MessageNonce { + self.strategy.best_at_target() + } + fn source_nonces_updated(&mut self, at_block: SourceHeaderIdOf

, nonces: ClientNonces) { self.source_nonces = Some(nonces.clone()); self.strategy.source_nonces_updated(at_block, nonces) diff --git a/bridges/relays/messages-relay/src/message_race_loop.rs b/bridges/relays/messages-relay/src/message_race_loop.rs index c3239f711537..43a2cd9ad275 100644 --- a/bridges/relays/messages-relay/src/message_race_loop.rs +++ b/bridges/relays/messages-relay/src/message_race_loop.rs @@ -117,6 +117,11 @@ pub trait RaceStrategy { /// Should return true if nothing has to be synced. fn is_empty(&self) -> bool; + /// Return best nonce at source node. + fn best_at_source(&self) -> MessageNonce; + /// Return best nonce at target node. + fn best_at_target(&self) -> MessageNonce; + /// Called when nonces are updated at source node of the race. fn source_nonces_updated(&mut self, at_block: SourceHeaderId, nonce: ClientNonces); /// Called when nonces are updated at target node of the race. @@ -135,6 +140,7 @@ pub trait RaceStrategy { } /// State of the race. +#[derive(Debug)] pub struct RaceState { /// Source state, if known. pub source_state: Option>, @@ -161,6 +167,7 @@ pub async fn run>( ProofParameters = SC::ProofParameters, >, ) -> Result<(), FailedClient> { + let mut progress_context = Instant::now(); let mut race_state = RaceState::default(); let mut stall_countdown = Instant::now(); @@ -295,6 +302,8 @@ pub async fn run>( } } + progress_context = print_race_progress::(progress_context, &strategy); + if stall_countdown.elapsed() > stall_timeout { return Err(FailedClient::Both); } else if race_state.nonces_to_submit.is_none() && race_state.nonces_submitted.is_none() && strategy.is_empty() @@ -379,6 +388,32 @@ impl Default } } +/// Print race progress. +fn print_race_progress(prev_time: Instant, strategy: &S) -> Instant +where + P: MessageRace, + S: RaceStrategy, +{ + let now_time = Instant::now(); + + let need_update = now_time.saturating_duration_since(prev_time) > Duration::from_secs(10); + if !need_update { + return prev_time; + } + + let now_best_nonce_at_source = strategy.best_at_source(); + let now_best_nonce_at_target = strategy.best_at_target(); + log::info!( + target: "bridge", + "Synced {:?} of {:?} nonces in {} -> {} race", + now_best_nonce_at_target, + now_best_nonce_at_source, + P::source_name(), + P::target_name(), + ); + now_time +} + fn select_nonces_to_deliver( race_state: &RaceState, strategy: &mut Strategy, diff --git a/bridges/relays/messages-relay/src/message_race_strategy.rs b/bridges/relays/messages-relay/src/message_race_strategy.rs index a22331fe07d1..4aabf6c200af 100644 --- a/bridges/relays/messages-relay/src/message_race_strategy.rs +++ b/bridges/relays/messages-relay/src/message_race_strategy.rs @@ -68,6 +68,17 @@ where self.source_queue.is_empty() } + fn best_at_source(&self) -> Nonce { + self.source_queue + .back() + .map(|(_, nonce)| *nonce) + .unwrap_or_else(Zero::zero) + } + + fn best_at_target(&self) -> Nonce { + self.target_nonce + } + fn source_nonces_updated( &mut self, at_block: HeaderId,