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

Problem: recent bug fixes are not included (backport: #558 #559) #561

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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (rpc) [#527](https://github.com/crypto-org-chain/ethermint/pull/527) Fix balance consistency between trace-block and state machine.
* (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`.

### 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 @@ -3684,12 +3684,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
14 changes: 14 additions & 0 deletions rpc/backend/evm_query_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strconv"
"testing"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
Expand All @@ -31,13 +32,26 @@ import (
var _ evmtypes.QueryClient = &mocks.EVMQueryClient{}

// TraceTransaction
func RegisterTraceTransactionWithPredecessorsAndBaseFee(queryClient *mocks.EVMQueryClient, msgEthTx *evmtypes.MsgEthereumTx, predecessors []*evmtypes.MsgEthereumTx, baseFee math.Int) {
data := []byte{0x7b, 0x22, 0x74, 0x65, 0x73, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x7d}
queryClient.On("TraceTx", rpc.ContextWithHeight(1),
&evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, Predecessors: predecessors, ChainId: 9000, BaseFee: &baseFee}).
Return(&evmtypes.QueryTraceTxResponse{Data: data}, nil)
}

func RegisterTraceTransactionWithPredecessors(queryClient *mocks.EVMQueryClient, msgEthTx *evmtypes.MsgEthereumTx, predecessors []*evmtypes.MsgEthereumTx) {
data := []byte{0x7b, 0x22, 0x74, 0x65, 0x73, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x7d}
queryClient.On("TraceTx", rpc.ContextWithHeight(1),
&evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, Predecessors: predecessors, ChainId: 9000}).
Return(&evmtypes.QueryTraceTxResponse{Data: data}, nil)
}

func RegisterTraceTransactionAndBaseFee(queryClient *mocks.EVMQueryClient, msgEthTx *evmtypes.MsgEthereumTx, baseFee math.Int) {
data := []byte{0x7b, 0x22, 0x74, 0x65, 0x73, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x7d}
queryClient.On("TraceTx", rpc.ContextWithHeight(1), &evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, ChainId: 9000, BaseFee: &baseFee}).
Return(&evmtypes.QueryTraceTxResponse{Data: data}, nil)
}

func RegisterTraceTransaction(queryClient *mocks.EVMQueryClient, msgEthTx *evmtypes.MsgEthereumTx) {
data := []byte{0x7b, 0x22, 0x74, 0x65, 0x73, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x7d}
queryClient.On("TraceTx", rpc.ContextWithHeight(1), &evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, ChainId: 9000}).
Expand Down
7 changes: 7 additions & 0 deletions rpc/backend/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"github.com/ethereum/go-ethereum/common/hexutil"
rpctypes "github.com/evmos/ethermint/rpc/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 @@ -113,6 +114,12 @@
// 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
}

Check warning on line 121 in rpc/backend/tracing.go

View check run for this annotation

Codecov / codecov/patch

rpc/backend/tracing.go#L120-L121

Added lines #L120 - L121 were not covered by tests
traceTxRequest.BaseFee = &res.Params.BaseFee
traceResult, err := b.queryClient.TraceTx(rpctypes.ContextWithHeight(contextHeight), &traceTxRequest)
if err != nil {
return nil, err
Expand Down
9 changes: 7 additions & 2 deletions rpc/backend/tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
rpctypes "github.com/evmos/ethermint/rpc/types"
"github.com/evmos/ethermint/tests"
evmtypes "github.com/evmos/ethermint/x/evm/types"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
)

func (suite *BackendTestSuite) TestTraceTransaction() {
Expand Down Expand Up @@ -114,7 +115,9 @@ 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})
RegisterTraceTransactionWithPredecessors(queryClient, msgEthereumTx, []*evmtypes.MsgEthereumTx{msgEthereumTx})
feeMarketClient := suite.backend.queryClient.FeeMarket.(*mocks.FeeMarketQueryClient)
RegisterFeeMarketParams(feeMarketClient, 1)
RegisterTraceTransactionWithPredecessorsAndBaseFee(queryClient, msgEthereumTx, []*evmtypes.MsgEthereumTx{msgEthereumTx}, feemarkettypes.DefaultParams().BaseFee)
},
&types.Block{Header: types.Header{Height: 1, ChainID: ChainID}, Data: types.Data{Txs: []types.Tx{txBz, txBz2}}},
[]*abci.ResponseDeliverTx{
Expand Down Expand Up @@ -154,7 +157,9 @@ func (suite *BackendTestSuite) TestTraceTransaction() {
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
client := suite.backend.clientCtx.Client.(*mocks.Client)
RegisterBlock(client, 1, txBz)
RegisterTraceTransaction(queryClient, msgEthereumTx)
feeMarketClient := suite.backend.queryClient.FeeMarket.(*mocks.FeeMarketQueryClient)
RegisterFeeMarketParams(feeMarketClient, 1)
RegisterTraceTransactionAndBaseFee(queryClient, msgEthereumTx, feemarkettypes.DefaultParams().BaseFee)
},
&types.Block{Header: types.Header{Height: 1}, Data: types.Data{Txs: []types.Tx{txBz}}},
[]*abci.ResponseDeliverTx{
Expand Down
8 changes: 4 additions & 4 deletions rpc/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@

// CheckTxFee is an internal function used to check whether the fee of
// the given transaction is _reasonable_(under the cap).
func CheckTxFee(gasPrice *big.Int, gas uint64, cap float64) error {
func CheckTxFee(gasPrice *big.Int, gas uint64, feeCap float64) error {

Check warning on line 259 in rpc/types/utils.go

View check run for this annotation

Codecov / codecov/patch

rpc/types/utils.go#L259

Added line #L259 was not covered by tests
// Short circuit if there is no cap for transaction fee at all.
if cap == 0 {
if feeCap == 0 {

Check warning on line 261 in rpc/types/utils.go

View check run for this annotation

Codecov / codecov/patch

rpc/types/utils.go#L261

Added line #L261 was not covered by tests
return nil
}
totalfee := new(big.Float).SetInt(new(big.Int).Mul(gasPrice, new(big.Int).SetUint64(gas)))
Expand All @@ -268,8 +268,8 @@
feeEth := new(big.Float).Quo(totalfee, oneToken)
// no need to check error from parsing
feeFloat, _ := feeEth.Float64()
if feeFloat > cap {
return fmt.Errorf("tx fee (%.2f ether) exceeds the configured cap (%.2f ether)", feeFloat, cap)
if feeFloat > feeCap {
return fmt.Errorf("tx fee (%.2f ether) exceeds the configured cap (%.2f ether)", feeFloat, feeCap)

Check warning on line 272 in rpc/types/utils.go

View check run for this annotation

Codecov / codecov/patch

rpc/types/utils.go#L271-L272

Added lines #L271 - L272 were not covered by tests
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions types/dynamic_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)

// HasDynamicFeeExtensionOption returns true if the tx implements the `ExtensionOptionDynamicFeeTx` extension option.
func HasDynamicFeeExtensionOption(any *codectypes.Any) bool {
_, ok := any.GetCachedValue().(*ExtensionOptionDynamicFeeTx)
func HasDynamicFeeExtensionOption(codecAny *codectypes.Any) bool {
_, ok := codecAny.GetCachedValue().(*ExtensionOptionDynamicFeeTx)

Check warning on line 24 in types/dynamic_fee.go

View check run for this annotation

Codecov / codecov/patch

types/dynamic_fee.go#L23-L24

Added lines #L23 - L24 were not covered by tests
return ok
}
70 changes: 48 additions & 22 deletions x/evm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

rpctypes "github.com/evmos/ethermint/rpc/types"
ethermint "github.com/evmos/ethermint/types"
"github.com/evmos/ethermint/x/evm/statedb"
"github.com/evmos/ethermint/x/evm/types"
)

Expand Down Expand Up @@ -413,9 +414,11 @@
c context.Context,
req T,
k Keeper,
baseFee *big.Int,
msgCb func(
ctx sdk.Context,
cfg *EVMConfig,
traceConfig *types.TraceConfig,
) (*core.Message, error),
) ([]byte, error) {
var zero T
Expand Down Expand Up @@ -448,7 +451,11 @@
return nil, status.Errorf(codes.Internal, "failed to load evm config: %s", err.Error())
}

msg, err := msgCb(ctx, cfg)
if baseFee != nil {
cfg.BaseFee = baseFee
}

Check warning on line 456 in x/evm/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/grpc_query.go#L455-L456

Added lines #L455 - L456 were not covered by tests

msg, err := msgCb(ctx, cfg, req.GetTraceConfig())
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
Expand All @@ -471,13 +478,23 @@
// 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())
}

Check warning on line 484 in x/evm/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/grpc_query.go#L483-L484

Added lines #L483 - L484 were not covered by tests
resultData, err := execTrace(
c,
req,
k,
func(ctx sdk.Context, cfg *EVMConfig) (*core.Message, error) {
baseFee,
func(ctx sdk.Context, cfg *EVMConfig, traceConfig *types.TraceConfig) (*core.Message, error) {
signer := ethtypes.MakeSigner(cfg.ChainConfig, big.NewInt(ctx.BlockHeight()))
cfg.Tracer = types.NewNoOpTracer()
tracer, err := newTacer(&logger.Config{}, cfg.TxConfig, traceConfig)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
cfg.Tracer = tracer
cfg.DebugTrace = true
for i, tx := range req.Predecessors {
ethTx := tx.AsTransaction()
msg, err := core.TransactionToMessage(ethTx, signer, cfg.BaseFee)
Expand Down Expand Up @@ -585,7 +602,8 @@
c,
req,
k,
func(ctx sdk.Context, cfg *EVMConfig) (*core.Message, error) {
nil,
func(ctx sdk.Context, cfg *EVMConfig, _ *types.TraceConfig) (*core.Message, error) {

Check warning on line 606 in x/evm/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/grpc_query.go#L605-L606

Added lines #L605 - L606 were not covered by tests
var args types.TransactionArgs
err := json.Unmarshal(req.Args, &args)
if err != nil {
Expand All @@ -612,6 +630,31 @@
}, nil
}

func newTacer(logConfig *logger.Config, txConfig statedb.TxConfig, traceConfig *types.TraceConfig) (tracers.Tracer, error) {
tracer := logger.NewStructLogger(logConfig)
if traceConfig != nil && traceConfig.Tracer != "" {
txIndex, err := ethermint.SafeInt(txConfig.TxIndex)
if err != nil {
return nil, err
}

Check warning on line 639 in x/evm/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/grpc_query.go#L638-L639

Added lines #L638 - L639 were not covered by tests
tCtx := &tracers.Context{
BlockHash: txConfig.BlockHash,
TxIndex: txIndex,
TxHash: txConfig.TxHash,
}
var cfg json.RawMessage
if traceConfig.TracerJsonConfig != "" {
cfg = json.RawMessage(traceConfig.TracerJsonConfig)
}

Check warning on line 648 in x/evm/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/grpc_query.go#L647-L648

Added lines #L647 - L648 were not covered by tests
tracer, err := tracers.DefaultDirectory.New(traceConfig.Tracer, tCtx, cfg)
if err != nil {
return nil, err
}
return tracer, nil
}
return tracer, nil
}

// prepareTrace prepare trace on one Ethereum message, it returns a tuple: (traceResult, nextLogIndex, error).
func (k *Keeper) prepareTrace(
ctx sdk.Context,
Expand Down Expand Up @@ -647,28 +690,11 @@
Overrides: overrides,
}

tracer = logger.NewStructLogger(&logConfig)

txIndex, err := ethermint.SafeInt(txConfig.TxIndex)
tracer, err = newTacer(&logConfig, txConfig, traceConfig)
if err != nil {
return nil, 0, status.Error(codes.Internal, err.Error())
}

tCtx := &tracers.Context{
BlockHash: txConfig.BlockHash,
TxIndex: txIndex,
TxHash: txConfig.TxHash,
}
if traceConfig.Tracer != "" {
var cfg json.RawMessage
if traceConfig.TracerJsonConfig != "" {
cfg = json.RawMessage(traceConfig.TracerJsonConfig)
}
if tracer, err = tracers.DefaultDirectory.New(traceConfig.Tracer, tCtx, cfg); err != nil {
return nil, 0, status.Error(codes.Internal, err.Error())
}
}

// Define a meaningful timeout of a single transaction trace
if traceConfig.Timeout != "" {
if timeout, err = time.ParseDuration(traceConfig.Timeout); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions x/evm/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@

// UnpackTxData unpacks an Any into a TxData. It returns an error if the
// client state can't be unpacked into a TxData.
func UnpackTxData(any *codectypes.Any) (TxData, error) {
if any == nil {
func UnpackTxData(codecAny *codectypes.Any) (TxData, error) {
if codecAny == nil {
return nil, errorsmod.Wrap(errortypes.ErrUnpackAny, "protobuf Any message cannot be nil")
}

txData, ok := any.GetCachedValue().(TxData)
txData, ok := codecAny.GetCachedValue().(TxData)
if !ok {
return nil, errorsmod.Wrapf(errortypes.ErrUnpackAny, "cannot unpack Any into TxData %T", any)
return nil, errorsmod.Wrapf(errortypes.ErrUnpackAny, "cannot unpack Any into TxData %T", codecAny)

Check warning on line 102 in x/evm/types/codec.go

View check run for this annotation

Codecov / codecov/patch

x/evm/types/codec.go#L102

Added line #L102 was not covered by tests
}

return txData, nil
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 @@ -62,6 +62,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
AddTransientGasWanted(ctx sdk.Context, gasWanted uint64) (uint64, error)
}
Expand Down
Loading
Loading