Skip to content

Commit de39513

Browse files
chfastgballet
authored andcommitted
core, internal, eth, miner, les: Take VM config from BlockChain (#17955)
Until this commit, when sending an RPC request that called `NewEVM`, a blank `vm.Config` would be taken so as to set some options, based on the default configuration. If some extra configuration switches were passed to the blockchain, those would be ignored. This PR adds a function to get the config from the blockchain, and this is what is now used for RPC calls. Some subsequent changes need to be made, see #17955 (review) for the details of the discussion.
1 parent 3ac633b commit de39513

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

core/blockchain.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ func (bc *BlockChain) getProcInterrupt() bool {
210210
return atomic.LoadInt32(&bc.procInterrupt) == 1
211211
}
212212

213+
// GetVMConfig returns the block chain VM config.
214+
func (bc *BlockChain) GetVMConfig() *vm.Config {
215+
return &bc.vmConfig
216+
}
217+
213218
// loadLastState loads the last known chain state from the database. This method
214219
// assumes that the chain manager mutex is held.
215220
func (bc *BlockChain) loadLastState() error {

eth/api_backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ func (b *EthAPIBackend) GetTd(blockHash common.Hash) *big.Int {
125125
return b.eth.blockchain.GetTdByHash(blockHash)
126126
}
127127

128-
func (b *EthAPIBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmCfg vm.Config) (*vm.EVM, func() error, error) {
128+
func (b *EthAPIBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header) (*vm.EVM, func() error, error) {
129129
state.SetBalance(msg.From(), math.MaxBig256)
130130
vmError := func() error { return nil }
131131

132132
context := core.NewEVMContext(msg, header, b.eth.BlockChain(), nil)
133-
return vm.NewEVM(context, state, b.eth.chainConfig, vmCfg), vmError, nil
133+
return vm.NewEVM(context, state, b.eth.chainConfig, *b.eth.blockchain.GetVMConfig()), vmError, nil
134134
}
135135

136136
func (b *EthAPIBackend) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription {

internal/ethapi/api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ type CallArgs struct {
683683
Data hexutil.Bytes `json:"data"`
684684
}
685685

686-
func (s *PublicBlockChainAPI) doCall(ctx context.Context, args CallArgs, blockNr rpc.BlockNumber, vmCfg vm.Config, timeout time.Duration) ([]byte, uint64, bool, error) {
686+
func (s *PublicBlockChainAPI) doCall(ctx context.Context, args CallArgs, blockNr rpc.BlockNumber, timeout time.Duration) ([]byte, uint64, bool, error) {
687687
defer func(start time.Time) { log.Debug("Executing EVM call finished", "runtime", time.Since(start)) }(time.Now())
688688

689689
state, header, err := s.b.StateAndHeaderByNumber(ctx, blockNr)
@@ -724,7 +724,7 @@ func (s *PublicBlockChainAPI) doCall(ctx context.Context, args CallArgs, blockNr
724724
defer cancel()
725725

726726
// Get a new instance of the EVM.
727-
evm, vmError, err := s.b.GetEVM(ctx, msg, state, header, vmCfg)
727+
evm, vmError, err := s.b.GetEVM(ctx, msg, state, header)
728728
if err != nil {
729729
return nil, 0, false, err
730730
}
@@ -748,7 +748,7 @@ func (s *PublicBlockChainAPI) doCall(ctx context.Context, args CallArgs, blockNr
748748
// Call executes the given transaction on the state for the given block number.
749749
// It doesn't make and changes in the state/blockchain and is useful to execute and retrieve values.
750750
func (s *PublicBlockChainAPI) Call(ctx context.Context, args CallArgs, blockNr rpc.BlockNumber) (hexutil.Bytes, error) {
751-
result, _, _, err := s.doCall(ctx, args, blockNr, vm.Config{}, 5*time.Second)
751+
result, _, _, err := s.doCall(ctx, args, blockNr, 5*time.Second)
752752
return (hexutil.Bytes)(result), err
753753
}
754754

@@ -777,7 +777,7 @@ func (s *PublicBlockChainAPI) EstimateGas(ctx context.Context, args CallArgs) (h
777777
executable := func(gas uint64) bool {
778778
args.Gas = hexutil.Uint64(gas)
779779

780-
_, _, failed, err := s.doCall(ctx, args, rpc.PendingBlockNumber, vm.Config{}, 0)
780+
_, _, failed, err := s.doCall(ctx, args, rpc.PendingBlockNumber, 0)
781781
if err != nil || failed {
782782
return false
783783
}

internal/ethapi/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type Backend interface {
5353
GetBlock(ctx context.Context, blockHash common.Hash) (*types.Block, error)
5454
GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error)
5555
GetTd(blockHash common.Hash) *big.Int
56-
GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmCfg vm.Config) (*vm.EVM, func() error, error)
56+
GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header) (*vm.EVM, func() error, error)
5757
SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
5858
SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
5959
SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription

les/api_backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ func (b *LesApiBackend) GetTd(hash common.Hash) *big.Int {
105105
return b.eth.blockchain.GetTdByHash(hash)
106106
}
107107

108-
func (b *LesApiBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmCfg vm.Config) (*vm.EVM, func() error, error) {
108+
func (b *LesApiBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header) (*vm.EVM, func() error, error) {
109109
state.SetBalance(msg.From(), math.MaxBig256)
110110
context := core.NewEVMContext(msg, header, b.eth.blockchain, nil)
111-
return vm.NewEVM(context, state, b.eth.chainConfig, vmCfg), state.Error, nil
111+
return vm.NewEVM(context, state, b.eth.chainConfig, vm.Config{}), state.Error, nil
112112
}
113113

114114
func (b *LesApiBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error {

miner/worker.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"github.com/ethereum/go-ethereum/core"
3232
"github.com/ethereum/go-ethereum/core/state"
3333
"github.com/ethereum/go-ethereum/core/types"
34-
"github.com/ethereum/go-ethereum/core/vm"
3534
"github.com/ethereum/go-ethereum/event"
3635
"github.com/ethereum/go-ethereum/log"
3736
"github.com/ethereum/go-ethereum/params"
@@ -692,7 +691,7 @@ func (w *worker) updateSnapshot() {
692691
func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Address) ([]*types.Log, error) {
693692
snap := w.current.state.Snapshot()
694693

695-
receipt, _, err := core.ApplyTransaction(w.config, w.chain, &coinbase, w.current.gasPool, w.current.state, w.current.header, tx, &w.current.header.GasUsed, vm.Config{})
694+
receipt, _, err := core.ApplyTransaction(w.config, w.chain, &coinbase, w.current.gasPool, w.current.state, w.current.header, tx, &w.current.header.GasUsed, *w.chain.GetVMConfig())
696695
if err != nil {
697696
w.current.state.RevertToSnapshot(snap)
698697
return nil, err

0 commit comments

Comments
 (0)