From f1a4dfb86dc79098d04b88dceec46353fd27007b Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Thu, 20 Mar 2014 14:08:46 -0500 Subject: [PATCH] Update chain state with best block. Rather than updating the new chain state with the hash and height of the block that was just processed, query the database for the best block. This is needed because the block that was just processed might be a side chain block or have caused a reorg. --- blockmanager.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/blockmanager.go b/blockmanager.go index 57cae6cd..bcadd2fe 100644 --- a/blockmanager.go +++ b/blockmanager.go @@ -548,7 +548,12 @@ func (b *blockManager) handleBlockMsg(bmsg *blockMsg) { if !b.blockChain.IsKnownOrphan(blockSha) { delete(b.blockPeer, *blockSha) b.logBlockHeight(bmsg.block) - b.updateChainState(blockSha, bmsg.block.Height()) + + // Query the db for the latest best block since the block + // that was processed could be on a side chain or have caused + // a reorg. + newestSha, newestHeight, _ := b.server.db.NewestSha() + b.updateChainState(newestSha, newestHeight) } // Sync the db to disk.