Skip to content

Commit da9cdd2

Browse files
committed
Do not run functions with necessary side-effects in assert()
1 parent 26fe5c9 commit da9cdd2

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/net_processing.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
15181518
}
15191519

15201520
CBlock block;
1521-
assert(ReadBlockFromDisk(block, it->second, chainparams.GetConsensus()));
1521+
bool ret = ReadBlockFromDisk(block, it->second, chainparams.GetConsensus());
1522+
assert(ret);
15221523

15231524
BlockTransactions resp(req);
15241525
for (size_t i = 0; i < req.indexes.size(); i++) {
@@ -2730,7 +2731,8 @@ bool SendMessages(CNode* pto, CConnman& connman)
27302731
vHeaders.front().GetHash().ToString(), pto->id);
27312732
//TODO: Shouldn't need to reload block from disk, but requires refactor
27322733
CBlock block;
2733-
assert(ReadBlockFromDisk(block, pBestIndex, consensusParams));
2734+
bool ret = ReadBlockFromDisk(block, pBestIndex, consensusParams);
2735+
assert(ret);
27342736
CBlockHeaderAndShortTxIDs cmpctblock(block, state.fWantsCmpctWitness);
27352737
int nSendFlags = state.fWantsCmpctWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
27362738
connman.PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, cmpctblock));

src/validation.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,7 +2100,8 @@ bool static DisconnectTip(CValidationState& state, const CChainParams& chainpara
21002100
CCoinsViewCache view(pcoinsTip);
21012101
if (!DisconnectBlock(block, state, pindexDelete, view))
21022102
return error("DisconnectTip(): DisconnectBlock %s failed", pindexDelete->GetBlockHash().ToString());
2103-
assert(view.Flush());
2103+
bool flushed = view.Flush();
2104+
assert(flushed);
21042105
}
21052106
LogPrint("bench", "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * 0.001);
21062107
// Write the chain state to disk, if necessary.
@@ -2189,7 +2190,8 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
21892190
}
21902191
nTime3 = GetTimeMicros(); nTimeConnectTotal += nTime3 - nTime2;
21912192
LogPrint("bench", " - Connect total: %.2fms [%.2fs]\n", (nTime3 - nTime2) * 0.001, nTimeConnectTotal * 0.000001);
2192-
assert(view.Flush());
2193+
bool flushed = view.Flush();
2194+
assert(flushed);
21932195
}
21942196
int64_t nTime4 = GetTimeMicros(); nTimeFlush += nTime4 - nTime3;
21952197
LogPrint("bench", " - Flush: %.2fms [%.2fs]\n", (nTime4 - nTime3) * 0.001, nTimeFlush * 0.000001);

0 commit comments

Comments
 (0)