Skip to content

Commit 146a3d5

Browse files
committed
[validation] Make script error messages uniform for parallel/single validation
This makes the debug output mostly the same for -par=1 and parallel validation runs. Of course, parallel validation is non-deterministic in what error it may encounter first if there are multiple issues. Also, the way certain script-related and non-script-related checks are performed differs between the two modes still, which may result in discrepancies.
1 parent 1ac1c33 commit 146a3d5

9 files changed

+11
-19
lines changed

src/test/miner_tests.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,7 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::
403403
tx.vout[0].nValue -= LOWFEE;
404404
hash = tx.GetHash();
405405
AddToMempool(tx_mempool, entry.Fee(LOWFEE).Time(Now<NodeSeconds>()).SpendsCoinbase(false).FromTx(tx));
406-
// Should throw block-validation-failed
407-
BOOST_CHECK_EXCEPTION(AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("block-validation-failed"));
406+
BOOST_CHECK_EXCEPTION(AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("mandatory-script-verify-flag-failed"));
408407

409408
// Delete the dummy blocks again.
410409
while (m_node.chainman->ActiveChain().Tip()->nHeight > nHeight) {

src/validation.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -2688,8 +2688,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
26882688
// Any transaction validation failure in ConnectBlock is a block consensus failure
26892689
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS,
26902690
tx_state.GetRejectReason(), tx_state.GetDebugMessage());
2691-
LogError("ConnectBlock(): CheckInputScripts on %s failed with %s\n",
2692-
tx.GetHash().ToString(), state.ToString());
2691+
LogInfo("Script validation error in block: %s\n", tx_state.GetRejectReason());
26932692
return false;
26942693
}
26952694
control.Add(std::move(vChecks));
@@ -2717,8 +2716,9 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
27172716

27182717
auto parallel_result = control.Complete();
27192718
if (parallel_result.has_value()) {
2720-
LogPrintf("ERROR: %s: CheckQueue failed\n", __func__);
2721-
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "block-validation-failed");
2719+
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, strprintf("mandatory-script-verify-flag-failed (%s)", ScriptErrorString(*parallel_result)));
2720+
LogInfo("Script validation error in block: %s", state.GetRejectReason());
2721+
return false;
27222722
}
27232723
const auto time_4{SteadyClock::now()};
27242724
m_chainman.time_verify += time_4 - time_2;

test/functional/feature_block.py

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ def set_test_params(self):
8888
self.extra_args = [[
8989
'-acceptnonstdtxn=1', # This is a consensus block test, we don't care about tx policy
9090
'-testactivationheight=bip34@2',
91-
'-par=1', # Until https://github.com/bitcoin/bitcoin/issues/30960 is fixed
9291
]]
9392

9493
def run_test(self):

test/functional/feature_cltv.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ def set_test_params(self):
8787
self.noban_tx_relay = True
8888
self.extra_args = [[
8989
f'-testactivationheight=cltv@{CLTV_HEIGHT}',
90-
'-par=1', # Use only one script thread to get the exact reject reason for testing
9190
'-acceptnonstdtxn=1', # cltv_invalidate is nonstandard
9291
]]
9392
self.setup_clean_chain = True
@@ -175,7 +174,7 @@ def run_test(self):
175174
block.hashMerkleRoot = block.calc_merkle_root()
176175
block.solve()
177176

178-
with self.nodes[0].assert_debug_log(expected_msgs=[f'CheckInputScripts on {block.vtx[-1].hash} failed with {expected_cltv_reject_reason}']):
177+
with self.nodes[0].assert_debug_log(expected_msgs=[f'Script validation error in block: {expected_cltv_reject_reason}']):
179178
peer.send_and_ping(msg_block(block))
180179
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
181180
peer.sync_with_ping()

test/functional/feature_csv_activation.py

-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ def set_test_params(self):
9999
self.noban_tx_relay = True
100100
self.extra_args = [[
101101
f'-testactivationheight=csv@{CSV_ACTIVATION_HEIGHT}',
102-
'-par=1', # Use only one script thread to get the exact reject reason for testing
103102
]]
104103
self.supports_cli = False
105104

