Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.

Commit c2b10c4

Browse files
danburckcrypto-facsfedekunze
authored
release: v0.14.1 changelog and backport (#1183)
* fix(rpc): optimize `eth_getBalance` endpoint (#1169) * optimize get balance endpoint * add comment * add changelog Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * add backport changes Co-authored-by: crypto-facs <84574577+crypto-facs@users.noreply.github.com> Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
1 parent 179c404 commit c2b10c4

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ Ref: https://keepachangelog.com/en/1.0.0/
3636

3737
# Changelog
3838

39+
## [v0.14.1] - 2022-07-13
40+
41+
### Improvements
42+
43+
* (rpc) [\#1169](https://github.com/evmos/ethermint/pull/1169) Remove unnecessary queries from `getBlockNumber` function
44+
3945
## [v0.14.0] - 2022-04-19
4046

4147
### API Breaking

rpc/ethereum/backend/backend.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type Backend interface {
6262
BlockByHash(blockHash common.Hash) (*ethtypes.Block, error)
6363
CurrentHeader() *ethtypes.Header
6464
HeaderByNumber(blockNum types.BlockNumber) (*ethtypes.Header, error)
65+
GetBlockNumberByHash(blockHash common.Hash) (*big.Int, error)
6566
HeaderByHash(blockHash common.Hash) (*ethtypes.Header, error)
6667
PendingTransactions() ([]*sdk.Tx, error)
6768
GetTransactionCount(address common.Address, blockNum types.BlockNumber) (*hexutil.Uint64, error)
@@ -508,6 +509,18 @@ func (e *EVMBackend) HeaderByNumber(blockNum types.BlockNumber) (*ethtypes.Heade
508509
return ethHeader, nil
509510
}
510511

512+
// GetBlockNumberByHash returns the block height of given block hash
513+
func (e *EVMBackend) GetBlockNumberByHash(blockHash common.Hash) (*big.Int, error) {
514+
resBlock, err := e.GetTendermintBlockByHash(blockHash)
515+
if err != nil {
516+
return nil, err
517+
}
518+
if resBlock == nil {
519+
return nil, errors.Errorf("block not found for hash %s", blockHash.Hex())
520+
}
521+
return big.NewInt(resBlock.Block.Height), nil
522+
}
523+
511524
// HeaderByHash returns the block header identified by hash.
512525
func (e *EVMBackend) HeaderByHash(blockHash common.Hash) (*ethtypes.Header, error) {
513526
resBlock, err := e.clientCtx.Client.BlockByHash(e.ctx, blockHash.Bytes())

rpc/ethereum/namespaces/eth/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,11 +1102,11 @@ func (e *PublicAPI) getBlockNumber(blockNrOrHash rpctypes.BlockNumberOrHash) (rp
11021102
case blockNrOrHash.BlockHash == nil && blockNrOrHash.BlockNumber == nil:
11031103
return rpctypes.EthEarliestBlockNumber, fmt.Errorf("types BlockHash and BlockNumber cannot be both nil")
11041104
case blockNrOrHash.BlockHash != nil:
1105-
blockHeader, err := e.backend.HeaderByHash(*blockNrOrHash.BlockHash)
1105+
blockNumber, err := e.backend.GetBlockNumberByHash(*blockNrOrHash.BlockHash)
11061106
if err != nil {
11071107
return rpctypes.EthEarliestBlockNumber, err
11081108
}
1109-
return rpctypes.NewBlockNumber(blockHeader.Number), nil
1109+
return rpctypes.NewBlockNumber(blockNumber), nil
11101110
case blockNrOrHash.BlockNumber != nil:
11111111
return *blockNrOrHash.BlockNumber, nil
11121112
default:

0 commit comments

Comments
 (0)