fix(trace): change l1Fee type from uint64 to *big.Int (#360)

* fix: change l1Fee type from uint64 to *big.Int

* use hexutil.Big
This commit is contained in:
Péter Garamvölgyi 2023-06-09 16:28:40 +02:00 committed by GitHub
parent 983d630244
commit 4e0daeb300
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 10 deletions

View file

@ -44,10 +44,10 @@ type StorageTrace struct {
// while replaying a transaction in debug mode as well as transaction
// execution status, the amount of gas used and the return value
type ExecutionResult struct {
L1Fee uint64 `json:"l1Fee,omitempty"`
Gas uint64 `json:"gas"`
Failed bool `json:"failed"`
ReturnValue string `json:"returnValue"`
L1Fee *hexutil.Big `json:"l1Fee,omitempty"`
Gas uint64 `json:"gas"`
Failed bool `json:"failed"`
ReturnValue string `json:"returnValue"`
// Sender's account state (before Tx)
From *AccountWrapper `json:"from,omitempty"`
// Receiver's account state (before Tx)

View file

@ -930,6 +930,7 @@ func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Contex
Failed: result.Failed(),
ReturnValue: returnVal,
StructLogs: vm.FormatLogs(tracer.StructLogs()),
L1Fee: (*hexutil.Big)(result.L1Fee),
}, nil
case Tracer:

View file

@ -384,16 +384,12 @@ func (api *API) getTxResult(env *traceEnv, state *state.StateDB, index int, bloc
}
}
var l1Fee uint64
if result.L1Fee != nil {
l1Fee = result.L1Fee.Uint64()
}
env.executionResults[index] = &types.ExecutionResult{
From: sender,
To: receiver,
AccountCreated: createdAcc,
AccountsAfter: after,
L1Fee: l1Fee,
L1Fee: (*hexutil.Big)(result.L1Fee),
Gas: result.UsedGas,
Failed: result.Failed(),
ReturnValue: fmt.Sprintf("%x", returnVal),

View file

@ -164,10 +164,12 @@ func checkStructLogs(t *testing.T, expect []*txTraceResult, actual []*types.Exec
assert.Equal(t, len(expect), len(actual))
for i, val := range expect {
trace1, trace2 := val.Result.(*types.ExecutionResult), actual[i]
assert.Equal(t, trace1.L1Fee, trace2.L1Fee)
assert.Equal(t, trace1.Failed, trace2.Failed)
assert.Equal(t, trace1.Gas, trace2.Gas)
assert.Equal(t, trace1.ReturnValue, trace2.ReturnValue)
assert.Equal(t, len(trace1.StructLogs), len(trace2.StructLogs))
// TODO: compare other fields
for i, opcode := range trace1.StructLogs {
data1, err := json.Marshal(opcode)

View file

@ -218,6 +218,7 @@ func TestTraceCall(t *testing.T) {
config: nil,
expectErr: nil,
expect: &types.ExecutionResult{
L1Fee: (*hexutil.Big)(big.NewInt(0)),
Gas: params.TxGas,
Failed: false,
ReturnValue: "",
@ -235,6 +236,7 @@ func TestTraceCall(t *testing.T) {
config: nil,
expectErr: nil,
expect: &types.ExecutionResult{
L1Fee: (*hexutil.Big)(big.NewInt(0)),
Gas: params.TxGas,
Failed: false,
ReturnValue: "",
@ -264,6 +266,7 @@ func TestTraceCall(t *testing.T) {
config: nil,
expectErr: nil,
expect: &types.ExecutionResult{
L1Fee: (*hexutil.Big)(big.NewInt(0)),
Gas: params.TxGas,
Failed: false,
ReturnValue: "",
@ -281,6 +284,7 @@ func TestTraceCall(t *testing.T) {
config: nil,
expectErr: nil,
expect: &types.ExecutionResult{
L1Fee: (*hexutil.Big)(big.NewInt(0)),
Gas: params.TxGas,
Failed: false,
ReturnValue: "",
@ -334,6 +338,7 @@ func TestTraceTransaction(t *testing.T) {
t.Errorf("Failed to trace transaction %v", err)
}
if !reflect.DeepEqual(result, &types.ExecutionResult{
L1Fee: (*hexutil.Big)(big.NewInt(0)),
Gas: params.TxGas,
Failed: false,
ReturnValue: "",

View file

@ -24,7 +24,7 @@ import (
const (
VersionMajor = 4 // Major version component of the current release
VersionMinor = 1 // Minor version component of the current release
VersionPatch = 0 // Patch version component of the current release
VersionPatch = 1 // Patch version component of the current release
VersionMeta = "sepolia" // Version metadata to append to the version string
)