test/functional/feature_dersig.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def set_test_params(self):
5151
self.noban_tx_relay = True
5252
self.extra_args = [[
5353
f'-testactivationheight=dersig@{DERSIG_HEIGHT}',
54-
'-par=1', # Use only one script thread to get the exact log msg for testing
5554
]]
5655
self.setup_clean_chain = True
5756
self.rpc_timeout = 240
@@ -131,7 +130,7 @@ def run_test(self):
131130
block.hashMerkleRoot = block.calc_merkle_root()
132131
block.solve()
133132

134-
with self.nodes[0].assert_debug_log(expected_msgs=[f'CheckInputScripts on {block.vtx[-1].hash} failed with mandatory-script-verify-flag-failed (Non-canonical DER signature)']):
133+
with self.nodes[0].assert_debug_log(expected_msgs=[f'Script validation error in block: mandatory-script-verify-flag-failed (Non-canonical DER signature)']):
135134
peer.send_and_ping(msg_block(block))
136135
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
137136
peer.sync_with_ping()

test/functional/feature_nulldummy.py

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def set_test_params(self):
5757
self.extra_args = [[
5858
f'-testactivationheight=segwit@{COINBASE_MATURITY + 5}',
5959
'-addresstype=legacy',
60-
'-par=1', # Use only one script thread to get the exact reject reason for testing
6160
]]
6261

6362
def create_transaction(self, *, txid, input_details=None, addr, amount, privkey):

test/functional/feature_taproot.py

-1
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,6 @@ def skip_test_if_missing_module(self):
12851285
def set_test_params(self):
12861286
self.num_nodes = 1
12871287
self.setup_clean_chain = True
1288-
self.extra_args = [["-par=1"]]
12891288

12901289
def block_submit(self, node, txs, msg, err_msg, cb_pubkey=None, fees=0, sigops_weight=0, witness=False, accept=False):
12911290

test/functional/p2p_segwit.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ def set_test_params(self):
214214
self.noban_tx_relay = True
215215
# This test tests SegWit both pre and post-activation, so use the normal BIP9 activation.
216216
self.extra_args = [
217+
# -par=1 should not affect validation outcome or logging/reported failures. It is kept
218+
# here to exercise the code path still (as it is distinct for multithread script
219+
# validation).
217220
["-acceptnonstdtxn=1", f"-testactivationheight=segwit@{SEGWIT_HEIGHT}", "-par=1"],
218221
["-acceptnonstdtxn=0", f"-testactivationheight=segwit@{SEGWIT_HEIGHT}"],
219222
]
@@ -507,10 +510,6 @@ def test_v0_outputs_arent_spendable(self):
507510
# When the block is serialized without witness, validation fails because the transaction is
508511
# invalid (transactions are always validated with SCRIPT_VERIFY_WITNESS so a segwit v0 transaction
509512
# without a witness is invalid).
510-
# Note: The reject reason for this failure could be
511-
# 'block-validation-failed' (if script check threads > 1) or
512-
# 'mandatory-script-verify-flag-failed (Witness program was passed an
513-
# empty witness)' (otherwise).
514513
test_witness_block(self.nodes[0], self.test_node, block, accepted=False, with_witness=False,
515514
reason='mandatory-script-verify-flag-failed (Witness program was passed an empty witness)')
516515

@@ -1015,7 +1014,7 @@ def test_extra_witness_data(self):
10151014
tx2.vout.append(CTxOut(tx.vout[0].nValue, CScript([OP_TRUE])))
10161015
tx2.wit.vtxinwit.extend([CTxInWitness(), CTxInWitness()])
10171016
tx2.wit.vtxinwit[0].scriptWitness.stack = [CScript([CScriptNum(1)]), CScript([CScriptNum(1)]), witness_script]
1018-
tx2.wit.vtxinwit[1].scriptWitness.stack = [CScript([OP_TRUE])]
1017+
tx2.wit.vtxinwit[1].scriptWitness.stack = []
10191018

10201019
block = self.build_next_block()
10211020
self.update_witness_block_with_transactions(block, [tx2])

0 commit comments

Comments
 (0)