Skip to content

Commit

Permalink
evmc: Add InitEVMC() for EVMC initialization at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Aug 7, 2019
1 parent 6258358 commit 1aa1499
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmd/evm/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ func runCmd(ctx *cli.Context) error {
},
}

vm.InitEVMC(runtimeConfig.EVMConfig.EVMInterpreter, runtimeConfig.EVMConfig.EWASMInterpreter)

if cpuProfilePath := ctx.GlobalString(CPUProfileFlag.Name); cpuProfilePath != "" {
f, err := os.Create(cpuProfilePath)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,8 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
cfg.Miner.GasPrice = big.NewInt(1)
}
}

vm.InitEVMC(cfg.EVMInterpreter, cfg.EWASMInterpreter)
}

// SetDashboardConfig applies dashboard related command line flags to the config.
Expand Down
12 changes: 10 additions & 2 deletions core/vm/evmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ var (
ewasmModule EVMCModule
)

// InitEVMC initializes the EVMC modules.
func InitEVMC(evmConfig string, ewasmConfig string) {
if evmConfig != "" {
initEVMC(&evmModule, evmc.CapabilityEVM1, evmConfig)
}
if ewasmConfig != "" {
initEVMC(&ewasmModule, evmc.CapabilityEWASM, ewasmConfig)
}
}

func initEVMC(module *EVMCModule, cap evmc.Capability, config string) {
module.once.Do(func() {
options := strings.Split(config, ",")
Expand Down Expand Up @@ -102,8 +112,6 @@ func NewEVMC(cap evmc.Capability, config string, env *EVM) *EVMC {
panic(fmt.Errorf("EVMC: Unknown capability %d", cap))
}

initEVMC(module, cap, config)

return &EVMC{module.instance, env, cap, false}
}

Expand Down
1 change: 1 addition & 0 deletions tests/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ var testVMConfig = func() vm.Config {
flag.StringVar(&vmconfig.EVMInterpreter, utils.EVMInterpreterFlag.Name, utils.EVMInterpreterFlag.Value, utils.EVMInterpreterFlag.Usage)
flag.StringVar(&vmconfig.EWASMInterpreter, utils.EWASMInterpreterFlag.Name, utils.EWASMInterpreterFlag.Value, utils.EWASMInterpreterFlag.Usage)
flag.Parse()
vm.InitEVMC(vmconfig.EVMInterpreter, vmconfig.EWASMInterpreter)
return vmconfig
}()

Expand Down

0 comments on commit 1aa1499

Please sign in to comment.