mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
core/vm: fix some issues with metering
This commit is contained in:
parent
be16aabe6f
commit
c4b48d1196
3 changed files with 13 additions and 10 deletions
|
|
@ -24,10 +24,8 @@ import (
|
|||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/go-interpreter/wagon/wasm"
|
||||
|
||||
|
|
@ -78,11 +76,9 @@ func NewEWASMInterpreter(evm *EVM, cfg Config) Interpreter {
|
|||
var meteringContract *Contract
|
||||
if metering {
|
||||
meteringContractAddress := common.HexToAddress("0x000000000000000000000000000000000000000a")
|
||||
meteringContract = NewContract(nil, AccountRef(meteringContractAddress), &big.Int{}, 0)
|
||||
meteringCode := evm.StateDB.GetCode(meteringContractAddress)
|
||||
meteringContract.SetCallCode(&meteringContractAddress, crypto.Keccak256Hash(meteringCode), meteringCode)
|
||||
|
||||
module, err := wasm.ReadModule(bytes.NewReader(evm.StateDB.GetCode(meteringContractAddress)), nil)
|
||||
module, err := wasm.ReadModule(bytes.NewReader(meteringCode), nil)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Error loading the metering contract: %v", err))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import (
|
|||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/go-interpreter/wagon/exec"
|
||||
"github.com/go-interpreter/wagon/wasm"
|
||||
)
|
||||
|
|
@ -697,7 +698,11 @@ func sentinel(in *InterpreterEWASM, input []byte) ([]byte, error) {
|
|||
in.contract = savedContract
|
||||
in.vm = savedVM
|
||||
}()
|
||||
meteringContractAddress := common.HexToAddress("0x000000000000000000000000000000000000000a")
|
||||
meteringCode := in.StateDB.GetCode(meteringContractAddress)
|
||||
in.contract = NewContract(in.contract, AccountRef(meteringContractAddress), &big.Int{}, 0)
|
||||
in.contract = in.meteringContract
|
||||
in.contract.SetCallCode(&meteringContractAddress, crypto.Keccak256Hash(meteringCode), meteringCode)
|
||||
in.vm = in.meteringVM
|
||||
meteredCode, err := in.meteringVM.ExecCode(0)
|
||||
return meteredCode.([]byte), err
|
||||
|
|
|
|||
|
|
@ -151,12 +151,14 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
|||
}
|
||||
|
||||
ewasmOptions := make(map[string]string)
|
||||
for _, option := range strings.Split(config.EWASMInterpreter, ",") {
|
||||
opt := strings.Split(option, ":")
|
||||
if len(opt) != 2 || len(opt[0]) == 0 {
|
||||
panic(fmt.Sprintf("Invalid ewasm option: expected a format of name:value, got: %s", option))
|
||||
if len(config.EWASMInterpreter) > 0 {
|
||||
for _, option := range strings.Split(config.EWASMInterpreter, ",") {
|
||||
opt := strings.Split(option, ":")
|
||||
if len(opt) != 2 || len(opt[0]) == 0 {
|
||||
panic(fmt.Sprintf("Invalid ewasm option: expected a format of name:value, got: %s", option))
|
||||
}
|
||||
ewasmOptions[opt[0]] = opt[1]
|
||||
}
|
||||
ewasmOptions[opt[0]] = opt[1]
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
|
|||
Loading…
Reference in a new issue