From 78a05d3b9e36243297ed325e00111a7f4d83e0c6 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Thu, 4 Feb 2021 21:33:29 +0100 Subject: [PATCH] check block store base is non negative before sending block meta or commits (#6042) --- consensus/reactor.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/consensus/reactor.go b/consensus/reactor.go index b81b5eebb..9924d0bdf 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -520,7 +520,8 @@ OUTER_LOOP: } // If the peer is on a previous height that we have, help catch up. - if (0 < prs.Height) && (prs.Height < rs.Height) && (prs.Height >= conR.conS.blockStore.Base()) { + blockStoreBase := conR.conS.blockStore.Base() + if blockStoreBase > 0 && 0 < prs.Height && prs.Height < rs.Height && prs.Height >= blockStoreBase { heightLogger := logger.With("height", prs.Height) // if we never received the commit message from the peer, the block parts wont be initialized @@ -528,7 +529,7 @@ OUTER_LOOP: blockMeta := conR.conS.blockStore.LoadBlockMeta(prs.Height) if blockMeta == nil { heightLogger.Error("Failed to load block meta", - "blockstoreBase", conR.conS.blockStore.Base(), "blockstoreHeight", conR.conS.blockStore.Height()) + "blockstoreBase", blockStoreBase, "blockstoreHeight", conR.conS.blockStore.Height()) time.Sleep(conR.conS.config.PeerGossipSleepDuration) } else { ps.InitProposalBlockParts(blockMeta.BlockID.PartSetHeader) @@ -674,7 +675,8 @@ OUTER_LOOP: // Catchup logic // If peer is lagging by more than 1, send Commit. - if prs.Height != 0 && rs.Height >= prs.Height+2 && prs.Height >= conR.conS.blockStore.Base() { + blockStoreBase := conR.conS.blockStore.Base() + if blockStoreBase > 0 && prs.Height != 0 && rs.Height >= prs.Height+2 && prs.Height >= blockStoreBase { // Load the block commit for prs.Height, // which contains precommit signatures for prs.Height. if commit := conR.conS.blockStore.LoadBlockCommit(prs.Height); commit != nil {