Skip to content

Commit

Permalink
add basefee req
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Nov 12, 2024
1 parent 61ef077 commit f4812d2
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 121 deletions.
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
4 changes: 2 additions & 2 deletions rpc/backend/evm_query_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var _ evmtypes.QueryClient = &mocks.EVMQueryClient{}
// TraceTransaction
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.ContextWithBaseFee(rpc.ContextWithHeight(1), "1000000000"),
queryClient.On("TraceTx", rpc.ContextWithHeight(1),
mock.MatchedBy(func(req *evmtypes.QueryTraceTxRequest) bool {
if req.BlockNumber != 1 {
return false
Expand Down Expand Up @@ -63,7 +63,7 @@ func RegisterTraceTransactionWithPredecessors(queryClient *mocks.EVMQueryClient,

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.ContextWithBaseFee(rpc.ContextWithHeight(1), "1000000000"),
queryClient.On("TraceTx", rpc.ContextWithHeight(1),
mock.MatchedBy(func(req *evmtypes.QueryTraceTxRequest) bool {
if req.BlockNumber != 1 {
return false
Expand Down
4 changes: 2 additions & 2 deletions rpc/backend/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ func (b *Backend) TraceTransaction(hash common.Hash, config *rpctypes.TraceConfi
if err != nil {
return nil, err
}

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

View check run for this annotation

Codecov / codecov/patch

rpc/backend/tracing.go#L124-L125

Added lines #L124 - L125 were not covered by tests
ctx := rpctypes.ContextWithBaseFee(rpctypes.ContextWithHeight(contextHeight), res.Params.BaseFee.String())
traceResult, err := b.queryClient.TraceTx(ctx, &traceTxRequest)
traceTxRequest.BaseFee = &res.Params.BaseFee
traceResult, err := b.queryClient.TraceTx(rpctypes.ContextWithHeight(contextHeight), &traceTxRequest)
if err != nil {
return nil, err
}
Expand Down
7 changes: 0 additions & 7 deletions rpc/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ const (
BlockParamPending = "pending"
)

const GRPCBaseFeeHeader = "x-cosmos-basefee"

// NewBlockNumber creates a new BlockNumber instance.
func NewBlockNumber(n *big.Int) BlockNumber {
if !n.IsInt64() {
Expand All @@ -74,11 +72,6 @@ func ContextWithHeight(height int64) context.Context {
return metadata.AppendToOutgoingContext(context.Background(), grpctypes.GRPCBlockHeightHeader, fmt.Sprintf("%d", height))
}

// ContextWithBaseFee wraps a context with a gRPC basefee header.
func ContextWithBaseFee(c context.Context, fee string) context.Context {
return metadata.AppendToOutgoingContext(c, GRPCBaseFeeHeader, fee)
}

// UnmarshalJSON parses the given JSON fragment into a BlockNumber. It supports:
// - "latest", "finalized", "earliest" or "pending" as string arguments
// - the block number
Expand Down
17 changes: 9 additions & 8 deletions x/evm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import (
ethermint "github.com/evmos/ethermint/types"
"github.com/evmos/ethermint/x/evm/statedb"
"github.com/evmos/ethermint/x/evm/types"
"google.golang.org/grpc/metadata"
)

var _ types.QueryServer = Keeper{}
Expand Down Expand Up @@ -423,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 @@ -460,13 +460,8 @@ func execTrace[T traceRequest](
return nil, status.Errorf(codes.Internal, "failed to load evm config: %s", err.Error())
}

// Get basefee from the request context, if present.
if md, ok := metadata.FromIncomingContext(c); ok {
if headers := md.Get(rpctypes.GRPCBaseFeeHeader); len(headers) == 1 {
if basefee, ok := new(big.Int).SetString(headers[0], 10); ok {
cfg.BaseFee = basefee
}
}
if baseFee != nil {
cfg.BaseFee = baseFee
}

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

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/grpc_query.go#L464-L465

Added lines #L464 - L465 were not covered by tests

msg, err := msgCb(ctx, cfg, req.GetTraceConfig())
Expand All @@ -492,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())
}

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

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/grpc_query.go#L492-L493

Added lines #L492 - L493 were not covered by tests
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 @@ -618,6 +618,7 @@ func (k Keeper) TraceCall(c context.Context, req *types.QueryTraceCallRequest) (
c,
req,
k,
nil,

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

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/grpc_query.go#L621

Added line #L621 was not covered by tests
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 f4812d2

Please sign in to comment.