From 621de7bd376a7f76b191829a7760c3045f344e7c Mon Sep 17 00:00:00 2001 From: Calvin Kim Date: Tue, 7 Jan 2025 14:02:50 +0900 Subject: [PATCH] blockchain: change HaveBlock behavior Since ProcessBlockHeader will add the block header as a blockNode to the blockIndex, the HaveBlock function will incorrectly state that the block exists when only the header exists. Because of this, we check that the node exists and also check the node's status to see if the data is stored. --- blockchain/blockindex.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blockchain/blockindex.go b/blockchain/blockindex.go index b9e8704d..834beb54 100644 --- a/blockchain/blockindex.go +++ b/blockchain/blockindex.go @@ -316,9 +316,9 @@ func newBlockIndex(db database.DB, chainParams *chaincfg.Params) *blockIndex { // This function is safe for concurrent access. func (bi *blockIndex) HaveBlock(hash *chainhash.Hash) bool { bi.RLock() - _, hasBlock := bi.index[*hash] + node, hasBlock := bi.index[*hash] bi.RUnlock() - return hasBlock + return hasBlock && node.status.HaveData() } // LookupNode returns the block node identified by the provided hash. It will