Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fewensa authored Mar 21, 2022
1 parent 57f5260 commit c04e565
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions relays/messages/src/message_race_delivery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub async fn run<P: MessageLane, Strategy: RelayStrategy>(
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(),
},
Expand Down Expand Up @@ -251,6 +252,8 @@ struct MessageDeliveryStrategy<P: MessageLane, Strategy: RelayStrategy, SC, TC>
/// Latest confirmed nonces at the source client + the header id where we have first met this
/// nonce.
latest_confirmed_nonces_at_source: VecDeque<(SourceHeaderIdOf<P>, MessageNonce)>,
/// latest updated confirm nonce at source chain
latest_updated_confirm_nonce_at_source: Option<MessageNonce>,
/// Target nonces from the source client.
target_nonces: Option<TargetClientNonces<DeliveryRaceTargetNoncesData>>,
/// Basic delivery strategy.
Expand Down Expand Up @@ -280,6 +283,10 @@ impl<P: MessageLane, Strategy: RelayStrategy, SC, TC> 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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c04e565

Please sign in to comment.