diff --git a/core/chain_makers.go b/core/chain_makers.go index 0799f6606f..baec098631 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -97,7 +97,7 @@ func (b *BlockGen) Difficulty() *big.Int { func (b *BlockGen) SetParentBeaconRoot(root common.Hash) { b.header.ParentBeaconRoot = &root var ( - blockContext = NewEVMBlockContext(b.header, nil, &b.header.Coinbase) + blockContext = NewEVMBlockContext(b.header, b.cm, &b.header.Coinbase) vmenv = vm.NewEVM(blockContext, vm.TxContext{}, b.statedb, b.cm.config, vm.Config{}) ) ProcessBeaconBlockRoot(root, vmenv, b.statedb) @@ -309,7 +309,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse if engine == nil { panic("nil consensus engine") } - cm := newChainMaker(parent, config) + cm := newChainMaker(parent, config, engine) genblock := func(i int, parent *types.Block, triedb *trie.Database, statedb *state.StateDB) (*types.Block, types.Receipts) { b := &BlockGen{i: i, cm: cm, parent: parent, statedb: statedb, engine: engine} @@ -472,16 +472,18 @@ func makeBlockChainWithGenesis(genesis *Genesis, n int, engine consensus.Engine, // chainMaker contains the state of chain generation. type chainMaker struct { bottom *types.Block + engine consensus.Engine config *params.ChainConfig chain []*types.Block chainByHash map[common.Hash]*types.Block receipts []types.Receipts } -func newChainMaker(bottom *types.Block, config *params.ChainConfig) *chainMaker { +func newChainMaker(bottom *types.Block, config *params.ChainConfig, engine consensus.Engine) *chainMaker { return &chainMaker{ bottom: bottom, config: config, + engine: engine, chainByHash: make(map[common.Hash]*types.Block), } } @@ -504,13 +506,18 @@ func (cm *chainMaker) blockByNumber(number uint64) *types.Block { return cm.chain[number-lowest] } -// ChainReader implementation +// ChainReader/ChainContext implementation -// Config returns the chain configuration. +// Config returns the chain configuration (for consensus.ChainReader). func (cm *chainMaker) Config() *params.ChainConfig { return cm.config } +// Engine returns the consensus engine (for ChainContext). +func (cm *chainMaker) Engine() consensus.Engine { + return cm.engine +} + func (cm *chainMaker) CurrentHeader() *types.Header { if len(cm.chain) == 0 { return cm.bottom.Header() diff --git a/core/state_processor_test.go b/core/state_processor_test.go index d3aca42687..e80bc288c3 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -359,7 +359,7 @@ func TestStateProcessorErrors(t *testing.T) { func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Transactions, config *params.ChainConfig) *types.Block { difficulty := big.NewInt(0) if !config.TerminalTotalDifficultyPassed { - fakeChainReader := newChainMaker(nil, config) + fakeChainReader := newChainMaker(nil, config, engine) difficulty = engine.CalcDifficulty(fakeChainReader, parent.Time()+10, &types.Header{ Number: parent.Number(), Time: parent.Time(),