Skip to content

Commit 1a37de4

Browse files
committed
[validation] Remove error() calls from Invalid() calls
This is in preparation for the next commit, which removes the useless `ret` parameter from ValidationState::Invalid(). error() is simply a convenience wrapper that calls LogPrintf and returns false. Call LogPrintf explicitly and substitute the error() call for a false bool literal.
1 parent 067981e commit 1a37de4

File tree

1 file changed

+37
-26
lines changed

1 file changed

+37
-26
lines changed

src/validation.cpp

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,8 +2057,8 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
20572057
for (const auto& tx : block.vtx) {
20582058
for (size_t o = 0; o < tx->vout.size(); o++) {
20592059
if (view.HaveCoin(COutPoint(tx->GetHash(), o))) {
2060-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, error("ConnectBlock(): tried to overwrite transaction"),
2061-
"bad-txns-BIP30");
2060+
LogPrintf("ERROR: ConnectBlock(): tried to overwrite transaction\n");
2061+
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, false, "bad-txns-BIP30");
20622062
}
20632063
}
20642064
}
@@ -2105,8 +2105,8 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
21052105
}
21062106
nFees += txfee;
21072107
if (!MoneyRange(nFees)) {
2108-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, error("%s: accumulated fee in the block out of range.", __func__),
2109-
"bad-txns-accumulated-fee-outofrange");
2108+
LogPrintf("ERROR: %s: accumulated fee in the block out of range.\n", __func__);
2109+
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, false, "bad-txns-accumulated-fee-outofrange");
21102110
}
21112111

21122112
// Check that transaction is BIP68 final
@@ -2118,8 +2118,8 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
21182118
}
21192119

21202120
if (!SequenceLocks(tx, nLockTimeFlags, &prevheights, *pindex)) {
2121-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, error("%s: contains a non-BIP68-final transaction", __func__),
2122-
"bad-txns-nonfinal");
2121+
LogPrintf("ERROR: %s: contains a non-BIP68-final transaction\n", __func__);
2122+
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, false, "bad-txns-nonfinal");
21232123
}
21242124
}
21252125

@@ -2128,9 +2128,10 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
21282128
// * p2sh (when P2SH enabled in flags and excludes coinbase)
21292129
// * witness (when witness enabled in flags and excludes coinbase)
21302130
nSigOpsCost += GetTransactionSigOpCost(tx, view, flags);
2131-
if (nSigOpsCost > MAX_BLOCK_SIGOPS_COST)
2132-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, error("ConnectBlock(): too many sigops"),
2133-
"bad-blk-sigops");
2131+
if (nSigOpsCost > MAX_BLOCK_SIGOPS_COST) {
2132+
LogPrintf("ERROR: ConnectBlock(): too many sigops\n");
2133+
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, false, "bad-blk-sigops");
2134+
}
21342135

21352136
txdata.emplace_back(tx);
21362137
if (!tx.IsCoinBase())
@@ -2158,14 +2159,15 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
21582159
LogPrint(BCLog::BENCH, " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs (%.2fms/blk)]\n", (unsigned)block.vtx.size(), MILLI * (nTime3 - nTime2), MILLI * (nTime3 - nTime2) / block.vtx.size(), nInputs <= 1 ? 0 : MILLI * (nTime3 - nTime2) / (nInputs-1), nTimeConnect * MICRO, nTimeConnect * MILLI / nBlocksTotal);
21592160

21602161
CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, chainparams.GetConsensus());
2161-
if (block.vtx[0]->GetValueOut() > blockReward)
2162-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS,
2163-
error("ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)",
2164-
block.vtx[0]->GetValueOut(), blockReward),
2165-
"bad-cb-amount");
2166-
2167-
if (!control.Wait())
2168-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, error("%s: CheckQueue failed", __func__), "block-validation-failed");
2162+
if (block.vtx[0]->GetValueOut() > blockReward) {
2163+
LogPrintf("ERROR: ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)\n", block.vtx[0]->GetValueOut(), blockReward);
2164+
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, false, "bad-cb-amount");
2165+
}
2166+
2167+
if (!control.Wait()) {
2168+
LogPrintf("ERROR: %s: CheckQueue failed\n", __func__);
2169+
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, false, "block-validation-failed");
2170+
}
21692171
int64_t nTime4 = GetTimeMicros(); nTimeVerify += nTime4 - nTime2;
21702172
LogPrint(BCLog::BENCH, " - Verify %u txins: %.2fms (%.3fms/txin) [%.2fs (%.2fms/blk)]\n", nInputs - 1, MILLI * (nTime4 - nTime2), nInputs <= 1 ? 0 : MILLI * (nTime4 - nTime2) / (nInputs-1), nTimeVerify * MICRO, nTimeVerify * MILLI / nBlocksTotal);
21712173

