Skip to content

Commit

Permalink
Add extra logging around vm execution
Browse files Browse the repository at this point in the history
  • Loading branch information
piersy committed Nov 1, 2024
1 parent 98fc492 commit cc6ae1d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
6 changes: 3 additions & 3 deletions contracts/contract_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ func (bm *BoundMethod) run(vmRunner vm.EVMRunner, result interface{}, readOnly b

if err != nil {
message, _ := unpackError(output)
logger.Error("Error invoking evm function: EVM call failure", "input", hexutil.Encode(input), "maxgas", bm.maxGas, "err", err, "message", message)
logger.Error("Error invoking evm function: EVM call failure", "input", hexutil.Encode(input), "value", value, "maxgas", bm.maxGas, "err", err, "message", message)
return err
}

if err := bm.decodeResult(result, output); err != nil {
logger.Error("Error invoking evm function: can't unpack result", "err", err, "maxgas", bm.maxGas)
logger.Error("Error invoking evm function: can't unpack result", "input", hexutil.Encode(input), "value", value, "err", err, "maxgas", bm.maxGas)
return err
}

logger.Trace("EVM call successful", "input", hexutil.Encode(input), "output", hexutil.Encode(output))
logger.Trace("EVM call successful", "input", hexutil.Encode(input), "value", value, "output", hexutil.Encode(output))
return nil
}
22 changes: 18 additions & 4 deletions core/vm/vmcontext/runner.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vmcontext

import (
"fmt"
"math/big"

"github.com/celo-org/celo-blockchain/common"
Expand All @@ -20,16 +21,17 @@ type evmRunnerContext interface {
}

type evmRunner struct {
newEVM func(from common.Address) *vm.EVM
state vm.StateDB
newEVM func(from common.Address) *vm.EVM
state vm.StateDB
blockNum uint64

dontMeterGas bool
}

func NewEVMRunner(chain evmRunnerContext, header *types.Header, state vm.StateDB) vm.EVMRunner {

return &evmRunner{
state: state,
blockNum: header.Number.Uint64(),
state: state,
newEVM: func(from common.Address) *vm.EVM {
// The EVM Context requires a msg, but the actual field values don't really matter for this case.
// Putting in zero values for gas price and tx fee recipient
Expand All @@ -49,6 +51,9 @@ func (ev *evmRunner) Execute(recipient common.Address, input []byte, gas uint64,
evm.StopGasMetering()
}
ret, _, err = evm.Call(vm.AccountRef(evm.Origin), recipient, input, gas, value)
if err != nil {
err = fmt.Errorf("execute failed at block %d: %w", ev.blockNum, err)
}
return ret, err
}

Expand All @@ -58,6 +63,9 @@ func (ev *evmRunner) ExecuteFrom(sender, recipient common.Address, input []byte,
evm.StopGasMetering()
}
ret, _, err = evm.Call(vm.AccountRef(sender), recipient, input, gas, value)
if err != nil {
err = fmt.Errorf("execute from failed at block %d: %w", ev.blockNum, err)
}
return ret, err
}

Expand All @@ -68,6 +76,9 @@ func (ev *evmRunner) ExecuteAndDiscardChanges(recipient common.Address, input []
evm.StopGasMetering()
}
ret, _, err = evm.Call(vm.AccountRef(evm.Origin), recipient, input, gas, value)
if err != nil {
err = fmt.Errorf("execute and discard changes failed at block %d: %w", ev.blockNum, err)
}
evm.StateDB.RevertToSnapshot(snapshot)
return ret, err
}
Expand All @@ -78,6 +89,9 @@ func (ev *evmRunner) Query(recipient common.Address, input []byte, gas uint64) (
evm.StopGasMetering()
}
ret, _, err = evm.StaticCall(vm.AccountRef(evm.Origin), recipient, input, gas)
if err != nil {
err = fmt.Errorf("query failed at block %d: %w", ev.blockNum, err)
}
return ret, err
}

Expand Down

0 comments on commit cc6ae1d

Please sign in to comment.