From 9783cbb9956a99d6422b60b68b360eb1cb071acd Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 27 Oct 2023 16:12:34 +0200 Subject: [PATCH] core: remove weird conditional around consensus engine GenerateChain doesn't work without a consensus engine, so this check is redundant and weird. --- core/chain_makers.go | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/core/chain_makers.go b/core/chain_makers.go index daea498e9f..188e38b521 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -306,6 +306,9 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse if config == nil { config = params.TestChainConfig } + if engine == nil { + panic("nil consensus engine") + } cm := newChainMaker(parent, config) genblock := func(i int, parent *types.Block, triedb *trie.Database, statedb *state.StateDB) (*types.Block, types.Receipts) { @@ -340,23 +343,21 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse if gen != nil { gen(i, b) } - if b.engine != nil { - block, err := b.engine.FinalizeAndAssemble(cm, b.header, statedb, b.txs, b.uncles, b.receipts, b.withdrawals) - if err != nil { - panic(err) - } - // Write state changes to db - root, err := statedb.Commit(b.header.Number.Uint64(), config.IsEIP158(b.header.Number)) - if err != nil { - panic(fmt.Sprintf("state write error: %v", err)) - } - if err = triedb.Commit(root, false); err != nil { - panic(fmt.Sprintf("trie write error: %v", err)) - } - return block, b.receipts + block, err := b.engine.FinalizeAndAssemble(cm, b.header, statedb, b.txs, b.uncles, b.receipts, b.withdrawals) + if err != nil { + panic(err) } - return nil, nil + + // Write state changes to db + root, err := statedb.Commit(b.header.Number.Uint64(), config.IsEIP158(b.header.Number)) + if err != nil { + panic(fmt.Sprintf("state write error: %v", err)) + } + if err = triedb.Commit(root, false); err != nil { + panic(fmt.Sprintf("trie write error: %v", err)) + } + return block, b.receipts } // Forcibly use hash-based state scheme for retaining all nodes in disk.