Repository navigation
Conversation
Reject branches whose common ancestor is below the current solidified height before erasing the canonical chain. Remove the rejected candidate path from Khaos and restore its canonical head.
Keep the common parent at the solidified boundary in single-witness fork scenarios. Allow execution to reach permission revalidation and successful-fork side effects under the solidified ancestor guard.
halibobo1205
left a comment
There was a problem hiding this comment.
[DISCUSS] Non-blocking follow-up. The guard reads LatestSolidifiedBlockNum from DynamicPropertiesStore, which eraseBlock() rolls back together with the snapshots, and DposService.updateSolidBlock() only compares against that rolled-back value. After an allowed switch, the solidified height can therefore end up lower than before, if the new branch's confirmations of the common prefix are spread differently (for example, a node on the smaller side of a partition rejoining). The next switch is then checked against the lower floor. That regression predates this PR. If the intent is "never reorg past a height this node has already reported as solidified", the guard could use a monotonic floor (for example, the highest solidified height seen after a committed block), plus a test that does an allowed switch which lowers the solidified height and then checks that a fork below the old height is still rejected.
| long ancestorNum = binaryTree.getValue().peekLast().getNum() - 1; | ||
| long solidifiedNum = getDynamicPropertiesStore().getLatestSolidifiedBlockNum(); | ||
| if (ancestorNum < solidifiedNum) { | ||
| Metrics.counterInc(MetricKeys.Counter.BLOCK_FORK, 1, MetricLabels.FAIL); |
There was a problem hiding this comment.
[NIT] The BLOCK_FORK/FAIL counter plus the BLOCKCHAIN_FAIL_FORK_COUNT meter now appear three times in switchFork. A small private helper would keep them in sync.
There was a problem hiding this comment.
The two metric updates are straightforward at each of the three failure sites. I'd prefer to keep this fix focused and retain the current structure for now. We can consider extracting a helper if more failure paths are added.
|
|
||
| if (solidifiedOffset > 0) { | ||
| int snapshots = dbManager.getRevokingStore().size(); | ||
| assertThrows(BadBlockException.class, () -> dbManager.pushBlock(newHead)); |
There was a problem hiding this comment.
[NIT] No test covers khaosDb.setHead(binaryTree.getValue().peekFirst()) yet. With that line removed, all switchForkShould* tests still pass. Once the branch is removed, the highest block left in Khaos is oldHead anyway, so removeBlk's own head recompute already lands on it. If it's cheap to build, a case where Khaos still holds a non-canonical block at or above the old head's height when the guard fires would pin this down.
There was a problem hiding this comment.
Agreed, the current fixture does not independently verify the explicit head restoration. The tests primarily cover rejection at the solidified boundary, preservation of the original chain, and continued processing of subsequent blocks. The additional cached-branch scenario you suggested would strengthen coverage; I'd prefer to keep the existing tests for this fix and consider adding that case separately.
What does this PR do?
Reject branches whose common ancestor is below the current solidified height before erasing the canonical chain. Remove the rejected candidate path from Khaos and restore its canonical head.
Why are these changes required?
This PR has been tested by:
Follow up
Extra details