mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-09 11:27:28 -03:00
[validation] merge all ConnectBlock debug logging code paths
This commit is contained in:
parent
b49df703f0
commit
492e1f0994
3 changed files with 24 additions and 24 deletions
|
@ -2595,9 +2595,8 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
|||
for (const auto& tx : block.vtx) {
|
||||
for (size_t o = 0; o < tx->vout.size(); o++) {
|
||||
if (view.HaveCoin(COutPoint(tx->GetHash(), o))) {
|
||||
LogPrintf("ERROR: ConnectBlock(): tried to overwrite transaction\n");
|
||||
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-BIP30",
|
||||
"tried to overwrite transaction");
|
||||
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-BIP30",
|
||||
"tried to overwrite transaction");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2636,6 +2635,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
|||
blockundo.vtxundo.reserve(block.vtx.size() - 1);
|
||||
for (unsigned int i = 0; i < block.vtx.size(); i++)
|
||||
{
|
||||
if (!state.IsValid()) break;
|
||||
const CTransaction &tx = *(block.vtx[i]);
|
||||
|
||||
nInputs += tx.vin.size();
|
||||
|
@ -2649,14 +2649,13 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
|||
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS,
|
||||
tx_state.GetRejectReason(),
|
||||
tx_state.GetDebugMessage() + " in transaction " + tx.GetHash().ToString());
|
||||
LogError("%s: Consensus::CheckTxInputs: %s, %s\n", __func__, tx.GetHash().ToString(), state.ToString());
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
nFees += txfee;
|
||||
if (!MoneyRange(nFees)) {
|
||||
LogPrintf("ERROR: %s: accumulated fee in the block out of range.\n", __func__);
|
||||
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-accumulated-fee-outofrange",
|
||||
"accumulated fee in the block out of range");
|
||||
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-accumulated-fee-outofrange",
|
||||
"accumulated fee in the block out of range");
|
||||
break;
|
||||
}
|
||||
|
||||
// Check that transaction is BIP68 final
|
||||
|
@ -2668,9 +2667,9 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
|||
}
|
||||
|
||||
if (!SequenceLocks(tx, nLockTimeFlags, prevheights, *pindex)) {
|
||||
LogPrintf("ERROR: %s: contains a non-BIP68-final transaction\n", __func__);
|
||||
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-nonfinal",
|
||||
"contains a non-BIP68-final transaction " + tx.GetHash().ToString());
|
||||
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-txns-nonfinal",
|
||||
"contains a non-BIP68-final transaction " + tx.GetHash().ToString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2680,8 +2679,8 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
|||
// * witness (when witness enabled in flags and excludes coinbase)
|
||||
nSigOpsCost += GetTransactionSigOpCost(tx, view, flags);
|
||||
if (nSigOpsCost > MAX_BLOCK_SIGOPS_COST) {
|
||||
LogPrintf("ERROR: ConnectBlock(): too many sigops\n");
|
||||
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-blk-sigops", "too many sigops");
|
||||
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-blk-sigops", "too many sigops");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!tx.IsCoinBase())
|
||||
|
@ -2693,8 +2692,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
|||
// Any transaction validation failure in ConnectBlock is a block consensus failure
|
||||
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS,
|
||||
tx_state.GetRejectReason(), tx_state.GetDebugMessage());
|
||||
LogInfo("Script validation error in block: %s\n", state.ToString());
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
control.Add(std::move(vChecks));
|
||||
}
|
||||
|
@ -2714,16 +2712,17 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
|||
Ticks<MillisecondsDouble>(m_chainman.time_connect) / m_chainman.num_blocks_total);
|
||||
|
||||
CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, params.GetConsensus());
|
||||
if (block.vtx[0]->GetValueOut() > blockReward) {
|
||||
LogPrintf("ERROR: ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)\n", block.vtx[0]->GetValueOut(), blockReward);
|
||||
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cb-amount",
|
||||
strprintf("coinbase pays too much (actual=%d vs limit=%d)", block.vtx[0]->GetValueOut(), blockReward));
|
||||
if (block.vtx[0]->GetValueOut() > blockReward && state.IsValid()) {
|
||||
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cb-amount",
|
||||
strprintf("coinbase pays too much (actual=%d vs limit=%d)", block.vtx[0]->GetValueOut(), blockReward));
|
||||
}
|
||||
|
||||
auto parallel_result = control.Complete();
|
||||
if (parallel_result.has_value()) {
|
||||
if (parallel_result.has_value() && state.IsValid()) {
|
||||
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, strprintf("mandatory-script-verify-flag-failed (%s)", ScriptErrorString(parallel_result->first)), parallel_result->second);
|
||||
LogInfo("Script validation error in block: %s", state.ToString());
|
||||
}
|
||||
if (!state.IsValid()) {
|
||||
LogInfo("Block validation error: %s", state.ToString());
|
||||
return false;
|
||||
}
|
||||
const auto time_4{SteadyClock::now()};
|
||||
|
@ -2734,8 +2733,9 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
|||
Ticks<SecondsDouble>(m_chainman.time_verify),
|
||||
Ticks<MillisecondsDouble>(m_chainman.time_verify) / m_chainman.num_blocks_total);
|
||||
|
||||
if (fJustCheck)
|
||||
if (fJustCheck) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!m_blockman.WriteUndoDataForBlock(blockundo, state, *pindex)) {
|
||||
return false;
|
||||
|
|
|
@ -174,7 +174,7 @@ class BIP65Test(BitcoinTestFramework):
|
|||
block.hashMerkleRoot = block.calc_merkle_root()
|
||||
block.solve()
|
||||
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=[f'Script validation error in block: {expected_cltv_reject_reason}']):
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=[f'Block validation error: {expected_cltv_reject_reason}']):
|
||||
peer.send_and_ping(msg_block(block))
|
||||
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
|
||||
peer.sync_with_ping()
|
||||
|
|
|
@ -130,7 +130,7 @@ class BIP66Test(BitcoinTestFramework):
|
|||
block.hashMerkleRoot = block.calc_merkle_root()
|
||||
block.solve()
|
||||
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=[f'Script validation error in block: mandatory-script-verify-flag-failed (Non-canonical DER signature)']):
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=[f'Block validation error: mandatory-script-verify-flag-failed (Non-canonical DER signature)']):
|
||||
peer.send_and_ping(msg_block(block))
|
||||
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
|
||||
peer.sync_with_ping()
|
||||
|
|
Loading…
Reference in a new issue