core: fix AdvancePartialHead to initialize partial state root

After the second snap sync completes, AdvancePartialHead moves the head
markers forward but never initialized partialState.Root(). This caused
ProcessBlockWithBAL to fall back to the parent's header root, which
doesn't match the computed trie root from BAL processing — resulting in
a state root mismatch on the first block after sync.

Fix: call SetRoot(root) and SetLastProcessedBlock() in AdvancePartialHead
so subsequent BAL processing chains from the correct state root.

Also add diagnostic logging to ProcessBlockWithBAL for easier debugging.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
CPerezz 2026-02-18 12:20:37 +01:00
parent 962e2de6e1
commit a0c3999bb9
No known key found for this signature in database
GPG key ID: 62045F34B97177DD
2 changed files with 12 additions and 0 deletions

View file

@ -1418,6 +1418,13 @@ func (bc *BlockChain) AdvancePartialHead(hash common.Hash) error {
bc.currentBlock.Store(block.Header())
headBlockGauge.Update(int64(block.NumberU64()))
// Set the partial state root so ProcessBlockWithBAL chains from the correct root.
// After the second snap sync, the trie root matches the block's header root.
if bc.partialState != nil {
bc.partialState.SetRoot(root)
bc.partialState.SetLastProcessedBlock(block.NumberU64())
}
log.Info("Advanced partial state head", "number", block.Number(), "hash", hash)
return nil
}

View file

@ -94,6 +94,11 @@ func (bc *BlockChain) ProcessBlockWithBAL(
parentRoot = parent.Root()
}
log.Debug("ProcessBlockWithBAL: parent root details",
"block", block.NumberU64(), "parentRoot", parentRoot,
"hasState", bc.HasState(parentRoot), "headerRoot", block.Root(),
"trackedRoot", bc.partialState.Root())
// 4. Apply BAL diffs and compute new state root.
// Pass block.Root() as expectedRoot so the resolver can query peers for this
// state's untracked contracts.