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: unwrap context panic in BlockMaxGasFromConsensusParams #16

Merged
merged 3 commits into from
Nov 25, 2021
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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

- [tharsis#782](https://github.com/tharsis/ethermint/pull/782) web3 rpc api returns wrong block gas limit
- [tharsis#781](https://github.com/tharsis/ethermint/pull/781) fix empty transactions in getBlock
- [tharsis#781](https://github.com/tharsis/ethermint/pull/781) fix empty transactions in getBlock
- [crypto-org-chain/ethermint#15](https://github.com/crypto-org-chain/ethermint/pull/15) web3 rpc api returns wrong block gas limit
- [crypto-org-chain/ethermint#16](https://github.com/crypto-org-chain/ethermint/pull/16) fix unwrap context panic in BlockMaxGasFromConsensusParams

## [v0.7.2-cronos-2] - 2021-11-17

Expand Down
2 changes: 1 addition & 1 deletion rpc/ethereum/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (e *EVMBackend) EthBlockFromTendermint(

validatorAddr := common.BytesToAddress(addr)

gasLimit, err := types.BlockMaxGasFromConsensusParams(ctx, e.clientCtx)
gasLimit, err := types.BlockMaxGasFromConsensusParams(ctx, e.clientCtx, &block.Height)
if err != nil {
e.logger.Error("failed to query consensus params", "error", err.Error())
}
Expand Down
10 changes: 3 additions & 7 deletions rpc/ethereum/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"fmt"
"math/big"

sdk "github.com/cosmos/cosmos-sdk/types"

tmbytes "github.com/tendermint/tendermint/libs/bytes"
tmtypes "github.com/tendermint/tendermint/types"

Expand Down Expand Up @@ -130,11 +128,9 @@ func EthTransactionsFromTendermint(clientCtx client.Context, txs []tmtypes.Tx) (
return transactionHashes, gasUsed, nil
}

// BlockMaxGasFromConsensusParams returns the gas limit for the latest block from the chain consensus params.
func BlockMaxGasFromConsensusParams(goCtx context.Context, clientCtx client.Context) (int64, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
blockHeight := ctx.BlockHeight()
resConsParams, err := clientCtx.Client.ConsensusParams(goCtx, &blockHeight)
// BlockMaxGasFromConsensusParams returns the gas limit for the current block from the chain consensus params.
func BlockMaxGasFromConsensusParams(ctx context.Context, clientCtx client.Context, height *int64) (int64, error) {
resConsParams, err := clientCtx.Client.ConsensusParams(ctx, height)
if err != nil {
return int64(^uint32(0)), err
}
Expand Down