@@ -3417,8 +3419,10 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, BlockValidatio
34173419
// GetLastCheckpoint finds the last checkpoint in MapCheckpoints that's in our
34183420
// g_blockman.m_block_index.
34193421
CBlockIndex* pcheckpoint = GetLastCheckpoint(params.Checkpoints());
3420-
if (pcheckpoint && nHeight < pcheckpoint->nHeight)
3421-
return state.Invalid(BlockValidationResult::BLOCK_CHECKPOINT, error("%s: forked chain older than last checkpoint (height %d)", __func__, nHeight), "bad-fork-prior-to-checkpoint");
3422+
if (pcheckpoint && nHeight < pcheckpoint->nHeight) {
3423+
LogPrintf("ERROR: %s: forked chain older than last checkpoint (height %d)\n", __func__, nHeight);
3424+
return state.Invalid(BlockValidationResult::BLOCK_CHECKPOINT, false, "bad-fork-prior-to-checkpoint");
3425+
}
34223426
}
34233427

34243428
// Check timestamp against prev
@@ -3541,8 +3545,10 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS
35413545
pindex = miSelf->second;
35423546
if (ppindex)
35433547
*ppindex = pindex;
3544-
if (pindex->nStatus & BLOCK_FAILED_MASK)
3545-
return state.Invalid(BlockValidationResult::BLOCK_CACHED_INVALID, error("%s: block %s is marked invalid", __func__, hash.ToString()), "duplicate");
3548+
if (pindex->nStatus & BLOCK_FAILED_MASK) {
3549+
LogPrintf("ERROR: %s: block %s is marked invalid\n", __func__, hash.ToString());
3550+
return state.Invalid(BlockValidationResult::BLOCK_CACHED_INVALID, false, "duplicate");
3551+
}
35463552
return true;
35473553
}
35483554

@@ -3552,11 +3558,15 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS
35523558
// Get prev block index
35533559
CBlockIndex* pindexPrev = nullptr;
35543560
BlockMap::iterator mi = m_block_index.find(block.hashPrevBlock);
3555-
if (mi == m_block_index.end())
3556-
return state.Invalid(BlockValidationResult::BLOCK_MISSING_PREV, error("%s: prev block not found", __func__), "prev-blk-not-found");
3561+
if (mi == m_block_index.end()) {
3562+
LogPrintf("ERROR: %s: prev block not found\n", __func__);
3563+
return state.Invalid(BlockValidationResult::BLOCK_MISSING_PREV, false, "prev-blk-not-found");
3564+
}
35573565
pindexPrev = (*mi).second;
3558-
if (pindexPrev->nStatus & BLOCK_FAILED_MASK)
3559-
return state.Invalid(BlockValidationResult::BLOCK_INVALID_PREV, error("%s: prev block invalid", __func__), "bad-prevblk");
3566+
if (pindexPrev->nStatus & BLOCK_FAILED_MASK) {
3567+
LogPrintf("ERROR: %s: prev block invalid\n", __func__);
3568+
return state.Invalid(BlockValidationResult::BLOCK_INVALID_PREV, false, "bad-prevblk");
3569+
}
35603570
if (!ContextualCheckBlockHeader(block, state, chainparams, pindexPrev, GetAdjustedTime()))
35613571
return error("%s: Consensus::ContextualCheckBlockHeader: %s, %s", __func__, hash.ToString(), FormatStateMessage(state));
35623572

@@ -3593,7 +3603,8 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS
35933603
setDirtyBlockIndex.insert(invalid_walk);
35943604
invalid_walk = invalid_walk->pprev;
35953605
}
3596-
return state.Invalid(BlockValidationResult::BLOCK_INVALID_PREV, error("%s: prev block invalid", __func__), "bad-prevblk");
3606+
LogPrintf("ERROR: %s: prev block invalid\n", __func__);
3607+
return state.Invalid(BlockValidationResult::BLOCK_INVALID_PREV, false, "bad-prevblk");
35973608
}
35983609
}
35993610
}

0 commit comments

Comments
 (0)