Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flow EVM] Reporting results for evm.Run and evm.coa.Call #5397

Merged
merged 21 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions fvm/evm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func TestEVMRun(t *testing.T) {
import EVM from %s

access(all)
fun main(tx: [UInt8], coinbaseBytes: [UInt8; 20]) {
fun main(tx: [UInt8], coinbaseBytes: [UInt8; 20]): EVM.Result {
let coinbase = EVM.EVMAddress(bytes: coinbaseBytes)
EVM.run(tx: tx, coinbase: coinbase)
return EVM.run(tx: tx, coinbase: coinbase)
}
`,
sc.EVMContract.Address.HexWithPrefix(),
Expand Down Expand Up @@ -79,6 +79,11 @@ func TestEVMRun(t *testing.T) {
snapshot)
require.NoError(t, err)
require.NoError(t, output.Err)

res, err := stdlib.ResultSummaryFromEVMResultValue(output.Value)
require.NoError(t, err)
require.Equal(t, types.StatusSuccessful, res.Status)
require.Equal(t, types.ErrCodeNoError, res.ErrorCode)
})
})
}
Expand Down
107 changes: 0 additions & 107 deletions fvm/evm/handler/codeFinder.go

This file was deleted.

47 changes: 16 additions & 31 deletions fvm/evm/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func (h *ContractHandler) FlowTokenAddress() common.Address {
return h.flowTokenAddress
}

func (h *ContractHandler) EVMContractAddress() common.Address {
return common.Address(h.evmContractAddress)
}

var _ types.ContractHandler = &ContractHandler{}

func NewContractHandler(
Expand Down Expand Up @@ -105,34 +109,19 @@ func (h *ContractHandler) LastExecutedBlock() *types.Block {
return block
}

// Run runs an rlpencoded evm transaction and
// RunOrPanic runs an rlpencoded evm transaction and
// collects the gas fees and pay it to the coinbase address provided.
func (h *ContractHandler) Run(rlpEncodedTx []byte, coinbase types.Address) {
func (h *ContractHandler) RunOrPanic(rlpEncodedTx []byte, coinbase types.Address) {
_, err := h.run(rlpEncodedTx, coinbase)
panicOnAnyError(err)
}

// TryRun tries to run an rlpencoded evm transaction and
// Run tries to run an rlpencoded evm transaction and
// collects the gas fees and pay it to the coinbase address provided.
func (h *ContractHandler) TryRun(rlpEncodedTx []byte, coinbase types.Address) *types.ResultSummary {
func (h *ContractHandler) Run(rlpEncodedTx []byte, coinbase types.Address) *types.ResultSummary {
res, err := h.run(rlpEncodedTx, coinbase)
rs := &types.ResultSummary{
Status: types.StatusSuccessful,
}
if err != nil {
panicOnFatalOrBackendError(err)
// remaining errors are validation errors
rs.ErrorCode = ValidationErrorCode(err)
rs.Status = types.StatusInvalid
return rs
}
if res.VMError != nil {
rs.ErrorCode = ExecutionErrorCode(res.VMError)
rs.Status = types.StatusFailed
rs.GasConsumed = res.GasConsumed
}
rs.GasConsumed = res.GasConsumed
return rs
panicOnFatalOrBackendError(err)
return types.NewResultSummary(res, err)
}

func (h *ContractHandler) run(
Expand Down Expand Up @@ -569,13 +558,13 @@ func (a *Account) deploy(code types.Code, gaslimit types.GasLimit, balance types
// it would limit the gas used according to the limit provided
// given it doesn't goes beyond what Flow transaction allows.
// the balance would be deducted from the OFA account and would be transferred to the target address
func (a *Account) Call(to types.Address, data types.Data, gaslimit types.GasLimit, balance types.Balance) types.Data {
data, err := a.call(to, data, gaslimit, balance)
panicOnAnyError(err)
return data
func (a *Account) Call(to types.Address, data types.Data, gaslimit types.GasLimit, balance types.Balance) *types.ResultSummary {
res, err := a.call(to, data, gaslimit, balance)
panicOnFatalOrBackendError(err)
return types.NewResultSummary(res, err)
}

func (a *Account) call(to types.Address, data types.Data, gaslimit types.GasLimit, balance types.Balance) (types.Data, error) {
func (a *Account) call(to types.Address, data types.Data, gaslimit types.GasLimit, balance types.Balance) (*types.Result, error) {
ctx, err := a.precheck(true, gaslimit)
if err != nil {
return nil, err
Expand All @@ -589,11 +578,7 @@ func (a *Account) call(to types.Address, data types.Data, gaslimit types.GasLimi
a.Nonce(),
)

res, err := a.fch.executeAndHandleCall(ctx, call, nil, false)
if err != nil {
return nil, err
}
return res.ReturnedValue, nil
return a.fch.executeAndHandleCall(ctx, call, nil, false)
}

func (a *Account) precheck(authroized bool, gaslimit types.GasLimit) (types.BlockContext, error) {
Expand Down
Loading
Loading