From c04e56598b2abc4c782765849093a517d122db71 Mon Sep 17 00:00:00 2001 From: fewensa <37804932+fewensa@users.noreply.github.com> Date: Mon, 21 Mar 2022 12:12:04 +0800 Subject: [PATCH] Pick from https://github.com/paritytech/parity-bridges-common/pull/1328 (#13) --- relays/messages/src/message_race_delivery.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/relays/messages/src/message_race_delivery.rs b/relays/messages/src/message_race_delivery.rs index dc994364f..308870944 100644 --- a/relays/messages/src/message_race_delivery.rs +++ b/relays/messages/src/message_race_delivery.rs @@ -72,6 +72,7 @@ pub async fn run( max_messages_size_in_single_batch: params.max_messages_size_in_single_batch, relay_strategy: params.relay_strategy, latest_confirmed_nonces_at_source: VecDeque::new(), + latest_updated_confirm_nonce_at_source: None, target_nonces: None, strategy: BasicStrategy::new(), }, @@ -251,6 +252,8 @@ struct MessageDeliveryStrategy /// Latest confirmed nonces at the source client + the header id where we have first met this /// nonce. latest_confirmed_nonces_at_source: VecDeque<(SourceHeaderIdOf

, MessageNonce)>, + /// latest updated confirm nonce at source chain + latest_updated_confirm_nonce_at_source: Option, /// Target nonces from the source client. target_nonces: Option>, /// Basic delivery strategy. @@ -280,6 +283,10 @@ impl std::fmt::Debug .field("max_messages_weight_in_single_batch", &self.max_messages_weight_in_single_batch) .field("max_messages_size_in_single_batch", &self.max_messages_size_in_single_batch) .field("latest_confirmed_nonces_at_source", &self.latest_confirmed_nonces_at_source) + .field( + "latest_updated_confirm_nonce_at_source", + &self.latest_updated_confirm_nonce_at_source, + ) .field("target_nonces", &self.target_nonces) .field("strategy", &self.strategy) .finish() @@ -346,13 +353,13 @@ where ) { if let Some(confirmed_nonce) = nonces.confirmed_nonce { let is_confirmed_nonce_updated = self - .latest_confirmed_nonces_at_source - .back() - .map(|(_, prev_nonce)| *prev_nonce != confirmed_nonce) + .latest_updated_confirm_nonce_at_source + .map(|nonce| nonce != confirmed_nonce) .unwrap_or(true); if is_confirmed_nonce_updated { self.latest_confirmed_nonces_at_source .push_back((at_block.clone(), confirmed_nonce)); + self.latest_updated_confirm_nonce_at_source = Some(confirmed_nonce); } } self.strategy.source_nonces_updated(at_block, nonces) @@ -392,6 +399,13 @@ where { self.latest_confirmed_nonces_at_source.pop_front(); } + let latest = self.latest_confirmed_nonces_at_source.back(); + log::debug!( + target: "bridge", + "Pop front latest_confirmed_nonces_at_source. the oldest_header_number_to_keep is {:?}. after pop the latest value is {:?}", + oldest_header_number_to_keep, + latest + ); } if let Some(ref mut target_nonces) = self.target_nonces {