Skip to content

Commit

Permalink
Problem: unwrap context panic in BlockMaxGasFromConsensusParams (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-nguy authored Nov 25, 2021
1 parent bf5cc3d commit 1237018
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
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

0 comments on commit 1237018

Please sign in to comment.