refactor(lease): inject WallClock trait into count_matching_leases - #249
Open
EnRaiha wants to merge 2 commits into
Open
refactor(lease): inject WallClock trait into count_matching_leases#249EnRaiha wants to merge 2 commits into
EnRaiha wants to merge 2 commits into
Conversation
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.
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.
EnRaiha
force-pushed
the
feat/wallclock-trait
branch
from
August 25, 2026 06:53
38f559d to
849f1b7
Compare
This was referenced Aug 25, 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
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 aWallClocktrait so the expiry check incount_matching_leasesis injectable.nodedb/src/control/lease/clock.rs:WallClocktrait,RealWallClock(production),MockClock(tests).count_matching_leasesnow takes&dyn WallClockinstead of callingsuper::wall_now_ns()directly.wait_for_lease_drainpasses&RealWallClock.MockClocktests 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.