-
Notifications
You must be signed in to change notification settings - Fork 1.2k
perf: faster calculation for versionbits #7064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ No Merge Conflicts DetectedThis PR currently has no conflicts with other open PRs. |
WalkthroughPrecomputes the attempt count and threshold used during STARTED-state processing in src/versionbits.cpp. Adds an early-return: if pindexPrev->nHeight is below MinBIP9WarningHeight, the state is marked DEFINED immediately. In the STARTED path, nAttempt and the threshold are computed once and reused inside the counting loop and the final comparison, replacing per-iteration threshold recalculation. FAILED determination based on median time past is unchanged. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (1)src/**/*.{cpp,h,hpp,cc}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🧠 Learnings (1)📓 Common learnings🧬 Code graph analysis (1)src/versionbits.cpp (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
🔇 Additional comments (4)
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 |
a4a461e to
ff742c6
Compare
|
Pls consider 1bb965e instead. CI: https://github.com/UdjinM6/dash/actions/runs/20215172691. |
It changes logic and that's a breaking change. Bip9warning is used only for warnings, but not for real for calculations of fork so far. But yeah, it works. What do you think? |
Not really. All known old deployments are below |
Optimize GetStateFor to stop walking backwards once it reaches MinBIP9WarningHeight. Since WarningBitsConditionChecker's Condition requires height >= MinBIP9WarningHeight, states below this are always DEFINED.
|
I moved check 5seconds -> 0.013s. 300 times faster! We are safe until we reach 200M blocks :D |
UdjinM6
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 617059f
Issue being fixed or feature implemented
::cs_mainmutex is kept after Dash-Qt starts until chain state is loaded.Loading of changestate includes a step with calculations of BIP9-warnings about unknown bits.
It takes just 0.3s [far from instant, but reasonable fast] per bit in my environment. But knowing that
VERSIONBITS_NUM_BITS=29it makes Dash Core start for 5-8seconds slower.Main window is shown on screen, UI is responsible during this calculations; but many RPC such as
getblockchaininfocan not be called yet; sync of new blocks and governance objects is delayed for all time that::cs_mainis held.This slow calculation for bip-9 warnings doesn't affect further consecutive blocks validation, because cache is used there and it's fulfilled after 1st time. Issue is relevant only for cold load of chainstate.
What was done?
This PR makes calculations of
AbstractThresholdConditionChecker::GetStateForfor case ofThresholdState::STARTEDfaster by early exit from internal loop over 2016 [nPeriod] blocks.This PR makes Dash Core (dash-qt, dashd) to sync 5-10 seconds faster after start.
How Has This Been Tested?
I added extra logs and made a guix build with all optimizations:
Current
develop:With changes from PR:
Breaking Changes
N/A
Checklist: