fix(payment): forward-port quote-skew tolerance 60s -> 300s (re-applies #83)#91
Merged
mickvandijke merged 1 commit intoMay 7, 2026
Conversation
…window to 300s `validate_quote_timestamps` had an unreachable `else` arm: if `now.duration_since(quote.timestamp)` returned `Err` (quote in the future), then `quote.timestamp.duration_since(now)` necessarily returns `Ok`, so the path that returned "has invalid timestamp" could never fire. Replaced the nested match with `SystemTimeError::duration()`, dropping the dead arm and its misleading error string. Also switched the boundary checks from `Duration::as_secs() > CONST` to `Duration > Duration::from_secs(CONST)`. The old form floored fractional seconds, silently widening both windows by up to ~1s past the documented limits. Behavior change: forward-skew tolerance bumped from 60s to 300s and the constant renamed `QUOTE_CLOCK_SKEW_TOLERANCE_SECS` -> `QUOTE_FUTURE_SKEW_TOLERANCE_SECS`. The previous 60s was too tight for unmanaged P2P nodes with imperfect clock sync; 300s gives realistic drift headroom while still being negligible against the 24h max age. Past-side skew is intentionally absorbed entirely by `QUOTE_MAX_AGE_SECS` — there is no separate past tolerance. Tests updated: the "beyond tolerance" test now uses 360s in the future to clear the new 300s threshold. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This pull request forward-ports the payment quote freshness fix from #83 to ensure production nodes accept realistically forward-dated quotes under common wall-clock drift, while still rejecting stale and excessively future quotes.
Changes:
- Increase tolerated forward quote timestamp skew from 60s to 300s and rename the constant to reflect “future skew” semantics.
- Simplify and correct future-timestamp handling in
validate_quote_timestampsby usingSystemTimeError::duration()and removing the previously unreachable “invalid timestamp” path. - Make timestamp comparisons precise by comparing
Durationvalues directly (avoidingas_secs()flooring in the decision logic) and update the affected tests accordingly.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mickvandijke
approved these changes
May 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Forward-port of #83 (merged 2026-04-28 into the now-superseded
rc-2026.4.3branch). The fix never made it ontorc-2026.4.4ormain, so the released0.11.xbinary still runs the oldQUOTE_CLOCK_SKEW_TOLERANCE_SECS = 60check.This is the dominant prod failure mode in Chris's 2026-05-05/06/07 PROD-UL-01 / STG-01 failure-analysis runs: storers reject quotes whose timestamp is in the future beyond the 60s tolerance, which fires regularly under realistic operator-clock drift.
Cherry-picks Mick's commit verbatim (
069f6bc):validate_quote_timestampshad an unreachableelsearm: whennow.duration_since(quote.timestamp)returnsErr,quote.timestamp.duration_since(now)necessarily returnsOk, so the "invalid timestamp" path could never fire. Replaced withSystemTimeError::duration().Duration::as_secs() > CONSTwithDuration > Duration::from_secs(CONST). The old form floored fractional seconds, silently widening both windows by up to ~1 s past the documented limits.QUOTE_CLOCK_SKEW_TOLERANCE_SECS→QUOTE_FUTURE_SKEW_TOLERANCE_SECS. 60 s was too tight for unmanaged P2P nodes with imperfect clock sync; 300 s gives realistic drift headroom while remaining negligible against the 24 h max age. Past-side skew is intentionally absorbed entirely byQUOTE_MAX_AGE_SECS— there is no separate past tolerance.No public API change. Behaviour change is limited to which forward-dated quotes are accepted.
Test plan
cargo fmt --all -- --checkcargo clippy --all-targets --all-features -- -D warningscargo test --lib payment::verifier— 44/44 passWill validate against prod failure rate once the next testnet run lands.