Skip to content

Commit 489e238

Browse files
authored
fix: Return current timestamp when nonce lags (#108)
The function `next_nonce()` always returns a unique nonce, by storing the current timestamp in a static variable and incrementing it before returning. However, this variable can lag during times of inactivity. Though there is a check that handles it by updating it with the current timestamp, it ends with returning the old nonce, which fails the current call. This fix makes sure that the current timestamp is returned when this check gets triggered.
1 parent ae36ca5 commit 489e238

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/helpers.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ pub(crate) fn next_nonce() -> u64 {
1919
}
2020
// more than 300 seconds behind
2121
if nonce + 300000 < now_ms {
22-
CUR_NONCE.fetch_max(now_ms, Ordering::Relaxed);
22+
CUR_NONCE.fetch_max(now_ms + 1, Ordering::Relaxed);
23+
return now_ms;
2324
}
2425
nonce
2526
}

0 commit comments

Comments
 (0)