Skip to content

Commit

Permalink
Problem: wrong gas price when using basefee of minus one height when …
Browse files Browse the repository at this point in the history
…trace tx (#559)

* Problem: wrong gas price when using basefee of minus one height when trace tx

* add basefee req

---------

Signed-off-by: mmsqe <[email protected]>
  • Loading branch information
mmsqe authored Nov 12, 2024
1 parent 64bd2de commit 4fb45a3
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 102 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (rpc) [#545](https://github.com/crypto-org-chain/ethermint/pull/545) Fix state overwrite in debug trace APIs.
* (rpc) [#554](https://github.com/crypto-org-chain/ethermint/pull/554) No trace detail on insufficient balance.
* (rpc) [#558](https://github.com/crypto-org-chain/ethermint/pull/558) New tracer in predecessors to trace balance correctly when `debug_traceTransaction`.
* (rpc) [#559](https://github.com/crypto-org-chain/ethermint/pull/559) Use basefee of transaction height instead of minus one height when `debug_traceTransaction`.
* (ante) [#560](https://github.com/crypto-org-chain/ethermint/pull/560) Check gasWanted only in checkTx mode.

### Improvements
Expand Down
9 changes: 8 additions & 1 deletion client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3730,12 +3730,19 @@ paths:
format: byte
- name: chain_id
description: >-
chain_id is the the eip155 chain id parsed from the requested block
chain_id is the eip155 chain id parsed from the requested block
header.
in: query
required: false
type: string
format: int64
- name: base_fee
description: >-
base_fee is the base fee based on the block_number of requested
transaction.
in: query
required: false
type: string
tags:
- Query
/ethermint/evm/v1/validator_account/{cons_address}:
Expand Down
4 changes: 3 additions & 1 deletion proto/ethermint/evm/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,10 @@ message QueryTraceTxRequest {
google.protobuf.Timestamp block_time = 7 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
// proposer_address is the proposer of the requested block
bytes proposer_address = 8 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ConsAddress"];
// chain_id is the the eip155 chain id parsed from the requested block header
// chain_id is the eip155 chain id parsed from the requested block header
int64 chain_id = 9;
// base_fee is the base fee based on the block_number of requested transaction
string base_fee = 10 [(gogoproto.customtype) = "cosmossdk.io/math.Int"];
}

// QueryTraceTxResponse defines TraceTx response
Expand Down
7 changes: 7 additions & 0 deletions rpc/backend/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
rpctypes "github.com/evmos/ethermint/rpc/types"
ethermint "github.com/evmos/ethermint/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -117,6 +118,12 @@ func (b *Backend) TraceTransaction(hash common.Hash, config *rpctypes.TraceConfi
// 0 is a special value in `ContextWithHeight`
contextHeight = 1
}
// Get basefee from transaction height
res, err := b.queryClient.FeeMarket.Params(rpctypes.ContextWithHeight(transaction.Height), &feemarkettypes.QueryParamsRequest{})
if err != nil {
return nil, err
}
traceTxRequest.BaseFee = &res.Params.BaseFee
traceResult, err := b.queryClient.TraceTx(rpctypes.ContextWithHeight(contextHeight), &traceTxRequest)
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions rpc/backend/tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ func (suite *BackendTestSuite) TestTraceTransaction() {
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
client := suite.backend.clientCtx.Client.(*mocks.Client)
RegisterBlockMultipleTxs(client, 1, []types.Tx{txBz, txBz2})
feeMarketClient := suite.backend.queryClient.FeeMarket.(*mocks.FeeMarketQueryClient)
RegisterFeeMarketParams(feeMarketClient, 1)
RegisterTraceTransactionWithPredecessors(queryClient, msgEthereumTx, []*evmtypes.MsgEthereumTx{msgEthereumTx})
},
&types.Block{Header: types.Header{Height: 1, ChainID: ChainID}, Data: types.Data{Txs: []types.Tx{txBz, txBz2}}},
Expand Down Expand Up @@ -169,6 +171,8 @@ func (suite *BackendTestSuite) TestTraceTransaction() {
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
client := suite.backend.clientCtx.Client.(*mocks.Client)
RegisterBlock(client, 1, txBz)
feeMarketClient := suite.backend.queryClient.FeeMarket.(*mocks.FeeMarketQueryClient)
RegisterFeeMarketParams(feeMarketClient, 1)
RegisterTraceTransaction(queryClient, msgEthereumTx)
},
&types.Block{Header: types.Header{Height: 1}, Data: types.Data{Txs: []types.Tx{txBz}}},
Expand Down
11 changes: 11 additions & 0 deletions x/evm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ func execTrace[T traceRequest](
c context.Context,
req T,
k Keeper,
baseFee *big.Int,
msgCb func(
ctx sdk.Context,
cfg *EVMConfig,
Expand Down Expand Up @@ -459,6 +460,10 @@ func execTrace[T traceRequest](
return nil, status.Errorf(codes.Internal, "failed to load evm config: %s", err.Error())
}

if baseFee != nil {
cfg.BaseFee = baseFee
}

msg, err := msgCb(ctx, cfg, req.GetTraceConfig())
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
Expand All @@ -482,10 +487,15 @@ func execTrace[T traceRequest](
// executes the given message in the provided environment. The return value will
// be tracer dependent.
func (k Keeper) TraceTx(c context.Context, req *types.QueryTraceTxRequest) (*types.QueryTraceTxResponse, error) {
var baseFee *big.Int
if req != nil && req.BaseFee != nil {
baseFee = big.NewInt(req.BaseFee.Int64())
}
resultData, err := execTrace(
c,
req,
k,
baseFee,
func(ctx sdk.Context, cfg *EVMConfig, traceConfig *types.TraceConfig) (*core.Message, error) {
signer := ethtypes.MakeSigner(cfg.ChainConfig, big.NewInt(ctx.BlockHeight()))
tracer, err := newTacer(&logger.Config{}, cfg.TxConfig, traceConfig)
Expand Down Expand Up @@ -608,6 +618,7 @@ func (k Keeper) TraceCall(c context.Context, req *types.QueryTraceCallRequest) (
c,
req,
k,
nil,
func(ctx sdk.Context, cfg *EVMConfig, _ *types.TraceConfig) (*core.Message, error) {
var args types.TransactionArgs
err := json.Unmarshal(req.Args, &args)
Expand Down
1 change: 1 addition & 0 deletions x/evm/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type StakingKeeper interface {
// FeeMarketKeeper
type FeeMarketKeeper interface {
GetBaseFee(ctx sdk.Context) *big.Int
CalculateBaseFee(ctx sdk.Context) *big.Int
GetParams(ctx sdk.Context) feemarkettypes.Params
}

Expand Down
Loading

0 comments on commit 4fb45a3

Please sign in to comment.