Skip to content

Commit

Permalink
Remove global fDIP0003ActiveAtTip and fix wrong use of VersionBitsSta…
Browse files Browse the repository at this point in the history
…te in auto IX (#2380)

* Remove global fDIP0003ActiveAtTip flag and always use VersionBitsState

fDIP0003ActiveAtTip was used much more often when introduced but turned out
to be not very useful in most places. Always use VersionBitsState now.

* Fix wrong use of VersionBitsState auto IX

* Make sure isAutoLockBip9Active flag is reset in case of chain reorgs
  • Loading branch information
codablock authored Oct 26, 2018
1 parent 25b6dae commit 733cd95
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/dsnotificationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, con

// Update global DIP0001 activation status
fDIP0001ActiveAtTip = pindexNew->nHeight >= Params().GetConsensus().DIP0001Height;
fDIP0003ActiveAtTip = (VersionBitsState(pindexNew->pprev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0003, versionbitscache) == THRESHOLD_ACTIVE);
// update instantsend autolock activation flag
instantsend.isAutoLockBip9Active =
(VersionBitsState(pindexNew->pprev, Params().GetConsensus(), Consensus::DEPLOYMENT_ISAUTOLOCKS, versionbitscache) == THRESHOLD_ACTIVE);
(VersionBitsState(pindexNew, Params().GetConsensus(), Consensus::DEPLOYMENT_ISAUTOLOCKS, versionbitscache) == THRESHOLD_ACTIVE);

if (fInitialDownload)
return;
Expand Down
15 changes: 9 additions & 6 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,15 @@ void ThreadImport(std::vector<boost::filesystem::path> vImportFiles)
// GetMainSignals().UpdatedBlockTip(chainActive.Tip());
pdsNotificationInterface->InitializeCurrentBlockTip();

if (activeMasternodeManager && fDIP0003ActiveAtTip)
bool fDIP003Active;
{
LOCK(cs_main);
if (chainActive.Tip()->pprev) {
fDIP003Active = VersionBitsState(chainActive.Tip()->pprev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0003, versionbitscache) == THRESHOLD_ACTIVE;
}
}

if (activeMasternodeManager && fDIP003Active)
activeMasternodeManager->Init();

#ifdef ENABLE_WALLET
Expand Down Expand Up @@ -1760,11 +1768,6 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
break;
}

// Needs to be called after chain is initialized
if (chainActive.Tip() && chainActive.Tip()->pprev) {
fDIP0003ActiveAtTip = VersionBitsState(chainActive.Tip()->pprev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0003, versionbitscache) == THRESHOLD_ACTIVE;
}

uiInterface.InitMessage(_("Verifying blocks..."));
if (fHavePruned && GetArg("-checkblocks", DEFAULT_CHECKBLOCKS) > MIN_BLOCKS_TO_KEEP) {
LogPrintf("Prune: pruned datadir may not have more than %d blocks; only checking available blocks",
Expand Down
22 changes: 12 additions & 10 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1740,10 +1740,6 @@ static DisconnectResult DisconnectBlock(const CBlock& block, CValidationState& s
}
}

if (pindex->pprev && pindex->pprev->pprev && VersionBitsState(pindex->pprev->pprev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0003, versionbitscache) != THRESHOLD_ACTIVE) {
fDIP0003ActiveAtTip = false;
}

// move best block pointer to prevout block
view.SetBestBlock(pindex->pprev->GetBlockHash());

Expand All @@ -1758,6 +1754,10 @@ static DisconnectResult DisconnectBlock(const CBlock& block, CValidationState& s
}
}

// make sure the flag is reset in case of a chain reorg
instantsend.isAutoLockBip9Active =
(VersionBitsState(pindex->pprev, Params().GetConsensus(), Consensus::DEPLOYMENT_ISAUTOLOCKS, versionbitscache) == THRESHOLD_ACTIVE);

return fClean ? DISCONNECT_OK : DISCONNECT_UNCLEAN;
}

Expand Down Expand Up @@ -2011,12 +2011,6 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
flags |= SCRIPT_VERIFY_NULLDUMMY;
}

if (!fJustCheck && VersionBitsState(pindex->pprev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_DIP0003, versionbitscache) == THRESHOLD_ACTIVE) {
if (!fDIP0003ActiveAtTip)
LogPrintf("ConnectBlock -- DIP0003 got activated at height %d\n", pindex->nHeight);
fDIP0003ActiveAtTip = true;
}

int64_t nTime2 = GetTimeMicros(); nTimeForks += nTime2 - nTime1;
LogPrint("bench", " - Fork checks: %.2fms [%.2fs]\n", 0.001 * (nTime2 - nTime1), nTimeForks * 0.000001);

Expand Down Expand Up @@ -2250,6 +2244,14 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
// add this block to the view's block chain
view.SetBestBlock(pindex->GetBlockHash());

if (!fJustCheck) {
// check if previous block had DIP3 disabled and the new block has it enabled
if (VersionBitsState(pindex->pprev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_DIP0003, versionbitscache) != THRESHOLD_ACTIVE &&
VersionBitsState(pindex, chainparams.GetConsensus(), Consensus::DEPLOYMENT_DIP0003, versionbitscache) == THRESHOLD_ACTIVE) {
LogPrintf("%s -- DIP0003 got activated at height %d\n", __func__, pindex->nHeight);
}
}

int64_t nTime5 = GetTimeMicros(); nTimeIndex += nTime5 - nTime4;
LogPrint("bench", " - Index writing: %.2fms [%.2fs]\n", 0.001 * (nTime5 - nTime4), nTimeIndex * 0.000001);

Expand Down
2 changes: 0 additions & 2 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ extern bool fLargeWorkInvalidChainFound;
extern std::map<uint256, int64_t> mapRejectedBlocks;

extern std::atomic<bool> fDIP0001ActiveAtTip;
extern std::atomic<bool> fDIP0003ActiveAtTip;


/** Block hash whose ancestors we will assume to have valid scripts without checking them. */
extern uint256 hashAssumeValid;
Expand Down

0 comments on commit 733cd95

Please sign in to comment.