Pass CChainParams to DisconnectTip()

This commit is contained in:
face 2016-04-17 10:58:50 +03:00 committed by Jack Grigg
parent a68c8114e1
commit f2baeb7cb6
No known key found for this signature in database
GPG Key ID: 9E8255172BBF9898
3 changed files with 10 additions and 11 deletions

View File

@ -3019,14 +3019,13 @@ void static UpdateTip(CBlockIndex *pindexNew, const CChainParams& chainParams) {
* Disconnect chainActive's tip. You probably want to call mempool.removeForReorg and
* mempool.removeWithoutBranchId after this, with cs_main held.
*/
bool static DisconnectTip(CValidationState &state, const Consensus::Params& consensusParams, bool fBare = false)
bool static DisconnectTip(CValidationState &state, const CChainParams& chainparams, bool fBare = false)
{
const CChainParams& chainparams = Params(); // TODO replace consensusParams parameter
CBlockIndex *pindexDelete = chainActive.Tip();
assert(pindexDelete);
// Read block from disk.
CBlock block;
if (!ReadBlockFromDisk(block, pindexDelete, consensusParams))
if (!ReadBlockFromDisk(block, pindexDelete, chainparams.GetConsensus()))
return AbortNode(state, "Failed to read block");
// Apply the block atomically to the chain state.
uint256 sproutAnchorBeforeDisconnect = pcoinsTip->GetBestAnchor(SPROUT);
@ -3274,7 +3273,7 @@ static bool ActivateBestChainStep(CValidationState& state, const CChainParams& c
// Disconnect active blocks which are no longer in the best chain.
bool fBlocksDisconnected = false;
while (chainActive.Tip() && chainActive.Tip() != pindexFork) {
if (!DisconnectTip(state, chainparams.GetConsensus()))
if (!DisconnectTip(state, chainparams))
return false;
fBlocksDisconnected = true;
}
@ -3395,7 +3394,7 @@ bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams,
return true;
}
bool InvalidateBlock(CValidationState& state, const Consensus::Params& consensusParams, CBlockIndex *pindex)
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex *pindex)
{
AssertLockHeld(cs_main);
@ -3411,10 +3410,10 @@ bool InvalidateBlock(CValidationState& state, const Consensus::Params& consensus
setBlockIndexCandidates.erase(pindexWalk);
// ActivateBestChain considers blocks already in chainActive
// unconditionally valid already, so force disconnect away from it.
if (!DisconnectTip(state, consensusParams)) {
if (!DisconnectTip(state, chainparams)) {
mempool.removeForReorg(pcoinsTip, chainActive.Tip()->nHeight + 1, STANDARD_LOCKTIME_VERIFY_FLAGS);
mempool.removeWithoutBranchId(
CurrentEpochBranchId(chainActive.Tip()->nHeight + 1, consensusParams));
CurrentEpochBranchId(chainActive.Tip()->nHeight + 1, chainparams.GetConsensus()));
return false;
}
}
@ -3432,7 +3431,7 @@ bool InvalidateBlock(CValidationState& state, const Consensus::Params& consensus
InvalidChainFound(pindex);
mempool.removeForReorg(pcoinsTip, chainActive.Tip()->nHeight + 1, STANDARD_LOCKTIME_VERIFY_FLAGS);
mempool.removeWithoutBranchId(
CurrentEpochBranchId(chainActive.Tip()->nHeight + 1, consensusParams));
CurrentEpochBranchId(chainActive.Tip()->nHeight + 1, chainparams.GetConsensus()));
return true;
}
@ -4607,7 +4606,7 @@ bool RewindBlockIndex(const CChainParams& params, bool& clearWitnessCaches)
// of the blockchain).
break;
}
if (!DisconnectTip(state, params.GetConsensus(), true)) {
if (!DisconnectTip(state, params, true)) {
return error("RewindBlockIndex: unable to disconnect block at height %i", pindex->nHeight);
}
// Occasionally flush state to disk.

View File

@ -565,7 +565,7 @@ public:
CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& locator);
/** Mark a block as invalid. */
bool InvalidateBlock(CValidationState& state, const Consensus::Params& consensusParams, CBlockIndex *pindex);
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex *pindex);
/** Remove invalidity status from a block and its descendants. */
bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex);

View File

@ -976,7 +976,7 @@ UniValue invalidateblock(const UniValue& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
CBlockIndex* pblockindex = mapBlockIndex[hash];
InvalidateBlock(state, Params().GetConsensus(), pblockindex);
InvalidateBlock(state, Params(), pblockindex);
}
if (state.IsValid()) {