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

rpc: fix panic #611

Merged
merged 3 commits into from
Oct 1, 2021
Merged
Changes from 1 commit
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
16 changes: 11 additions & 5 deletions ethereum/rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ func (e *EVMBackend) GetBlockByNumber(blockNum types.BlockNumber, fullTx bool) (
return nil, err
}

// return if requested block height is greater than the current one
if resBlock == nil || resBlock.Block == nil {
return nil, nil
}

res, err := e.EthBlockFromTendermint(resBlock.Block, fullTx)
if err != nil {
e.logger.Debug("EthBlockFromTendermint failed", "height", blockNum, "error", err.Error())
Expand Down Expand Up @@ -172,18 +177,18 @@ func (e *EVMBackend) GetTendermintBlockByNumber(blockNum types.BlockNumber) (*tm
height = 1
default:
if blockNum < 0 {
err := errors.Errorf("incorrect block height: %d", height)
return nil, err
} else if height > int64(currentBlockNumber) {
return nil, errors.Errorf("cannot fetch a negative block height: %d", height)
}
if height > int64(currentBlockNumber) {
// TODO: should we set height = int64(currentBlockNumber) ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done a quick check and it seems that infura would return an empty response so current behavior is fine

return nil, nil
}
}

resBlock, err := e.clientCtx.Client.Block(e.ctx, &height)
if err != nil {
// e.logger.Debug("GetBlockByNumber safely bumping down from %d to latest", height)
if resBlock, err = e.clientCtx.Client.Block(e.ctx, nil); err != nil {
e.logger.Debug("GetBlockByNumber failed to get latest block", "error", err.Error())
e.logger.Debug("tendermint client failed to get latest block", "height", height, "error", err.Error())
return nil, nil
}
}
Expand All @@ -192,6 +197,7 @@ func (e *EVMBackend) GetTendermintBlockByNumber(blockNum types.BlockNumber) (*tm
e.logger.Debug("GetBlockByNumber block not found", "height", height)
return nil, nil
}

return resBlock, nil
}

Expand Down