blockstore: fix race conditions when loading data (#5382)

Fixes #5377 and comments in #4588 (review).
This commit is contained in:
Erik Grinaker
2020-09-23 08:13:43 +02:00
committed by GitHub
parent 3502901dd8
commit 58b4deca86
8 changed files with 67 additions and 16 deletions

View File

@@ -122,6 +122,7 @@ type mockBlockStore struct {
func (mockBlockStore) Base() int64 { return 1 }
func (store mockBlockStore) Height() int64 { return store.height }
func (store mockBlockStore) Size() int64 { return store.height }
func (mockBlockStore) LoadBaseMeta() *types.BlockMeta { return nil }
func (mockBlockStore) LoadBlockMeta(height int64) *types.BlockMeta { return nil }
func (mockBlockStore) LoadBlock(height int64) *types.Block { return nil }
func (mockBlockStore) LoadBlockByHash(hash []byte) *types.Block { return nil }

View File

@@ -15,14 +15,14 @@ import (
// More: https://docs.tendermint.com/master/rpc/#/Info/status
func Status(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) {
var (
earliestBlockHeight int64
earliestBlockHash tmbytes.HexBytes
earliestAppHash tmbytes.HexBytes
earliestBlockTimeNano int64
earliestBlockHeight = env.BlockStore.Base()
)
if earliestBlockMeta := env.BlockStore.LoadBlockMeta(earliestBlockHeight); earliestBlockMeta != nil {
if earliestBlockMeta := env.BlockStore.LoadBaseMeta(); earliestBlockMeta != nil {
earliestBlockHeight = earliestBlockMeta.Header.Height
earliestAppHash = earliestBlockMeta.Header.AppHash
earliestBlockHash = earliestBlockMeta.BlockID.Hash
earliestBlockTimeNano = earliestBlockMeta.Header.Time.UnixNano()
@@ -37,8 +37,7 @@ func Status(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) {
)
if latestHeight != 0 {
latestBlockMeta := env.BlockStore.LoadBlockMeta(latestHeight)
if latestBlockMeta != nil {
if latestBlockMeta := env.BlockStore.LoadBlockMeta(latestHeight); latestBlockMeta != nil {
latestBlockHash = latestBlockMeta.BlockID.Hash
latestAppHash = latestBlockMeta.Header.AppHash
latestBlockTimeNano = latestBlockMeta.Header.Time.UnixNano()