mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-02 03:31:35 +02:00
Merge #10742: scripted-diff: Use scoped enumerations (C++11, "enum class")
1f45e21
scripted-diff: Convert 11 enums into scoped enums (C++11) (practicalswift)
Pull request description:
Rationale (from Bjarne Stroustrup's ["C++11 FAQ"](http://www.stroustrup.com/C++11FAQ.html#enum)):
>
> The enum classes ("new enums", "strong enums") address three problems with traditional C++ enumerations:
>
> * conventional enums implicitly convert to int, causing errors when someone does not want an enumeration to act as an integer.
> * conventional enums export their enumerators to the surrounding scope, causing name clashes.
> * the underlying type of an enum cannot be specified, causing confusion, compatibility problems, and makes forward declaration impossible.
>
> The new enums are "enum class" because they combine aspects of traditional enumerations (names values) with aspects of classes (scoped members and absence of conversions).
Tree-SHA512: 9656e1cf4c3cabd4378c7a38d0c2eaf79e4a54d204a3c5762330840e55ee7e141e188a3efb2b4daf0ef3110bbaff80d8b9253abf2a9b015cdc4d60b49ac2b914
This commit is contained in:
@ -280,11 +280,11 @@ std::unique_ptr<CCoinsViewDB> pcoinsdbview;
|
||||
std::unique_ptr<CCoinsViewCache> pcoinsTip;
|
||||
std::unique_ptr<CBlockTreeDB> pblocktree;
|
||||
|
||||
enum FlushStateMode {
|
||||
FLUSH_STATE_NONE,
|
||||
FLUSH_STATE_IF_NEEDED,
|
||||
FLUSH_STATE_PERIODIC,
|
||||
FLUSH_STATE_ALWAYS
|
||||
enum class FlushStateMode {
|
||||
NONE,
|
||||
IF_NEEDED,
|
||||
PERIODIC,
|
||||
ALWAYS
|
||||
};
|
||||
|
||||
// See definition for documentation
|
||||
@ -983,7 +983,7 @@ static bool AcceptToMemoryPoolWithTime(const CChainParams& chainparams, CTxMemPo
|
||||
}
|
||||
// After we've (potentially) uncached entries, ensure our coins cache is still within its size limits
|
||||
CValidationState stateDummy;
|
||||
FlushStateToDisk(chainparams, stateDummy, FLUSH_STATE_PERIODIC);
|
||||
FlushStateToDisk(chainparams, stateDummy, FlushStateMode::PERIODIC);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -1684,7 +1684,7 @@ int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Para
|
||||
|
||||
for (int i = 0; i < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; i++) {
|
||||
ThresholdState state = VersionBitsState(pindexPrev, params, static_cast<Consensus::DeploymentPos>(i), versionbitscache);
|
||||
if (state == THRESHOLD_LOCKED_IN || state == THRESHOLD_STARTED) {
|
||||
if (state == ThresholdState::LOCKED_IN || state == ThresholdState::STARTED) {
|
||||
nVersion |= VersionBitsMask(params, static_cast<Consensus::DeploymentPos>(i));
|
||||
}
|
||||
}
|
||||
@ -1740,7 +1740,7 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens
|
||||
}
|
||||
|
||||
// Start enforcing BIP68 (sequence locks) and BIP112 (CHECKSEQUENCEVERIFY) using versionbits logic.
|
||||
if (VersionBitsState(pindex->pprev, consensusparams, Consensus::DEPLOYMENT_CSV, versionbitscache) == THRESHOLD_ACTIVE) {
|
||||
if (VersionBitsState(pindex->pprev, consensusparams, Consensus::DEPLOYMENT_CSV, versionbitscache) == ThresholdState::ACTIVE) {
|
||||
flags |= SCRIPT_VERIFY_CHECKSEQUENCEVERIFY;
|
||||
}
|
||||
|
||||
@ -1926,7 +1926,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
||||
|
||||
// Start enforcing BIP68 (sequence locks) and BIP112 (CHECKSEQUENCEVERIFY) using versionbits logic.
|
||||
int nLockTimeFlags = 0;
|
||||
if (VersionBitsState(pindex->pprev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_CSV, versionbitscache) == THRESHOLD_ACTIVE) {
|
||||
if (VersionBitsState(pindex->pprev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_CSV, versionbitscache) == ThresholdState::ACTIVE) {
|
||||
nLockTimeFlags |= LOCKTIME_VERIFY_SEQUENCE;
|
||||
}
|
||||
|
||||
@ -2096,15 +2096,15 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &
|
||||
int64_t cacheSize = pcoinsTip->DynamicMemoryUsage();
|
||||
int64_t nTotalSpace = nCoinCacheUsage + std::max<int64_t>(nMempoolSizeMax - nMempoolUsage, 0);
|
||||
// The cache is large and we're within 10% and 10 MiB of the limit, but we have time now (not in the middle of a block processing).
|
||||
bool fCacheLarge = mode == FLUSH_STATE_PERIODIC && cacheSize > std::max((9 * nTotalSpace) / 10, nTotalSpace - MAX_BLOCK_COINSDB_USAGE * 1024 * 1024);
|
||||
bool fCacheLarge = mode == FlushStateMode::PERIODIC && cacheSize > std::max((9 * nTotalSpace) / 10, nTotalSpace - MAX_BLOCK_COINSDB_USAGE * 1024 * 1024);
|
||||
// The cache is over the limit, we have to write now.
|
||||
bool fCacheCritical = mode == FLUSH_STATE_IF_NEEDED && cacheSize > nTotalSpace;
|
||||
bool fCacheCritical = mode == FlushStateMode::IF_NEEDED && cacheSize > nTotalSpace;
|
||||
// It's been a while since we wrote the block index to disk. Do this frequently, so we don't need to redownload after a crash.
|
||||
bool fPeriodicWrite = mode == FLUSH_STATE_PERIODIC && nNow > nLastWrite + (int64_t)DATABASE_WRITE_INTERVAL * 1000000;
|
||||
bool fPeriodicWrite = mode == FlushStateMode::PERIODIC && nNow > nLastWrite + (int64_t)DATABASE_WRITE_INTERVAL * 1000000;
|
||||
// It's been very long since we flushed the cache. Do this infrequently, to optimize cache usage.
|
||||
bool fPeriodicFlush = mode == FLUSH_STATE_PERIODIC && nNow > nLastFlush + (int64_t)DATABASE_FLUSH_INTERVAL * 1000000;
|
||||
bool fPeriodicFlush = mode == FlushStateMode::PERIODIC && nNow > nLastFlush + (int64_t)DATABASE_FLUSH_INTERVAL * 1000000;
|
||||
// Combine all conditions that result in a full cache flush.
|
||||
fDoFullFlush = (mode == FLUSH_STATE_ALWAYS) || fCacheLarge || fCacheCritical || fPeriodicFlush || fFlushForPrune;
|
||||
fDoFullFlush = (mode == FlushStateMode::ALWAYS) || fCacheLarge || fCacheCritical || fPeriodicFlush || fFlushForPrune;
|
||||
// Write blocks and block index to disk.
|
||||
if (fDoFullFlush || fPeriodicWrite) {
|
||||
// Depend on nMinDiskSpace to ensure we can write block index
|
||||
@ -2150,7 +2150,7 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &
|
||||
nLastFlush = nNow;
|
||||
}
|
||||
}
|
||||
if (fDoFullFlush || ((mode == FLUSH_STATE_ALWAYS || mode == FLUSH_STATE_PERIODIC) && nNow > nLastSetChain + (int64_t)DATABASE_WRITE_INTERVAL * 1000000)) {
|
||||
if (fDoFullFlush || ((mode == FlushStateMode::ALWAYS || mode == FlushStateMode::PERIODIC) && nNow > nLastSetChain + (int64_t)DATABASE_WRITE_INTERVAL * 1000000)) {
|
||||
// Update best block in wallet (so we can detect restored wallets).
|
||||
GetMainSignals().SetBestChain(chainActive.GetLocator());
|
||||
nLastSetChain = nNow;
|
||||
@ -2164,14 +2164,14 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &
|
||||
void FlushStateToDisk() {
|
||||
CValidationState state;
|
||||
const CChainParams& chainparams = Params();
|
||||
FlushStateToDisk(chainparams, state, FLUSH_STATE_ALWAYS);
|
||||
FlushStateToDisk(chainparams, state, FlushStateMode::ALWAYS);
|
||||
}
|
||||
|
||||
void PruneAndFlush() {
|
||||
CValidationState state;
|
||||
fCheckForPruning = true;
|
||||
const CChainParams& chainparams = Params();
|
||||
FlushStateToDisk(chainparams, state, FLUSH_STATE_NONE);
|
||||
FlushStateToDisk(chainparams, state, FlushStateMode::NONE);
|
||||
}
|
||||
|
||||
static void DoWarning(const std::string& strWarning)
|
||||
@ -2199,9 +2199,9 @@ void static UpdateTip(const CBlockIndex *pindexNew, const CChainParams& chainPar
|
||||
for (int bit = 0; bit < VERSIONBITS_NUM_BITS; bit++) {
|
||||
WarningBitsConditionChecker checker(bit);
|
||||
ThresholdState state = checker.GetStateFor(pindex, chainParams.GetConsensus(), warningcache[bit]);
|
||||
if (state == THRESHOLD_ACTIVE || state == THRESHOLD_LOCKED_IN) {
|
||||
if (state == ThresholdState::ACTIVE || state == ThresholdState::LOCKED_IN) {
|
||||
const std::string strWarning = strprintf(_("Warning: unknown new rules activated (versionbit %i)"), bit);
|
||||
if (state == THRESHOLD_ACTIVE) {
|
||||
if (state == ThresholdState::ACTIVE) {
|
||||
DoWarning(strWarning);
|
||||
} else {
|
||||
warningMessages.push_back(strWarning);
|
||||
@ -2267,7 +2267,7 @@ bool CChainState::DisconnectTip(CValidationState& state, const CChainParams& cha
|
||||
}
|
||||
LogPrint(BCLog::BENCH, "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * MILLI);
|
||||
// Write the chain state to disk, if necessary.
|
||||
if (!FlushStateToDisk(chainparams, state, FLUSH_STATE_IF_NEEDED))
|
||||
if (!FlushStateToDisk(chainparams, state, FlushStateMode::IF_NEEDED))
|
||||
return false;
|
||||
|
||||
if (disconnectpool) {
|
||||
@ -2405,7 +2405,7 @@ bool CChainState::ConnectTip(CValidationState& state, const CChainParams& chainp
|
||||
int64_t nTime4 = GetTimeMicros(); nTimeFlush += nTime4 - nTime3;
|
||||
LogPrint(BCLog::BENCH, " - Flush: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime4 - nTime3) * MILLI, nTimeFlush * MICRO, nTimeFlush * MILLI / nBlocksTotal);
|
||||
// Write the chain state to disk, if necessary.
|
||||
if (!FlushStateToDisk(chainparams, state, FLUSH_STATE_IF_NEEDED))
|
||||
if (!FlushStateToDisk(chainparams, state, FlushStateMode::IF_NEEDED))
|
||||
return false;
|
||||
int64_t nTime5 = GetTimeMicros(); nTimeChainState += nTime5 - nTime4;
|
||||
LogPrint(BCLog::BENCH, " - Writing chainstate: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime5 - nTime4) * MILLI, nTimeChainState * MICRO, nTimeChainState * MILLI / nBlocksTotal);
|
||||
@ -2682,7 +2682,7 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
|
||||
CheckBlockIndex(chainparams.GetConsensus());
|
||||
|
||||
// Write changes periodically to disk, after relay.
|
||||
if (!FlushStateToDisk(chainparams, state, FLUSH_STATE_PERIODIC)) {
|
||||
if (!FlushStateToDisk(chainparams, state, FlushStateMode::PERIODIC)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -3076,7 +3076,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P
|
||||
bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params)
|
||||
{
|
||||
LOCK(cs_main);
|
||||
return (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == THRESHOLD_ACTIVE);
|
||||
return (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == ThresholdState::ACTIVE);
|
||||
}
|
||||
|
||||
// Compute at which vout of the block's coinbase transaction the witness
|
||||
@ -3195,7 +3195,7 @@ static bool ContextualCheckBlock(const CBlock& block, CValidationState& state, c
|
||||
|
||||
// Start enforcing BIP113 (Median Time Past) using versionbits logic.
|
||||
int nLockTimeFlags = 0;
|
||||
if (VersionBitsState(pindexPrev, consensusParams, Consensus::DEPLOYMENT_CSV, versionbitscache) == THRESHOLD_ACTIVE) {
|
||||
if (VersionBitsState(pindexPrev, consensusParams, Consensus::DEPLOYMENT_CSV, versionbitscache) == ThresholdState::ACTIVE) {
|
||||
nLockTimeFlags |= LOCKTIME_MEDIAN_TIME_PAST;
|
||||
}
|
||||
|
||||
@ -3229,7 +3229,7 @@ static bool ContextualCheckBlock(const CBlock& block, CValidationState& state, c
|
||||
// {0xaa, 0x21, 0xa9, 0xed}, and the following 32 bytes are SHA256^2(witness root, witness nonce). In case there are
|
||||
// multiple, the last one is used.
|
||||
bool fHaveWitness = false;
|
||||
if (VersionBitsState(pindexPrev, consensusParams, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == THRESHOLD_ACTIVE) {
|
||||
if (VersionBitsState(pindexPrev, consensusParams, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == ThresholdState::ACTIVE) {
|
||||
int commitpos = GetWitnessCommitmentIndex(block);
|
||||
if (commitpos != -1) {
|
||||
bool malleated = false;
|
||||
@ -3443,7 +3443,7 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CVali
|
||||
}
|
||||
|
||||
if (fCheckForPruning)
|
||||
FlushStateToDisk(chainparams, state, FLUSH_STATE_NONE); // we just allocated more disk space for block files
|
||||
FlushStateToDisk(chainparams, state, FlushStateMode::NONE); // we just allocated more disk space for block files
|
||||
|
||||
CheckBlockIndex(chainparams.GetConsensus());
|
||||
|
||||
@ -3596,7 +3596,7 @@ void PruneBlockFilesManual(int nManualPruneHeight)
|
||||
{
|
||||
CValidationState state;
|
||||
const CChainParams& chainparams = Params();
|
||||
FlushStateToDisk(chainparams, state, FLUSH_STATE_NONE, nManualPruneHeight);
|
||||
FlushStateToDisk(chainparams, state, FlushStateMode::NONE, nManualPruneHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4094,7 +4094,7 @@ bool CChainState::RewindBlockIndex(const CChainParams& params)
|
||||
return error("RewindBlockIndex: unable to disconnect block at height %i", pindex->nHeight);
|
||||
}
|
||||
// Occasionally flush state to disk.
|
||||
if (!FlushStateToDisk(params, state, FLUSH_STATE_PERIODIC))
|
||||
if (!FlushStateToDisk(params, state, FlushStateMode::PERIODIC))
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -4160,7 +4160,7 @@ bool RewindBlockIndex(const CChainParams& params) {
|
||||
// and skip it here, we're about to -reindex-chainstate anyway, so
|
||||
// it'll get called a bunch real soon.
|
||||
CValidationState state;
|
||||
if (!FlushStateToDisk(params, state, FLUSH_STATE_ALWAYS)) {
|
||||
if (!FlushStateToDisk(params, state, FlushStateMode::ALWAYS)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user