From a0c3999bb95f25e6f317f1737402ebb28c05e370 Mon Sep 17 00:00:00 2001 From: CPerezz Date: Wed, 18 Feb 2026 12:20:37 +0100 Subject: [PATCH] core: fix AdvancePartialHead to initialize partial state root MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- core/blockchain.go | 7 +++++++ core/blockchain_partial.go | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/core/blockchain.go b/core/blockchain.go index 45eee13a19..8da91009cf 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -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 } diff --git a/core/blockchain_partial.go b/core/blockchain_partial.go index 6b50ac1c26..8cf8ab5fa0 100644 --- a/core/blockchain_partial.go +++ b/core/blockchain_partial.go @@ -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.