mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
core/vm: fix metering contract support
Still some issues for when the creation tx fails
This commit is contained in:
parent
a59a081e4c
commit
b2482f5a4a
4 changed files with 14 additions and 6 deletions
|
|
@ -95,13 +95,14 @@ func runCmd(ctx *cli.Context) error {
|
|||
// VM: vm,
|
||||
// }
|
||||
|
||||
output, err := evm.Interpreter().Run(contract, []byte(input), false)
|
||||
output, leftOver, err := evm.Call(coreVM.AccountRef(callerAddr), contractAddr, input, gas, big.NewInt(0))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Output: %v\n", output)
|
||||
fmt.Println("Output\n", output)
|
||||
fmt.Println("left over gas: ", leftOver)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -407,7 +407,11 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
|
|||
ret, err := run(evm, contract, nil, false)
|
||||
|
||||
/* The new contract needs to be metered after it has executed the constructor */
|
||||
ret = evm.interpreter.PostContractCreation(ret)
|
||||
for _, interpreter := range evm.interpreters {
|
||||
if interpreter.CanRun(contract.Code) {
|
||||
ret = interpreter.PostContractCreation(ret)
|
||||
}
|
||||
}
|
||||
|
||||
// check whether the max code size has been exceeded
|
||||
maxCodeSizeExceeded := evm.ChainConfig().IsEIP158(evm.BlockNumber) && len(ret) > params.MaxCodeSize
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ func (in *InterpreterEWASM) Run(contract *Contract, input []byte, ro bool) ([]by
|
|||
|
||||
module, err := wasm.ReadModule(bytes.NewReader(contract.Code), WrappedModuleResolver(in))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error decoding module at address %s: %v", contract.Address(), err)
|
||||
return nil, fmt.Errorf("Error decoding module at address %s: %v", contract.Address().Hex(), err)
|
||||
}
|
||||
|
||||
// The module should not have any start function
|
||||
|
|
|
|||
|
|
@ -704,8 +704,11 @@ func sentinel(in *InterpreterEWASM, input []byte) ([]byte, error) {
|
|||
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
|
||||
var asBytes []byte
|
||||
if err == nil {
|
||||
asBytes = meteredCode.([]byte)
|
||||
}
|
||||
return asBytes, err
|
||||
}
|
||||
|
||||
func create(p *exec.Process, in *InterpreterEWASM, valueOffset uint32, codeOffset uint32, length uint32, resultOffset uint32) int32 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue