Skip to content

Commit faadc60

Browse files
author
MarcoFalke
committed
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.
1 parent 9174bcf commit faadc60

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/validation.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ bool CheckSequenceLocks(CBlockIndex* tip,
302302
}
303303

304304
// Returns the script flags which should be checked for a given block
305-
static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consensus::Params& chainparams);
305+
static unsigned int GetBlockScriptFlags(const CBlockIndex& block_index, const Consensus::Params& chainparams);
306306

307307
static void LimitMempoolSize(CTxMemPool& pool, CCoinsViewCache& coins_cache, size_t limit, std::chrono::seconds age)
308308
EXCLUSIVE_LOCKS_REQUIRED(pool.cs, ::cs_main)
@@ -939,7 +939,7 @@ bool MemPoolAccept::ConsensusScriptChecks(const ATMPArgs& args, Workspace& ws)
939939
// There is a similar check in CreateNewBlock() to prevent creating
940940
// invalid blocks (using TestBlockValidity), however allowing such
941941
// transactions into the mempool can be exploited as a DoS attack.
942-
unsigned int currentBlockScriptVerifyFlags = GetBlockScriptFlags(m_active_chainstate.m_chain.Tip(), chainparams.GetConsensus());
942+
unsigned int currentBlockScriptVerifyFlags{GetBlockScriptFlags(*m_active_chainstate.m_chain.Tip(), chainparams.GetConsensus())};
943943
if (!CheckInputsFromMempoolAndCache(tx, state, m_view, m_pool, currentBlockScriptVerifyFlags,
944944
ws.m_precomputed_txdata, m_active_chainstate.CoinsTip())) {
945945
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 @@ class WarningBitsConditionChecker : public AbstractThresholdConditionChecker
15791579

15801580
static ThresholdConditionCache warningcache[VERSIONBITS_NUM_BITS] GUARDED_BY(cs_main);
15811581

1582-
static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consensus::Params& consensusparams)
1582+
static unsigned int GetBlockScriptFlags(const CBlockIndex& block_index, const Consensus::Params& consensusparams)
15831583
{
15841584
unsigned int flags = SCRIPT_VERIFY_NONE;
15851585

@@ -1589,43 +1589,42 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens
15891589
// mainnet and testnet), so for simplicity, always leave P2SH
15901590
// on except for the one violating block.
15911591
if (consensusparams.BIP16Exception.IsNull() || // no bip16 exception on this chain
1592-
pindex->phashBlock == nullptr || // this is a new candidate block, eg from TestBlockValidity()
1593-
*pindex->phashBlock != consensusparams.BIP16Exception) // this block isn't the historical exception
1592+
block_index.phashBlock == nullptr || // this is a new candidate block, eg from TestBlockValidity()
1593+
*block_index.phashBlock != consensusparams.BIP16Exception) // this block isn't the historical exception
15941594
{
15951595
// Enforce WITNESS rules whenever P2SH is in effect
15961596
flags |= SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS;
15971597
}
15981598

15991599
// Enforce the DERSIG (BIP66) rule
1600-
if (DeploymentActiveAt(*pindex, consensusparams, Consensus::DEPLOYMENT_DERSIG)) {
1600+
if (DeploymentActiveAt(block_index, consensusparams, Consensus::DEPLOYMENT_DERSIG)) {
16011601
flags |= SCRIPT_VERIFY_DERSIG;
16021602
}
16031603

16041604
// Enforce CHECKLOCKTIMEVERIFY (BIP65)
1605-
if (DeploymentActiveAt(*pindex, consensusparams, Consensus::DEPLOYMENT_CLTV)) {
1605+
if (DeploymentActiveAt(block_index, consensusparams, Consensus::DEPLOYMENT_CLTV)) {
16061606
flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY;
16071607
}
16081608

16091609
// Enforce CHECKSEQUENCEVERIFY (BIP112)
1610-
if (DeploymentActiveAt(*pindex, consensusparams, Consensus::DEPLOYMENT_CSV)) {
1610+
if (DeploymentActiveAt(block_index, consensusparams, Consensus::DEPLOYMENT_CSV)) {
16111611
flags |= SCRIPT_VERIFY_CHECKSEQUENCEVERIFY;
16121612
}
16131613

16141614
// Enforce Taproot (BIP340-BIP342)
1615-
if (DeploymentActiveAt(*pindex, consensusparams, Consensus::DEPLOYMENT_TAPROOT)) {
1615+
if (DeploymentActiveAt(block_index, consensusparams, Consensus::DEPLOYMENT_TAPROOT)) {
16161616
flags |= SCRIPT_VERIFY_TAPROOT;
16171617
}
16181618

16191619
// Enforce BIP147 NULLDUMMY (activated simultaneously with segwit)
1620-
if (DeploymentActiveAt(*pindex, consensusparams, Consensus::DEPLOYMENT_SEGWIT)) {
1620+
if (DeploymentActiveAt(block_index, consensusparams, Consensus::DEPLOYMENT_SEGWIT)) {
16211621
flags |= SCRIPT_VERIFY_NULLDUMMY;
16221622
}
16231623

16241624
return flags;
16251625
}
16261626

16271627

1628-
16291628
static int64_t nTimeCheck = 0;
16301629
static int64_t nTimeForks = 0;
16311630
static int64_t nTimeVerify = 0;
@@ -1811,7 +1810,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
18111810
}
18121811

18131812
// Get the script flags for this block
1814-
unsigned int flags = GetBlockScriptFlags(pindex, m_params.GetConsensus());
1813+
unsigned int flags{GetBlockScriptFlags(*pindex, m_params.GetConsensus())};
18151814

18161815
int64_t nTime2 = GetTimeMicros(); nTimeForks += nTime2 - nTime1;
18171816
LogPrint(BCLog::BENCH, " - Fork checks: %.2fms [%.2fs (%.2fms/blk)]\n", MILLI * (nTime2 - nTime1), nTimeForks * MICRO, nTimeForks * MILLI / nBlocksTotal);

0 commit comments

Comments
 (0)