Skip to content

Commit ca6d045

Browse files
sipatomt1664
authored andcommitted
[validation] merge all ConnectBlock debug logging code paths
1 parent 797965e commit ca6d045

3 files changed

Lines changed: 25 additions & 22 deletions

File tree

src/validation.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,8 +2403,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
24032403
for (const auto& tx : block.vtx) {
24042404
for (size_t o = 0; o < tx->vout.size(); o++) {
24052405
if (view.HaveCoin(COutPoint(tx->GetHash(), o))) {
2406-
LogPrintf("ERROR: ConnectBlock(): tried to overwrite transaction\n");
2407-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-BIP30");
2406+
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-BIP30");
24082407
}
24092408
}
24102409
}
@@ -2463,6 +2462,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
24632462

24642463
for (unsigned int i = 0; i < block.vtx.size(); i++)
24652464
{
2465+
if (!state.IsValid()) break;
24662466
const CTransaction &tx = *(block.vtx[i]);
24672467

24682468
nInputs += tx.vin.size();
@@ -2483,8 +2483,8 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
24832483
control.Add(vChecks);
24842484

24852485
if (!MoneyRange(fee_map)) {
2486-
LogPrintf("ERROR: %s: accumulated fee in the block out of range.\n", __func__);
2487-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-accumulated-fee-outofrange");
2486+
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-accumulated-fee-outofrange");
2487+
break;
24882488
}
24892489

24902490
// Check that transaction is BIP68 final
@@ -2500,8 +2500,8 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
25002500
}
25012501

25022502
if (!SequenceLocks(tx, nLockTimeFlags, prevheights, *pindex)) {
2503-
LogPrintf("ERROR: %s: contains a non-BIP68-final transaction\n", __func__);
2504-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-nonfinal");
2503+
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-nonfinal");
2504+
break;
25052505
}
25062506
}
25072507

@@ -2511,8 +2511,8 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
25112511
// * witness (when witness enabled in flags and excludes coinbase)
25122512
nSigOpsCost += GetTransactionSigOpCost(tx, view, flags);
25132513
if (nSigOpsCost > MAX_BLOCK_SIGOPS_COST) {
2514-
LogPrintf("ERROR: ConnectBlock(): too many sigops\n");
2515-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-blk-sigops");
2514+
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-blk-sigops");
2515+
break;
25162516
}
25172517

25182518
if (!tx.IsCoinBase())
@@ -2524,8 +2524,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
25242524
// Any transaction validation failure in ConnectBlock is a block consensus failure
25252525
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS,
25262526
tx_state.GetRejectReason(), tx_state.GetDebugMessage());
2527-
return error("ConnectBlock(): CheckInputScripts on %s failed with %s",
2528-
tx.GetHash().ToString(), state.ToString());
2527+
break;
25292528
}
25302529
control.Add(vChecks);
25312530
}
@@ -2542,24 +2541,28 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
25422541

25432542
CAmountMap block_reward = fee_map;
25442543
block_reward[consensusParams.subsidy_asset] += GetBlockSubsidy(pindex->nHeight, consensusParams);
2545-
if (!MoneyRange(block_reward)) {
2546-
LogPrintf("ERROR: ConnectBlock(): total block reward overflowed\n");
2547-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-blockreward-outofrange");
2544+
if (!MoneyRange(block_reward) && state.IsValid()) {
2545+
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-blockreward-outofrange");
25482546
}
2549-
if (!VerifyCoinbaseAmount(*(block.vtx[0]), block_reward)) {
2550-
LogPrintf("ERROR: ConnectBlock(): coinbase pays too much\n");
2551-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cb-amount");
2547+
if (!VerifyCoinbaseAmount(*(block.vtx[0]), block_reward) && state.IsValid()) {
2548+
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cb-amount");
25522549
}
25532550

2554-
if (!control.Wait()) {
2555-
LogPrintf("ERROR: %s: CheckQueue failed\n", __func__);
2556-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "block-validation-failed");
2551+
if (!control.Wait() && state.IsValid()) {
2552+
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "block-validation-failed");
25572553
}
2554+
2555+
if (!state.IsValid()) {
2556+
LogPrintf("Block validation error: %s", state.ToString());
2557+
return false;
2558+
}
2559+
25582560
int64_t nTime4 = GetTimeMicros(); nTimeVerify += nTime4 - nTime2;
25592561
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);
25602562

2561-
if (fJustCheck)
2563+
if (fJustCheck) {
25622564
return true;
2565+
}
25632566

25642567
if (!m_blockman.WriteUndoDataForBlock(blockundo, state, pindex, m_params)) {
25652568
return false;

test/functional/feature_cltv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def run_test(self):
175175
block.hashMerkleRoot = block.calc_merkle_root()
176176
block.solve()
177177

178-
with self.nodes[0].assert_debug_log(expected_msgs=[f'CheckInputScripts on {block.vtx[-1].hash} failed with {tx_rej + expected_cltv_reject_reason}']):
178+
with self.nodes[0].assert_debug_log(expected_msgs=[f'Block validation error: mempool-script-verify-flag-failed{expected_cltv_reject_reason}']):
179179
peer.send_and_ping(msg_block(block))
180180
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
181181
peer.sync_with_ping()

test/functional/feature_dersig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def run_test(self):
131131
block.hashMerkleRoot = block.calc_merkle_root()
132132
block.solve()
133133

134-
with self.nodes[0].assert_debug_log(expected_msgs=[f'CheckInputScripts on {block.vtx[-1].hash} failed with mempool-script-verify-flag-failed (Non-canonical DER signature)']):
134+
with self.nodes[0].assert_debug_log(expected_msgs=[f'Block validation error: mempool-script-verify-flag-failed (Non-canonical DER signature)']):
135135
peer.send_and_ping(msg_block(block))
136136
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
137137
peer.sync_with_ping()

0 commit comments

Comments
 (0)