Skip to content

refactor(lease): inject WallClock trait into count_matching_leases - #249

Open
EnRaiha wants to merge 2 commits into
NodeDB-Lab:mainfrom
EnRaiha:feat/wallclock-trait
Open

refactor(lease): inject WallClock trait into count_matching_leases#249
EnRaiha wants to merge 2 commits into
NodeDB-Lab:mainfrom
EnRaiha:feat/wallclock-trait

Conversation

@EnRaiha

@EnRaiha EnRaiha commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Lease expiry is a duration question, so it must be measured against real wall time. PR #246 established this after the HlcClock::peek() wedge (a frozen HLC on an idle cluster makes every lease look unexpired). This extracts the clock behind a WallClock trait so the expiry check in count_matching_leases is injectable.

  • New nodedb/src/control/lease/clock.rs: WallClock trait, RealWallClock (production), MockClock (tests).
  • count_matching_leases now takes &dyn WallClock instead of calling super::wall_now_ns() directly.
  • wait_for_lease_drain passes &RealWallClock.
  • Adds 3 MockClock tests that pin the clock and prove expiry uses the injected wall clock, not the HLC (including the skewed-HLC case that must not drop a live lease).

Scope

Single logical change: clock injection for lease expiry. No behaviour change in production (real wall time is still used). Under ~80 lines of new code + tests.

Test plan

cargo test -p nodedb --lib control::lease::drain_propose (existing + 3 new tests).

Follow-up to #246.

Lease expiry is a duration question, so it must be measured against real
wall time (PR NodeDB-Lab#246 established this after the HlcClock::peek wedge). This
extracts the clock behind a WallClock trait so the expiry check is
injectable: RealWallClock for production, MockClock for tests.

count_matching_leases now takes &dyn WallClock instead of calling
super::wall_now_ns() directly. Adds 3 MockClock tests that pin the clock
and prove expiry uses the injected wall clock, not the HLC.

Follow-up to NodeDB-Lab#246; small, single-purpose per review feedback.
Copilot AI lite review requested due to automatic review settings August 25, 2026 03:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

The clock abstraction is a general utility (lease expiry is just the first
consumer), so it belongs in util/ next to bounded_json/bounded_msgpack.
No behaviour change; imports updated. wall_now_ns re-export widened to
pub(crate) so util can reach it.
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