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 <garyrong0905@gmail.com>
This commit is contained in:
Marius van der Wijden 2026-07-28 04:30:40 +02:00 committed by GitHub
parent 3dad51ec5b
commit 1bfc028d43
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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),