Skip to content

fix(payment): forward-port quote-skew tolerance 60s -> 300s (re-applies #83)#91

Merged
mickvandijke merged 1 commit into
WithAutonomi:mainfrom
grumbach:fix/forward-port-quote-skew-300s
May 7, 2026
Merged

fix(payment): forward-port quote-skew tolerance 60s -> 300s (re-applies #83)#91
mickvandijke merged 1 commit into
WithAutonomi:mainfrom
grumbach:fix/forward-port-quote-skew-300s

Conversation

@grumbach
Copy link
Copy Markdown
Collaborator

@grumbach grumbach commented May 7, 2026

Summary

Forward-port of #83 (merged 2026-04-28 into the now-superseded rc-2026.4.3 branch). The fix never made it onto rc-2026.4.4 or main, so the released 0.11.x binary still runs the old QUOTE_CLOCK_SKEW_TOLERANCE_SECS = 60 check.

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_timestamps had an unreachable else arm: when now.duration_since(quote.timestamp) returns Err, quote.timestamp.duration_since(now) necessarily returns Ok, so the "invalid timestamp" path could never fire. Replaced with SystemTimeError::duration().
  • Replaced Duration::as_secs() > CONST with Duration > Duration::from_secs(CONST). The old form floored fractional seconds, silently widening both windows by up to ~1 s past the documented limits.
  • Raised the forward-skew tolerance from 60 s to 300 s and renamed QUOTE_CLOCK_SKEW_TOLERANCE_SECSQUOTE_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 by QUOTE_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 -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test --lib payment::verifier — 44/44 pass

Will validate against prod failure rate once the next testnet run lands.

…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>
Copilot AI review requested due to automatic review settings May 7, 2026 06:53
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_timestamps by using SystemTimeError::duration() and removing the previously unreachable “invalid timestamp” path.
  • Make timestamp comparisons precise by comparing Duration values directly (avoiding as_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 mickvandijke merged commit cb424c6 into WithAutonomi:main May 7, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants