Skip to content

Commit

Permalink
Bound the jitter
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles committed Dec 18, 2024
1 parent 1b1f848 commit 12cda7c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion backend/canisters/community/impl/src/updates/claim_prize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ fn prepare(args: &Args, state: &mut RuntimeState) -> Result<PrepareResult, Box<R
};

// Hack to ensure 2 prizes claimed by the same user in the same block don't result in "duplicate transaction" errors.
let transaction_time = now_nanos - u32::from(result.message_index) as u64;
let jitter = u32::from(result.message_index) as u64 % 1000;
let transaction_time = now_nanos - jitter;

let transaction = create_pending_transaction(
result.token,
Expand Down
3 changes: 2 additions & 1 deletion backend/canisters/group/impl/src/updates/claim_prize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ fn prepare(args: &Args, state: &mut RuntimeState) -> Result<PrepareResult, Box<R
};

// Hack to ensure 2 prizes claimed by the same user in the same block don't result in "duplicate transaction" errors.
let transaction_time = now_nanos - u32::from(result.message_index) as u64;
let jitter = u32::from(result.message_index) as u64 % 1000;
let transaction_time = now_nanos - jitter;

let transaction = create_pending_transaction(
result.token,
Expand Down

0 comments on commit 12cda7c

Please sign in to comment.