Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 1,915 Lines • ▼ Show 20 Lines | for (int i = 0; i < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; i++) { | ||||
if (state == THRESHOLD_LOCKED_IN || state == THRESHOLD_STARTED) { | if (state == THRESHOLD_LOCKED_IN || state == THRESHOLD_STARTED) { | ||||
nVersion |= VersionBitsMask(params, (Consensus::DeploymentPos)i); | nVersion |= VersionBitsMask(params, (Consensus::DeploymentPos)i); | ||||
} | } | ||||
} | } | ||||
return nVersion; | return nVersion; | ||||
} | } | ||||
/** | |||||
* Threshold condition checker that triggers when unknown versionbits are seen | |||||
* on the network. | |||||
*/ | |||||
class WarningBitsConditionChecker : public AbstractThresholdConditionChecker { | |||||
private: | |||||
int bit; | |||||
public: | |||||
WarningBitsConditionChecker(int bitIn) : bit(bitIn) {} | |||||
int64_t BeginTime(const Consensus::Params ¶ms) const override { | |||||
return 0; | |||||
} | |||||
int64_t EndTime(const Consensus::Params ¶ms) const override { | |||||
return std::numeric_limits<int64_t>::max(); | |||||
} | |||||
int Period(const Consensus::Params ¶ms) const override { | |||||
return params.nMinerConfirmationWindow; | |||||
} | |||||
int Threshold(const Consensus::Params ¶ms) const override { | |||||
return params.nRuleChangeActivationThreshold; | |||||
} | |||||
bool Condition(const CBlockIndex *pindex, | |||||
const Consensus::Params ¶ms) const override { | |||||
return ((pindex->nVersion & VERSIONBITS_TOP_MASK) == | |||||
VERSIONBITS_TOP_BITS) && | |||||
((pindex->nVersion >> bit) & 1) != 0 && | |||||
((ComputeBlockVersion(pindex->pprev, params) >> bit) & 1) == 0; | |||||
} | |||||
}; | |||||
// Protected by cs_main | |||||
static ThresholdConditionCache warningcache[VERSIONBITS_NUM_BITS]; | |||||
// Returns the script flags which should be checked for a given block | // Returns the script flags which should be checked for a given block | ||||
static uint32_t GetBlockScriptFlags(const Config &config, | static uint32_t GetBlockScriptFlags(const Config &config, | ||||
const CBlockIndex *pChainTip) { | const CBlockIndex *pChainTip) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
const Consensus::Params &consensusParams = | const Consensus::Params &consensusParams = | ||||
config.GetChainParams().GetConsensus(); | config.GetChainParams().GetConsensus(); | ||||
uint32_t flags = SCRIPT_VERIFY_NONE; | uint32_t flags = SCRIPT_VERIFY_NONE; | ||||
▲ Show 20 Lines • Show All 576 Lines • ▼ Show 20 Lines | static void UpdateTip(const Config &config, CBlockIndex *pindexNew) { | ||||
cvBlockChange.notify_all(); | cvBlockChange.notify_all(); | ||||
static bool fWarned = false; | static bool fWarned = false; | ||||
std::vector<std::string> warningMessages; | std::vector<std::string> warningMessages; | ||||
if (!IsInitialBlockDownload()) { | if (!IsInitialBlockDownload()) { | ||||
int nUpgraded = 0; | int nUpgraded = 0; | ||||
const CBlockIndex *pindex = chainActive.Tip(); | const CBlockIndex *pindex = chainActive.Tip(); | ||||
for (int bit = 0; bit < VERSIONBITS_NUM_BITS; bit++) { | |||||
WarningBitsConditionChecker checker(bit); | |||||
ThresholdState state = | |||||
checker.GetStateFor(pindex, consensusParams, warningcache[bit]); | |||||
if (state == THRESHOLD_ACTIVE || state == THRESHOLD_LOCKED_IN) { | |||||
if (state == THRESHOLD_ACTIVE) { | |||||
std::string strWarning = | |||||
strprintf(_("Warning: unknown new rules activated " | |||||
"(versionbit %i)"), | |||||
bit); | |||||
SetMiscWarning(strWarning); | |||||
if (!fWarned) { | |||||
AlertNotify(strWarning); | |||||
fWarned = true; | |||||
} | |||||
} else { | |||||
warningMessages.push_back( | |||||
strprintf("unknown new rules are about to activate " | |||||
"(versionbit %i)", | |||||
bit)); | |||||
} | |||||
} | |||||
} | |||||
// Check the version of the last 100 blocks to see if we need to | // Check the version of the last 100 blocks to see if we need to | ||||
// upgrade: | // upgrade: | ||||
for (int i = 0; i < 100 && pindex != nullptr; i++) { | for (int i = 0; i < 100 && pindex != nullptr; i++) { | ||||
int32_t nExpectedVersion = | int32_t nExpectedVersion = | ||||
ComputeBlockVersion(pindex->pprev, consensusParams); | ComputeBlockVersion(pindex->pprev, consensusParams); | ||||
if (pindex->nVersion > VERSIONBITS_LAST_OLD_BLOCK_VERSION && | if (pindex->nVersion > VERSIONBITS_LAST_OLD_BLOCK_VERSION && | ||||
(pindex->nVersion & ~nExpectedVersion) != 0) { | (pindex->nVersion & ~nExpectedVersion) != 0) { | ||||
++nUpgraded; | ++nUpgraded; | ||||
▲ Show 20 Lines • Show All 2,326 Lines • ▼ Show 20 Lines | void UnloadBlockIndex() { | ||||
mempool.clear(); | mempool.clear(); | ||||
mapBlocksUnlinked.clear(); | mapBlocksUnlinked.clear(); | ||||
vinfoBlockFile.clear(); | vinfoBlockFile.clear(); | ||||
nLastBlockFile = 0; | nLastBlockFile = 0; | ||||
nBlockSequenceId = 1; | nBlockSequenceId = 1; | ||||
setDirtyBlockIndex.clear(); | setDirtyBlockIndex.clear(); | ||||
setDirtyFileInfo.clear(); | setDirtyFileInfo.clear(); | ||||
versionbitscache.Clear(); | versionbitscache.Clear(); | ||||
for (int b = 0; b < VERSIONBITS_NUM_BITS; b++) { | |||||
warningcache[b].clear(); | |||||
} | |||||
for (BlockMap::value_type &entry : mapBlockIndex) { | for (BlockMap::value_type &entry : mapBlockIndex) { | ||||
delete entry.second; | delete entry.second; | ||||
} | } | ||||
mapBlockIndex.clear(); | mapBlockIndex.clear(); | ||||
fHavePruned = false; | fHavePruned = false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 705 Lines • Show Last 20 Lines |