Skip to content

Commit

Permalink
distribution of leftover tickets fix
Browse files Browse the repository at this point in the history
  • Loading branch information
psorinionut committed Nov 12, 2024
1 parent 57493fd commit 9fc07c1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions launchpad-guaranteed-tickets-v2/src/guaranteed_ticket_winners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,18 @@ pub trait GuaranteedTicketWinnersModule:
}

let rand_pos = rng.next_usize_in_range(current_ticket_position, last_ticket_position + 1);
let winning_ticket_id = self.get_ticket_id_from_pos(rand_pos);
if self.is_already_winning_ticket(winning_ticket_id) {
let selected_ticket_id = self.get_ticket_id_from_pos(rand_pos);
if self.is_already_winning_ticket(selected_ticket_id) {
// Swap tickets positions so that the current position still has a chance in future selections
self.ticket_pos_to_id(current_ticket_position)
.set(selected_ticket_id);
self.ticket_pos_to_id(rand_pos).set(current_ticket_id);

return AdditionalSelectionTryResult::NewlySelectedAlreadyWinning;
}

self.ticket_pos_to_id(rand_pos).set(current_ticket_id);
self.ticket_status(winning_ticket_id).set(WINNING_TICKET);
self.ticket_status(selected_ticket_id).set(WINNING_TICKET);

AdditionalSelectionTryResult::Ok
}
Expand Down

0 comments on commit 9fc07c1

Please sign in to comment.