Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the way latest_confirmed_nonce_at_source is "calculated" #2067

Merged
merged 1 commit into from
Apr 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions relays/messages/src/message_race_delivery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,10 @@ where
let best_target_nonce = self.strategy.best_at_target()?;
let best_finalized_source_header_id_at_best_target =
race_state.best_finalized_source_header_id_at_best_target()?;
let target_nonces = self.target_nonces.as_ref()?;
let latest_confirmed_nonce_at_source = self
.latest_confirmed_nonce_at_source(&best_finalized_source_header_id_at_best_target)
.unwrap_or(best_target_nonce);
let target_nonces = self.target_nonces.as_ref()?;
.unwrap_or(target_nonces.nonces_data.confirmed_nonce);

// There's additional condition in the message delivery race: target would reject messages
// if there are too much unconfirmed messages at the inbound lane.
Expand Down Expand Up @@ -1404,4 +1404,37 @@ mod tests {
assert_eq!(strategy.required_source_header_at_target(state.clone()).await, None);
assert_eq!(at_target_block_3_select_nonces_to_deliver(&strategy, state).await, None);
}

#[async_std::test]
async fn outbound_state_proof_is_not_required_when_we_have_no_new_confirmations() {
let (mut state, mut strategy) = prepare_strategy();

// pretend that we haven't seen any confirmations yet (or they're at the future target chain
// blocks)
strategy.latest_confirmed_nonces_at_source.clear();

// emulate delivery of some nonces (20..=23 are generated, but we only deliver 20..=21)
let nonces_at_target = TargetClientNonces {
latest_nonce: 21,
nonces_data: DeliveryRaceTargetNoncesData {
confirmed_nonce: 19,
unrewarded_relayers: UnrewardedRelayersState {
unrewarded_relayer_entries: 1,
total_messages: 2,
..Default::default()
},
},
};
state.best_target_header_id = Some(header_id(2));
state.best_finalized_target_header_id = Some(header_id(2));
strategy.best_target_nonces_updated(nonces_at_target.clone(), &mut state);
strategy.finalized_target_nonces_updated(nonces_at_target, &mut state);

// we won't include outbound lane state proof into 22..=23 delivery transaction
// because it brings no new reward confirmations
assert_eq!(
strategy.select_nonces_to_deliver(state).await,
Some(((22..=23), proof_parameters(false, 2)))
);
}
}