From 1bfc028d4353ca808f17170abf949f7f7b72cc5c Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Tue, 28 Jul 2026 04:30:40 +0200 Subject: [PATCH] miner: don't seal block if a db error occurred (#35427) A corrupted node should not create a bad block, but rather error out --------- Co-authored-by: rjl493456442 --- miner/worker.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/miner/worker.go b/miner/worker.go index 1a527007e7..e0e49217f8 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -45,6 +45,7 @@ var ( errBlockInterruptedByNewHead = errors.New("new head arrived while building block") errBlockInterruptedByRecommit = errors.New("recommit interrupt while building block") errBlockInterruptedByTimeout = errors.New("timeout while building block") + errStateReadFailure = errors.New("state read failed while building block") ) // maxBlobsPerBlock returns the maximum number of blobs per block. @@ -230,6 +231,11 @@ func (miner *Miner) generateWork(ctx context.Context, genParam *generateParams, block := core.AssembleBlock(miner.chain, work.header, work.state, &body, work.receipts, work.bal) assembleSpanEnd(nil) + // Check for db errors. If anything happened during the mining or IntermediateRoot, such as a + // weird flush or a trie node missing, we need to bail out and not create a block. + if dbErr := work.state.Error(); dbErr != nil { + return &newPayloadResult{err: fmt.Errorf("%w: %v", errStateReadFailure, dbErr)} + } return &newPayloadResult{ block: block, fees: totalFees(block, work.receipts),