0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-10 10:52:31 -05:00

refactor: Pass const reference instead of pointer to GetBlockScriptFlags

The function dereferences the pointer and can not accept nullptr. Change
the arg to a const reference to clarify this for the caller.
This commit is contained in:
MarcoFalke 2021-11-25 10:59:26 +01:00
parent 9174bcf7da
commit faadc606c7
No known key found for this signature in database
GPG key ID: CE2B75697E69A548

View file

@ -302,7 +302,7 @@ bool CheckSequenceLocks(CBlockIndex* tip,
} }
// 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 unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consensus::Params& chainparams); static unsigned int GetBlockScriptFlags(const CBlockIndex& block_index, const Consensus::Params& chainparams);
static void LimitMempoolSize(CTxMemPool& pool, CCoinsViewCache& coins_cache, size_t limit, std::chrono::seconds age) static void LimitMempoolSize(CTxMemPool& pool, CCoinsViewCache& coins_cache, size_t limit, std::chrono::seconds age)
EXCLUSIVE_LOCKS_REQUIRED(pool.cs, ::cs_main) EXCLUSIVE_LOCKS_REQUIRED(pool.cs, ::cs_main)
@ -939,7 +939,7 @@ bool MemPoolAccept::ConsensusScriptChecks(const ATMPArgs& args, Workspace& ws)
// There is a similar check in CreateNewBlock() to prevent creating // There is a similar check in CreateNewBlock() to prevent creating
// invalid blocks (using TestBlockValidity), however allowing such // invalid blocks (using TestBlockValidity), however allowing such
// transactions into the mempool can be exploited as a DoS attack. // transactions into the mempool can be exploited as a DoS attack.
unsigned int currentBlockScriptVerifyFlags = GetBlockScriptFlags(m_active_chainstate.m_chain.Tip(), chainparams.GetConsensus()); unsigned int currentBlockScriptVerifyFlags{GetBlockScriptFlags(*m_active_chainstate.m_chain.Tip(), chainparams.GetConsensus())};
if (!CheckInputsFromMempoolAndCache(tx, state, m_view, m_pool, currentBlockScriptVerifyFlags, if (!CheckInputsFromMempoolAndCache(tx, state, m_view, m_pool, currentBlockScriptVerifyFlags,
ws.m_precomputed_txdata, m_active_chainstate.CoinsTip())) { ws.m_precomputed_txdata, m_active_chainstate.CoinsTip())) {
LogPrintf("BUG! PLEASE REPORT THIS! CheckInputScripts failed against latest-block but not STANDARD flags %s, %s\n", hash.ToString(), state.ToString()); LogPrintf("BUG! PLEASE REPORT THIS! CheckInputScripts failed against latest-block but not STANDARD flags %s, %s\n", hash.ToString(), state.ToString());
@ -1579,7 +1579,7 @@ public:
static ThresholdConditionCache warningcache[VERSIONBITS_NUM_BITS] GUARDED_BY(cs_main); static ThresholdConditionCache warningcache[VERSIONBITS_NUM_BITS] GUARDED_BY(cs_main);
static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consensus::Params& consensusparams) static unsigned int GetBlockScriptFlags(const CBlockIndex& block_index, const Consensus::Params& consensusparams)
{ {
unsigned int flags = SCRIPT_VERIFY_NONE; unsigned int flags = SCRIPT_VERIFY_NONE;
@ -1589,35 +1589,35 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens
// mainnet and testnet), so for simplicity, always leave P2SH // mainnet and testnet), so for simplicity, always leave P2SH
// on except for the one violating block. // on except for the one violating block.
if (consensusparams.BIP16Exception.IsNull() || // no bip16 exception on this chain if (consensusparams.BIP16Exception.IsNull() || // no bip16 exception on this chain
pindex->phashBlock == nullptr || // this is a new candidate block, eg from TestBlockValidity() block_index.phashBlock == nullptr || // this is a new candidate block, eg from TestBlockValidity()
*pindex->phashBlock != consensusparams.BIP16Exception) // this block isn't the historical exception *block_index.phashBlock != consensusparams.BIP16Exception) // this block isn't the historical exception
{ {
// Enforce WITNESS rules whenever P2SH is in effect // Enforce WITNESS rules whenever P2SH is in effect
flags |= SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS; flags |= SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS;
} }
// Enforce the DERSIG (BIP66) rule // Enforce the DERSIG (BIP66) rule
if (DeploymentActiveAt(*pindex, consensusparams, Consensus::DEPLOYMENT_DERSIG)) { if (DeploymentActiveAt(block_index, consensusparams, Consensus::DEPLOYMENT_DERSIG)) {
flags |= SCRIPT_VERIFY_DERSIG; flags |= SCRIPT_VERIFY_DERSIG;
} }
// Enforce CHECKLOCKTIMEVERIFY (BIP65) // Enforce CHECKLOCKTIMEVERIFY (BIP65)
if (DeploymentActiveAt(*pindex, consensusparams, Consensus::DEPLOYMENT_CLTV)) { if (DeploymentActiveAt(block_index, consensusparams, Consensus::DEPLOYMENT_CLTV)) {
flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY; flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY;
} }
// Enforce CHECKSEQUENCEVERIFY (BIP112) // Enforce CHECKSEQUENCEVERIFY (BIP112)
if (DeploymentActiveAt(*pindex, consensusparams, Consensus::DEPLOYMENT_CSV)) { if (DeploymentActiveAt(block_index, consensusparams, Consensus::DEPLOYMENT_CSV)) {
flags |= SCRIPT_VERIFY_CHECKSEQUENCEVERIFY; flags |= SCRIPT_VERIFY_CHECKSEQUENCEVERIFY;
} }
// Enforce Taproot (BIP340-BIP342) // Enforce Taproot (BIP340-BIP342)
if (DeploymentActiveAt(*pindex, consensusparams, Consensus::DEPLOYMENT_TAPROOT)) { if (DeploymentActiveAt(block_index, consensusparams, Consensus::DEPLOYMENT_TAPROOT)) {
flags |= SCRIPT_VERIFY_TAPROOT; flags |= SCRIPT_VERIFY_TAPROOT;
} }
// Enforce BIP147 NULLDUMMY (activated simultaneously with segwit) // Enforce BIP147 NULLDUMMY (activated simultaneously with segwit)
if (DeploymentActiveAt(*pindex, consensusparams, Consensus::DEPLOYMENT_SEGWIT)) { if (DeploymentActiveAt(block_index, consensusparams, Consensus::DEPLOYMENT_SEGWIT)) {
flags |= SCRIPT_VERIFY_NULLDUMMY; flags |= SCRIPT_VERIFY_NULLDUMMY;
} }
@ -1625,7 +1625,6 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens
} }
static int64_t nTimeCheck = 0; static int64_t nTimeCheck = 0;
static int64_t nTimeForks = 0; static int64_t nTimeForks = 0;
static int64_t nTimeVerify = 0; static int64_t nTimeVerify = 0;
@ -1811,7 +1810,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
} }
// Get the script flags for this block // Get the script flags for this block
unsigned int flags = GetBlockScriptFlags(pindex, m_params.GetConsensus()); unsigned int flags{GetBlockScriptFlags(*pindex, m_params.GetConsensus())};
int64_t nTime2 = GetTimeMicros(); nTimeForks += nTime2 - nTime1; int64_t nTime2 = GetTimeMicros(); nTimeForks += nTime2 - nTime1;
LogPrint(BCLog::BENCH, " - Fork checks: %.2fms [%.2fs (%.2fms/blk)]\n", MILLI * (nTime2 - nTime1), nTimeForks * MICRO, nTimeForks * MILLI / nBlocksTotal); LogPrint(BCLog::BENCH, " - Fork checks: %.2fms [%.2fs (%.2fms/blk)]\n", MILLI * (nTime2 - nTime1), nTimeForks * MICRO, nTimeForks * MILLI / nBlocksTotal);