C++20 modernization: nullptr, constexpr, smart pointers, thread safety, enum class
- Replace ~320 NULL occurrences with nullptr across 47 files (-184 net lines) - static const -> constexpr for version, coin, utility constants - Collapse 9 PushMessage overloads into 1 variadic template with fold expressions - Convert boost::array -> std::array, boost::type_traits -> std:: equivalents - pwalletMain, pScriptCheckQueue, pScriptCheckThreads -> unique_ptr - mapOrphanBlocks values: raw CBlock* -> unique_ptr<CBlock> - Fix data races: add locks to wallet registration, pindexBest reads, mempool exists - pwalletdbEncryption: raw new/delete -> local unique_ptr, remove exit() calls - PoS reward overflow: CBigNum intermediate for nCoinAge * nRewardCoinYear - memset -> OPENSSL_cleanse for secure zeroing - Fix const-cast UB in SetMerkleBranch - Log silent catch(...) blocks instead of silently swallowing - Enum class: GetMinFeeMode, WalletFeature - std::string_view for 8 utility function parameters - Range-for with structured bindings: 63 iterator loops modernized - std::make_pair -> brace init: 35 sites - Delegating constructors: CWallet, CBlockIndex - Merkle tree caching, std::array for GetMedianTimePast - CScript copy ctor -> = default, operator!= -> = default
This commit is contained in:
+6
-7
@@ -79,7 +79,7 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake, int64_t* pFees)
|
||||
// Create new block
|
||||
unique_ptr<CBlock> pblock(new CBlock());
|
||||
if (!pblock.get())
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
CBlockIndex* pindexPrev = pindexBest;
|
||||
|
||||
@@ -145,13 +145,12 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake, int64_t* pFees)
|
||||
// This vector will be sorted into a priority queue:
|
||||
vector<TxPriority> vecPriority;
|
||||
vecPriority.reserve(mempool.mapTx.size());
|
||||
for (map<uint256, CTransaction>::iterator mi = mempool.mapTx.begin(); mi != mempool.mapTx.end(); ++mi)
|
||||
for (auto& [hash, tx] : mempool.mapTx)
|
||||
{
|
||||
CTransaction& tx = (*mi).second;
|
||||
if (tx.IsCoinBase() || tx.IsCoinStake() || !tx.IsFinal())
|
||||
continue;
|
||||
|
||||
COrphan* porphan = NULL;
|
||||
COrphan* porphan = nullptr;
|
||||
double dPriority = 0;
|
||||
int64_t nTotalIn = 0;
|
||||
bool fMissingInputs = false;
|
||||
@@ -210,7 +209,7 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake, int64_t* pFees)
|
||||
porphan->dFeePerKb = dFeePerKb;
|
||||
}
|
||||
else
|
||||
vecPriority.push_back(TxPriority(dPriority, dFeePerKb, &(*mi).second));
|
||||
vecPriority.push_back(TxPriority(dPriority, dFeePerKb, &tx));
|
||||
}
|
||||
|
||||
// Collect transactions into block
|
||||
@@ -247,7 +246,7 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake, int64_t* pFees)
|
||||
continue;
|
||||
|
||||
// Transaction fee
|
||||
int64_t nMinFee = tx.GetMinFee(nBlockSize, GMF_BLOCK);
|
||||
int64_t nMinFee = tx.GetMinFee(nBlockSize, GetMinFeeMode::Block);
|
||||
|
||||
// Skip free transactions if we're past the minimum block size:
|
||||
if (fSortedByFee && (dFeePerKb < nMinTxFee) && (nBlockSize + nTxSize >= nBlockMinSize))
|
||||
@@ -372,7 +371,7 @@ bool CheckStake(CBlock* pblock, CWallet& wallet)
|
||||
}
|
||||
|
||||
// Process this block the same as if we had received it from another node
|
||||
if (!ProcessBlock(NULL, pblock))
|
||||
if (!ProcessBlock(nullptr, pblock))
|
||||
return error("CheckStake() : ProcessBlock, block not accepted");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user