From 79657a8e3a90c318d1897d54be0eb4b53a45d2c4 Mon Sep 17 00:00:00 2001 From: therealyingtong Date: Thu, 14 May 2020 00:14:44 +0800 Subject: [PATCH] Fix off-by-one error in CreateNewBlock() When calling GetHistoryRoot, use prevConsensusBranchId instead of consensusBranchId for compatibility with NU4 and future upgrades. Co-authored by Jack Grigg (jack@electriccoin.co) --- src/miner.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 9134024f6..89f52175a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -518,12 +518,14 @@ CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const MinerAddre nonce >>= 16; pblock->nNonce = ArithToUint256(nonce); + uint32_t prevConsensusBranchId = CurrentEpochBranchId(pindexPrev->nHeight, chainparams.GetConsensus()); + // Fill in header pblock->hashPrevBlock = pindexPrev->GetBlockHash(); if (IsActivationHeight(nHeight, chainparams.GetConsensus(), Consensus::UPGRADE_HEARTWOOD)) { pblock->hashLightClientRoot.SetNull(); } else if (chainparams.GetConsensus().NetworkUpgradeActive(nHeight, Consensus::UPGRADE_HEARTWOOD)) { - pblock->hashLightClientRoot = view.GetHistoryRoot(consensusBranchId); + pblock->hashLightClientRoot = view.GetHistoryRoot(prevConsensusBranchId); } else { pblock->hashLightClientRoot = sapling_tree.root(); }