Skip to content

Commit

Permalink
fix: gas_price & eth_getBlockByNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
sheldon committed Sep 2, 2022
1 parent 55bdb6a commit 4a70d2f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
17 changes: 10 additions & 7 deletions rpc/ethereum/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ func (e *EVMBackend) EthBlockFromTendermint(
ConsAddress: sdk.ConsAddress(block.Header.ProposerAddress).String(),
}

var validatorAccAddr sdk.AccAddress

res, err := e.queryClient.ValidatorAccount(ctx, req)
if err != nil {
e.logger.Debug(
Expand All @@ -423,15 +425,16 @@ func (e *EVMBackend) EthBlockFromTendermint(
"cons-address", req.ConsAddress,
"error", err.Error(),
)
return nil, err
}

addr, err := sdk.AccAddressFromBech32(res.AccountAddress)
if err != nil {
return nil, err
// use zero address as the validator operator address
validatorAccAddr = sdk.AccAddress(common.Address{}.Bytes())
} else {
validatorAccAddr, err = sdk.AccAddressFromBech32(res.AccountAddress)
if err != nil {
return nil, err
}
}

validatorAddr := common.BytesToAddress(addr)
validatorAddr := common.BytesToAddress(validatorAccAddr)

gasLimit, err := types.BlockMaxGasFromConsensusParams(ctx, e.clientCtx, block.Height)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions rpc/ethereum/backend/feebackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ func (s sortGasAndReward) Swap(i, j int) {
}

func (s sortGasAndReward) Less(i, j int) bool {
// -1 if x < y
// 0 if x == y
// +1 if x > y
if s[i].reward == nil {
return true
}
if s[j].reward == nil {
return false
}
return s[i].reward.Cmp(s[j].reward) < 0
}

Expand Down
3 changes: 3 additions & 0 deletions rpc/ethereum/namespaces/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ func (e *PublicAPI) GasPrice() (*hexutil.Big, error) {
} else {
result = big.NewInt(e.backend.RPCMinGasPrice())
}
if result.Cmp(new(big.Int).SetUint64(0)) == 0 {
result = big.NewInt(e.backend.RPCMinGasPrice())
}

return (*hexutil.Big)(result), nil
}
Expand Down

0 comments on commit 4a70d2f

Please sign in to comment.