Browse Source

rpc: check nil blockmeta (#4320)

* rpc: check nil blockmeta

- fixes #4319

- check if block meta is nil

Signed-off-by: Marko Baricevic <marbar3778@yahoo.com>

* add changelog entry
pull/4323/head
Marko 5 years ago
committed by GitHub
parent
commit
b50cb26664
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions
  1. +2
    -0
      CHANGELOG_PENDING.md
  2. +7
    -1
      rpc/core/blocks.go

+ 2
- 0
CHANGELOG_PENDING.md View File

@ -21,4 +21,6 @@ program](https://hackerone.com/tendermint).
### BUG FIXES:
- [rpc] [#\4319] Check BlockMeta is not nil in Blocks & BlockByHash

+ 7
- 1
rpc/core/blocks.go View File

@ -76,8 +76,11 @@ func Block(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlock, error)
return nil, err
}
blockMeta := blockStore.LoadBlockMeta(height)
block := blockStore.LoadBlock(height)
blockMeta := blockStore.LoadBlockMeta(height)
if blockMeta == nil {
return &ctypes.ResultBlock{BlockID: types.BlockID{}, Block: block}, nil
}
return &ctypes.ResultBlock{BlockID: blockMeta.BlockID, Block: block}, nil
}
@ -88,6 +91,9 @@ func BlockByHash(ctx *rpctypes.Context, hash []byte) (*ctypes.ResultBlock, error
height := block.Height
blockMeta := blockStore.LoadBlockMeta(height)
if blockMeta == nil {
return &ctypes.ResultBlock{BlockID: types.BlockID{}, Block: block}, nil
}
return &ctypes.ResultBlock{BlockID: blockMeta.BlockID, Block: block}, nil
}


Loading…
Cancel
Save