feat: Parallelize header validation with rayon#243
Conversation
WalkthroughThe changes add parallelization support via the rayon dependency and refactor header validation to remove the ValidationMode parameter, introducing parallel validation with explicit chain continuity and proof-of-work checks instead of mode-based branching. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (4)
🧰 Additional context used📓 Path-based instructions (4)**/*.rs📄 CodeRabbit inference engine (CLAUDE.md)
Files:
dash-spv/**/*.rs📄 CodeRabbit inference engine (dash-spv/CLAUDE.md)
Files:
dash-spv/src/sync/**/*.rs📄 CodeRabbit inference engine (dash-spv/CLAUDE.md)
Files:
dash-spv/src/client/**/*.rs📄 CodeRabbit inference engine (dash-spv/CLAUDE.md)
Files:
🧠 Learnings (20)📓 Common learnings📚 Learning: 2025-12-04T15:51:59.632ZApplied to files:
📚 Learning: 2025-12-04T15:51:59.632ZApplied to files:
📚 Learning: 2025-08-21T04:45:50.436ZApplied to files:
📚 Learning: 2025-12-01T08:00:50.618ZApplied to files:
📚 Learning: 2025-12-01T07:59:58.608ZApplied to files:
📚 Learning: 2025-12-01T08:00:50.618ZApplied to files:
📚 Learning: 2025-12-01T07:59:58.608ZApplied to files:
📚 Learning: 2025-12-01T07:59:58.608ZApplied to files:
📚 Learning: 2025-12-04T15:51:59.632ZApplied to files:
📚 Learning: 2025-12-01T08:01:18.174ZApplied to files:
📚 Learning: 2025-12-04T15:51:59.632ZApplied to files:
📚 Learning: 2025-12-04T15:51:59.632ZApplied to files:
📚 Learning: 2025-12-04T15:51:59.632ZApplied to files:
📚 Learning: 2025-12-04T15:51:59.632ZApplied to files:
📚 Learning: 2025-12-01T08:00:50.618ZApplied to files:
📚 Learning: 2025-12-04T15:51:59.632ZApplied to files:
📚 Learning: 2025-06-26T16:02:42.390ZApplied to files:
📚 Learning: 2025-06-26T15:54:02.509ZApplied to files:
📚 Learning: 2025-06-26T15:52:45.327ZApplied to files:
🧬 Code graph analysis (2)dash-spv/src/sync/headers/manager.rs (1)
dash-spv/src/client/sync_coordinator.rs (2)
🔇 Additional comments (6)
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 |
1aa875d to
a3c1449
Compare
2a9b4f7 to
656bc9b
Compare
This PR improves header validation timings and also refactors the validation mode out of `validate_headers` since there is no difference in validation mode timings anymore which is archived by: - Check PoW of i and continuity of i-1 to i in parallel by leveraging a `rayon` parallel iterator. - Using `CachedHeader` to avoid multiple `block_hash` calculations of the same header - Calling `Target::is_met_by` directly which drops another `block_hash` call inside `validate_pow`. | Validation Mode | Before | After | |-----------------|--------------|-------------| | Basic | ~80 ms | ~12 ms | | Full | ~150 ms | ~12 ms |
656bc9b to
5081110
Compare
PastaPastaPasta
left a comment
There was a problem hiding this comment.
I've confirmed this does speed up a local node testnet sync, which should be mostly CPU bound to be near 10s
This PR improves header validation timings and refactors the validation mode out of
validate_headerssince there is no difference in validation mode timings anymore. It also overhauls the header validation tests to remove all the clutter and have few focused tests.Improvements are archived by:
rayonparallel iterator.CachedHeaderto avoid multipleblock_hashcalculations of the same headerTarget::is_met_bydirectly which drops anotherblock_hashcall insidevalidate_pow.Summary by CodeRabbit
Chores
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.