-
Notifications
You must be signed in to change notification settings - Fork 1.2k
perf: cache x11 block header hash, reduce reindex hashes from 4->2 per block #6610
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
base: develop
Are you sure you want to change the base?
perf: cache x11 block header hash, reduce reindex hashes from 4->2 per block #6610
Conversation
WalkthroughThe changes introduce an optional caching mechanism for block header hashes within the Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (10)
🚧 Files skipped from review as they are similar to previous changes (10)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Nice! 👍
develop: This PR: |
10b0bc8
to
3e760e2
Compare
SERIALIZE_METHODS(CBlockHeader, obj) { READWRITE(obj.nVersion, obj.hashPrevBlock, obj.hashMerkleRoot, obj.nTime, obj.nBits, obj.nNonce); } | ||
SERIALIZE_METHODS(CBlockHeader, obj) { | ||
READWRITE(obj.nVersion, obj.hashPrevBlock, obj.hashMerkleRoot, obj.nTime, obj.nBits, obj.nNonce); | ||
obj.cached_hash.SetNull(); |
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.
I think it may reset only in case of read
event
See tsan error: https://gitlab.com/dashpay/dash/-/jobs/9770587678
|
…shing sources 0c5e295 chore: retain only Skein512, remove other variants (Kittywhiskers Van Gogh) 6fa5ddc chore: retain only Simd512, remove other variants (Kittywhiskers Van Gogh) 2c5b641 chore: retain only Shavite512, remove other variants (Kittywhiskers Van Gogh) 9035b5f chore: retain only Luffa512, remove other variants (Kittywhiskers Van Gogh) 11c0517 chore: retain only Keccak512, remove other variants (Kittywhiskers Van Gogh) 9fa0bc9 chore: retain only Jh512, remove other variants (Kittywhiskers Van Gogh) 9229220 chore: retain only Groestl512, remove other variants (Kittywhiskers Van Gogh) 822e75d chore: retain only Echo512, remove other variants (Kittywhiskers Van Gogh) 79f3078 chore: retain only Cubehash512, remove other variants (Kittywhiskers Van Gogh) 05e53e6 chore: retain only Bmw512, remove other variants (Kittywhiskers Van Gogh) 974b330 chore: retain only Blake512, remove other variants (Kittywhiskers Van Gogh) 4a31cfb chore: remove unused big-endian AES tables (Kittywhiskers Van Gogh) d0f94c3 chore: remove Doxygen macro blocks (Kittywhiskers Van Gogh) 79b9c87 chore: remove commented out code (Kittywhiskers Van Gogh) Pull request description: ## Motivation Dash utilizes a daisy-chain of 11 hash algorithms for its proof of work termed X11. The library that provided the implementation of the underlying hash algorithms is `sphlib` by Thomas Pornin ([source](https://web.archive.org/web/20180428002946/http://www.saphir2.com/sphlib/), Internet Archive). The library has been a part of Dash Core since inception (f164aea) and does what it says on the tin quite well. Though, it's been a solid decade since and performance profiling has shown that proof of work hashing takes up a not-insignificant amount of time. As an alternative to (or alongside) [dash#6610](#6610), we intend to work on improving the performance of X11 while maintaining readability and auditability. To begin with that, we are removing variants that Dash _doesn't_ use, namely, non 512-bit variants of the constituent algorithms used and subsequent pull requests will be integrating the library's contents with primitives available in Dash Core to allow for attributable and reasonable performance improvements. ## Breaking Changes None expected. ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas **(note: N/A)** - [x] I have added or updated relevant unit/integration/functional/e2e tests **(note: N/A)** - [x] I have made corresponding changes to the documentation **(note: N/A)** - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: PastaPastaPasta: utACK 0c5e295 UdjinM6: utACK 0c5e295 knst: utACK 0c5e295 Tree-SHA512: fb6cd94bcb01b9434d83c35509f5bd2ed902c918bf58d7027af87643abcd62a937aa94070d73c7a2c4e9177809194369b71630e353df87e0432dac503e8e0d72
Issue being fixed or feature implemented
We currently hash the header up to 4 times per block we are loading from disk; drop this down to 2 times
before:

./src/dashd --printtoconsole --testnet --nowallet --reindex --stopatheight=1 76.34s user 6.15s system 95% cpu 1:25.98 total
after:
./src/dashd --printtoconsole --testnet --nowallet --reindex --stopatheight=1 62.87s user 5.70s system 95% cpu 1:11.52 total

Shaves ~20-25% off of header reindex times.
Calculated as ((76.34-62.87)/76.34)=17.6%, but this includes the overhead of startup / shutdown, so it's likely higher.
What was done?
How Has This Been Tested?
Reindex headers; should probably do a full reindex
Breaking Changes
Checklist:
Go over all the following points, and put an
x
in all the boxes that apply.