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

Do not select any nonces in delivery race if something is already selected/submitted #2065

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
38 changes: 36 additions & 2 deletions relays/messages/src/message_race_delivery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,16 @@ where
&self,
race_state: RS,
) -> Option<(RangeInclusive<MessageNonce>, MessageProofParameters)> {
// if we have already selected nonces that we want to submit, do nothing
if race_state.nonces_to_submit().is_some() {
return None
}

// if we already submitted some nonces, do nothing
if race_state.nonces_submitted().is_some() {
return None
}

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()?;
Expand Down Expand Up @@ -1301,8 +1311,6 @@ mod tests {
},
));

// TODO: also fix + test `required_source_header_at_target`

// when lane is NOT blocked
let (mut state, mut strategy) = prepare_strategy();
at_target_block_2_deliver_messages(
Expand Down Expand Up @@ -1369,5 +1377,31 @@ mod tests {
at_target_block_3_select_nonces_to_deliver(&strategy, state).await,
expected_rewards_proof
);

// when we have already selected some nonces to deliver, we don't need to select anything
let (mut state, mut strategy) = prepare_strategy();
at_target_block_2_deliver_messages(
&mut strategy,
&mut state,
max_unrewarded_relayer_entries_at_target - 1,
max_unconfirmed_nonces_at_target,
);
at_source_block_2_deliver_confirmations(&mut strategy, &mut state);
state.nonces_to_submit = Some((header_id(2), 1..=0, (1..=0, None)));
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);

// when we have already submitted some nonces, we don't need to select anything
let (mut state, mut strategy) = prepare_strategy();
at_target_block_2_deliver_messages(
&mut strategy,
&mut state,
max_unrewarded_relayer_entries_at_target - 1,
max_unconfirmed_nonces_at_target,
);
at_source_block_2_deliver_confirmations(&mut strategy, &mut state);
state.nonces_submitted = Some(1..=0);
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);
}
}