fix root hash calculation during reorgs#2080
Conversation
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (86.36%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #2080 +/- ##
===========================================
- Coverage 50.62% 50.61% -0.01%
===========================================
Files 875 875
Lines 151794 151799 +5
===========================================
- Hits 76842 76835 -7
- Misses 69879 69895 +16
+ Partials 5073 5069 -4
... and 15 files with indirect coverage changes
🚀 New features to boost your workflow:
|
|
@claude Can you review this replacement check from the root hash to the end hash on the function and analyze the impacts? Do a deep analysis based on your deep knowledge on reorgs and how they should be handled. Get the context of the affected function and analyze the impact of this change. By the end evaluate if the tests made for these changes are compatible with the changes or if we should cover any other scenario |
|
Claude finished @lucca30's task in 1m 24s —— View job Deep Analysis: Root Hash Calculation During Reorgs
SummaryThis PR fixes a subtle but important bug in the Core Change AnalysisBefore (Bug)type rootHashCacheEntry struct {
headHash common.Hash // Tracked chain tip
root string
}
// Cache invalidation checked:
if entry.headHash == headHash { /* cache hit */ }
// Reorg detection checked:
newHead := api.chain.CurrentHeader()
if newHead.Hash() != headHash { /* reorg detected */ }After (Fix)type rootHashCacheEntry struct {
endHash common.Hash // Tracks end block of range
root string
}
// Cache invalidation checks:
if entry.endHash == endHash { /* cache hit */ }
// Reorg detection checks:
newEndHeader := api.chain.GetHeaderByNumber(end)
if newEndHeader.Hash() != endHash { /* reorg detected */ }Why This Fix is CorrectThe Problem with Tracking Head HashConsider a checkpoint request for blocks Scenario: Normal block production (no reorg)
This caused spurious cache invalidations whenever the chain tip advanced, even though the blocks The Solution: Track End Block HashBy tracking
Reorg Detection Remains SoundThe fix also correctly updates the reorg detection mechanism:
Defense in Depth: Multiple Reorg Safety MechanismsThe function employs three layers of protection against mixed-fork data:
This multi-layered approach is sound from a reorg-safety perspective. Test Coverage EvaluationTests Added/Modified
The New Test is KeyThe new test
This directly tests the scenario that was broken before. Potential Gap: Non-contiguous Header Error TestThe Suggested additional test scenario:
However, this is a minor gap since:
ConclusionThis fix is correct and improves both performance and precision:
The change from |
|
govuln check is pointing some errors, also kurtosis e2e is not properly running. Would be good having both working before merging. |
@lucca30 |
|
…othash fix root hash calculation during reorgs (cherry picked from commit bbc3b53)



Description
Fix root hash calculation during bor reorgs by always checking the end block's hash instead of current header.
More context here: #1950
Changes
Breaking changes
Please complete this section if any breaking changes have been made, otherwise delete it
Nodes audience
In case this PR includes changes that must be applied only to a subset of nodes, please specify how you handled it (e.g. by adding a flag with a default value...)
Checklist
Cross repository changes
Testing
Manual tests
Please complete this section with the steps you performed if you ran manual tests for this functionality, otherwise delete it
Additional comments
Please post additional comments in this section if you have them, otherwise delete it