fix(trace): Fix l1Fee (#234)

Fix l1Fee
This commit is contained in:
maskpp 2023-02-24 14:04:25 +08:00 committed by GitHub
parent d91c8c799e
commit 15f94b93ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 7 deletions

View file

@ -89,6 +89,7 @@ type Message interface {
// ExecutionResult includes all output after executing given evm // ExecutionResult includes all output after executing given evm
// message no matter the execution itself is successful or not. // message no matter the execution itself is successful or not.
type ExecutionResult struct { type ExecutionResult struct {
L1Fee *big.Int
UsedGas uint64 // Total used gas but include the refunded gas UsedGas uint64 // Total used gas but include the refunded gas
Err error // Any error encountered during the execution(listed in core/vm/errors.go) Err error // Any error encountered during the execution(listed in core/vm/errors.go)
ReturnData []byte // Returned data from evm(function result or data supplied with revert opcode) ReturnData []byte // Returned data from evm(function result or data supplied with revert opcode)
@ -381,6 +382,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
} }
return &ExecutionResult{ return &ExecutionResult{
L1Fee: st.l1Fee,
UsedGas: st.gasUsed(), UsedGas: st.gasUsed(),
Err: vmerr, Err: vmerr,
ReturnData: ret, ReturnData: ret,

View file

@ -4,7 +4,6 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"math/big"
"runtime" "runtime"
"sync" "sync"
@ -15,7 +14,6 @@ import (
"github.com/scroll-tech/go-ethereum/core/types" "github.com/scroll-tech/go-ethereum/core/types"
"github.com/scroll-tech/go-ethereum/core/vm" "github.com/scroll-tech/go-ethereum/core/vm"
"github.com/scroll-tech/go-ethereum/log" "github.com/scroll-tech/go-ethereum/log"
"github.com/scroll-tech/go-ethereum/rollup/fees"
"github.com/scroll-tech/go-ethereum/rollup/rcfg" "github.com/scroll-tech/go-ethereum/rollup/rcfg"
"github.com/scroll-tech/go-ethereum/rollup/withdrawtrie" "github.com/scroll-tech/go-ethereum/rollup/withdrawtrie"
"github.com/scroll-tech/go-ethereum/rpc" "github.com/scroll-tech/go-ethereum/rpc"
@ -330,17 +328,16 @@ func (api *API) getTxResult(env *traceEnv, state *state.StateDB, index int, bloc
} }
} }
l1Fee := big.NewInt(0) var l1Fee uint64
if vmenv.ChainConfig().UsingScroll { if result.L1Fee != nil {
l1Fee, _ = fees.CalculateL1MsgFee(msg, vmenv.StateDB) l1Fee = result.L1Fee.Uint64()
} }
env.executionResults[index] = &types.ExecutionResult{ env.executionResults[index] = &types.ExecutionResult{
From: sender, From: sender,
To: receiver, To: receiver,
AccountCreated: createdAcc, AccountCreated: createdAcc,
AccountsAfter: after, AccountsAfter: after,
L1Fee: l1Fee.Uint64(), L1Fee: l1Fee,
Gas: result.UsedGas, Gas: result.UsedGas,
Failed: result.Failed(), Failed: result.Failed(),
ReturnValue: fmt.Sprintf("%x", returnVal), ReturnValue: fmt.Sprintf("%x", returnVal),