refactor: use SteadyClock instead of SystemClock for duration measurements in Dash-specific code#7283
refactor: use SteadyClock instead of SystemClock for duration measurements in Dash-specific code#7283UdjinM6 wants to merge 1 commit intodashpay:developfrom
Conversation
…ments in Dash-specific code Extends the approach from bitcoin#27405 to Dash-specific code. All six call sites were purely measuring elapsed time for timeouts, throttling, or cache expiry — SteadyClock is monotonic and immune to NTP adjustments, making it the correct choice. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
✅ No Merge Conflicts DetectedThis PR currently has no conflicts with other open PRs. |
|
✅ Review complete (commit 01b8c79) |
WalkthroughThis PR migrates timing mechanisms across multiple components from epoch-based Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/net.cpp (1)
3666-3677: LGTM — same pattern, correct here too.Same reasoning as the
ThreadSocketHandlerchange: the default-constructedSteadyClock::time_point{}initial value ensures the 100 ms gate opens on the first iteration, and using a monotonic clock makes the throttle immune to system-time jumps (previously a backward NTP step could extend the effective skip interval, a forward step could unexpectedly unblock it).Minor note (not blocking): the unchanged
condMsgProc.wait_until(...)call a few lines below at roughly line 3704 still spells outstd::chrono::steady_clock::now()directly. SinceSteadyClockis juststd::chrono::steady_clock, it's functionally identical, but a follow-up to use theSteadyClockalias consistently here would be a nice readability nit.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/net.cpp` around lines 3666 - 3677, The condMsgProc.wait_until call still uses std::chrono::steady_clock::now() directly while the surrounding code uses the SteadyClock alias; update the wait_until invocation to use SteadyClock::now() for consistency with the alias used around nLastSendMessagesTimeMasternodes and the loop logic (refer to condMsgProc.wait_until, SteadyClock, and nLastSendMessagesTimeMasternodes) so the code consistently uses the SteadyClock typedef.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/net.cpp`:
- Around line 3666-3677: The condMsgProc.wait_until call still uses
std::chrono::steady_clock::now() directly while the surrounding code uses the
SteadyClock alias; update the wait_until invocation to use SteadyClock::now()
for consistency with the alias used around nLastSendMessagesTimeMasternodes and
the loop logic (refer to condMsgProc.wait_until, SteadyClock, and
nLastSendMessagesTimeMasternodes) so the code consistently uses the SteadyClock
typedef.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 17bb09fd-2752-4123-961a-e04d5d142063
📒 Files selected for processing (7)
src/active/dkgsessionhandler.cppsrc/instantsend/instantsend.cppsrc/instantsend/instantsend.hsrc/llmq/dkgsessionmgr.cppsrc/llmq/dkgsessionmgr.hsrc/net.cppsrc/net.h
@coderabbitai I believe this code is not Dash-specific and it shouldn't be touched here. Pls verify. |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 2893
My nitpick suggesting that line be updated to use the (╥_╥) |
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
Clean SystemClock→SteadyClock refactor for Dash-specific duration-measurement call sites. No blocking issues or suggestions. Two nitpicks surfaced by Claude concerning (1) potential non-lock-free fallback of std::atomicSteadyClock::time_point on non-64-bit targets and (2) the default-constructed time_point sentinel idiom. Both are low-signal observations; Codex independently found nothing to flag.
Reviewed commit: 01b8c79
💬 2 nitpick(s)
| // next time DisconnectNodes() runs | ||
| std::atomic_bool fDisconnect{false}; | ||
| std::atomic<int64_t> nDisconnectLingerTime{0}; | ||
| std::atomic<SteadyClock::time_point> nDisconnectLingerTime{SteadyClock::time_point{}}; |
There was a problem hiding this comment.
💬 Nitpick: std::atomicSteadyClock::time_point lock-freedom is not asserted
std::atomic<SteadyClock::time_point> is well-formed and will be lock-free on all 64-bit targets Dash ships (same width as the previous atomic<int64_t>). On platforms where steady_clock::duration::rep is wider than the largest lock-free integer, libstdc++/libc++ fall back to an internal spinlock — a silent regression from the previous atomic<int64_t>. All official Dash builds are 64-bit so this is not a real concern today; a defensive static_assert(std::atomic<SteadyClock::time_point>::is_always_lock_free) would catch any future regression.
source: ['claude']
| // thus can immediately close the socket. | ||
| if (!pnode->fOtherSideDisconnected) { | ||
| if (pnode->nDisconnectLingerTime == 0) { | ||
| if (pnode->nDisconnectLingerTime.load() == SteadyClock::time_point{}) { |
There was a problem hiding this comment.
💬 Nitpick: Default-constructed time_point used as sentinel
The == SteadyClock::time_point{} check preserves the prior == 0 sentinel semantics and is correct in practice (a running process's SteadyClock::now() is never the epoch). It is slightly less self-documenting than std::optional<SteadyClock::time_point> or a named kUnset constant. Low priority — a short comment at the declaration site would be enough to document the idiom.
source: ['claude']
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
Clean mechanical refactor converting six Dash-specific call sites from epoch-based SystemClock arithmetic to monotonic SteadyClock time_points and chrono durations. Each site measures elapsed time (DKG cache expiry, InstantSend timing, net linger and cleanup intervals, DKG phase sleep), so SteadyClock correctly insulates them from NTP step adjustments. Both Claude and Codex independently verified no correctness, consensus, or build regressions; CodeRabbit also returned zero inline findings.
Reviewed commit: 01b8c79
No findings to report.
Issue being fixed or feature implemented
Extends the approach from bitcoin#27405 to Dash-specific code. All six call sites were purely measuring elapsed time for timeouts, throttling, or cache expiry — SteadyClock is monotonic and immune to NTP adjustments, making it the correct choice.
What was done?
How Has This Been Tested?
Breaking Changes
n/a
Checklist: