From 27b2ce34683bccee0ac9437a2df4ce7f3865a174 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 7 May 2020 22:06:05 +1200 Subject: [PATCH] Use the cached consensusBranchId in DisconnectBlock If a node is started with a set of network upgrades that don't match the serialized chain (such as when we implement NU rollbacks on testnet), RewindBlockIndex will disconnect each block in the chain until it reaches the most recent block that agrees with the node's set of network upgrades. However, the blocks themselves should be disconnected using the consensus branch ID that they were connected with, which is persisted alongside the chain and reconstructed in LoadBlockIndex. --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 9b50482d6..f97755e58 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2461,7 +2461,9 @@ static DisconnectResult DisconnectBlock(const CBlock& block, CValidationState& s view.PopAnchor(SaplingMerkleTree::empty_root(), SAPLING); } - auto consensusBranchId = CurrentEpochBranchId(pindex->nHeight, chainparams.GetConsensus()); + // This is guaranteed to be filled by LoadBlockIndex. + assert(pindex->nCachedBranchId); + auto consensusBranchId = pindex->nCachedBranchId.get(); if (chainparams.GetConsensus().NetworkUpgradeActive(pindex->nHeight, Consensus::UPGRADE_HEARTWOOD)) { view.PopHistoryNode(consensusBranchId);