From 6a7acc29a166a8278dfa84dfc3f6b78729221903 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Mon, 17 Oct 2016 11:09:24 -0500 Subject: [PATCH] Set CBlockIndex.hashAnchor correctly in ConnectBlock --- src/main.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9cf6db490..2b09a50d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2033,8 +2033,12 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin // Special case for the genesis block, skipping connection of its transactions // (its coinbase is unspendable) if (block.GetHash() == chainparams.GetConsensus().hashGenesisBlock) { - if (!fJustCheck) + if (!fJustCheck) { view.SetBestBlock(pindex->GetBlockHash()); + // Before the genesis block, there was an empty tree + ZCIncrementalMerkleTree tree; + pindex->hashAnchor = tree.root(); + } return true; } @@ -2080,7 +2084,9 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin // block position, auto old_tree_root = view.GetBestAnchor(); // saving the top anchor in the block index as we go. - pindex->hashAnchor = old_tree_root; + if (!fJustCheck) { + pindex->hashAnchor = old_tree_root; + } ZCIncrementalMerkleTree tree; // This should never fail: we should always be able to get the root // that is on the tip of our chain