mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core: implement ChainContext interface in chainMaker
This commit is contained in:
parent
c983208c54
commit
619605e13f
2 changed files with 13 additions and 6 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue