Skip to content

Conversation

gubatron
Copy link
Contributor

This patch removes ad-hoc time conversions and establishes a single, correct, and auditable path for turning SystemTime into microseconds across the auctions client. It also ensures event filtering uses the right on-chain width (U256) and tightens error messages so unit mismatches are obvious.

What changed

  • New helpers inside AuctionClient:
    • micros_from_system_time(SystemTime) -> u128
    • micros_u64_from_system_time(SystemTime) -> anyhow::Result<u64> (overflow-checked)
    • micros_u256_from_system_time(SystemTime) -> U256
  • fetch_bids_for_deadline now filters with topic3(Self::micros_u256_from_system_time(deadline))
  • submit_bid now converts the deadline via micros_u64_from_system_timereplacing the previous inline try_into()
  • Error text corrected from "seconds" to "microseconds" to reflect actual units.

Why this is needed

  • Correctness & type fidelity: The auction ABI uses microseconds; topics are 256-bit. Converting once and feeding the exact expected types eliminates subtle bugs (e.g., ms/us mismatches, accidental narrowing).
  • Overflow safety: Far-future deadlines now fail fast with a precise error instead of silently truncating to u64
  • Maintainability: Centralizing the conversions prevents drift and duplication. If our time representation changes, we update in one place. DRY principle.
  • Operator clarity: Accurate error messages shorten incident triage when a caller provides an out-of-range timestamp.

Risk assessment

  • Low. This is a client-side refactor preserving semantics for valid inputs. The only behavior change is improved validation (explicit overflow error) and more accurate error messages.
  • Gas/chain impact: None. Contract code and calldata formats are unchanged.
  • Backwards compatibility: Call sites passing reasonable deadlines continue to behave identically.

Notes for reviewers

  • The helpers are intentionally fn (not const fn) to keep the surface minimal and focused on correctness rather than compile-time evaluation.
  • Naming uses µs/micros consistently; this PR also scrubs the last misleading “seconds” mention in error text.
  • If we later store deadlines differently (e.g., milliseconds or a newtype), swapping the internals of these helpers will propagate safely.

Checklist

  • Centralized conversions
  • Correct U256 topic filtering
  • Overflow-checked u64 path
  • Clear, unit-accurate error messages
  • No public API breakage

If there’s any preference to move these helpers to a shared time utils module, I can follow up with a separate, mechanical PR.

Cheers!

…; tighten errors

- Introduce helpers in AuctionClient to convert SystemTime to:
  - u128 microseconds (single source of truth)
  - u64 microseconds (with overflow check + clear error msg)
  - U256 microseconds (for event/topic filters)

- Replace ad-hoc conversions with helpers in:
  - fetch_bids_for_deadline(): now passes U256 microseconds directly to topic3
  - submit_bid(): now converts to u64 microseconds via checked path

- Fix misleading error text ("seconds") → accurate "microseconds".

Why:
- Correctness: the ABI uses microseconds; mixing ad-hoc conversions risks ms/us mistakes.
- Safety: explicit u64 fallible conversion avoids silent truncation on far-future deadlines.
- Consistency/maintainability: one code path for time conversions reduces duplication and bugs.
- Clarity: U256 for event topics matches on-chain types; errors now communicate the real unit.

No behavior change for valid inputs; client logic only (no contract/ABI changes).
Copy link
Contributor

@abresas abresas left a comment

Choose a reason for hiding this comment

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

LGTM

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.

2 participants