Skip to content

Commit f12d8b1

Browse files
committed
qa: test a compact block with an invalid transaction
The current test to exercise a block with an invalid transaction actually creates a block with an invalid coinbase witness, which is checked early and for which MaybePunishNodeForBlock() is not called. Add a test case with an invalid regular transaction, which will lead CheckInputScripts to return a CONSENSUS error and MaybePunishNodeForBlock() to be called, appropriately not disconnecting upon an invalid compact block. This was until now untested as can be checked with the following diff: ```diff diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 0c4a89c..d243fb88d4b 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1805,10 +1805,10 @@ void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati // The node is providing invalid data: case BlockValidationResult::BLOCK_CONSENSUS: case BlockValidationResult::BLOCK_MUTATED: - if (!via_compact_block) { + //if (!via_compact_block) { if (peer) Misbehaving(*peer, message); return; - } + //} break; case BlockValidationResult::BLOCK_CACHED_INVALID: { ``` Finally, note this failure is cached (unlike the malleated witness failure), which will be used in the following commits.
1 parent d6c37b2 commit f12d8b1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/functional/p2p_compactblocks.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
CScript,
5555
OP_DROP,
5656
OP_TRUE,
57+
OP_RETURN,
5758
)
5859
from test_framework.test_framework import BitcoinTestFramework
5960
from test_framework.util import (
@@ -726,6 +727,23 @@ def test_invalid_tx_in_compactblock(self, test_node):
726727
assert_not_equal(node.getbestblockhash(), block.hash_hex)
727728
test_node.sync_with_ping()
728729

730+
# Re-establish a proper witness commitment with the coinbase witness, but
731+
# invalidate the last tx in the block.
732+
block.vtx[4].vin[0].scriptSig = CScript([OP_RETURN])
733+
block.hashMerkleRoot = block.calc_merkle_root()
734+
add_witness_commitment(block)
735+
block.solve()
736+
737+
# This will lead to a consensus failure for which we also won't be disconnected but which
738+
# will be cached.
739+
comp_block.initialize_from_block(block, prefill_list=list(range(len(block.vtx))), use_witness=True)
740+
msg = msg_cmpctblock(comp_block.to_p2p())
741+
test_node.send_and_ping(msg)
742+
743+
# The tip still didn't advance.
744+
assert_not_equal(node.getbestblockhash(), block.hash_hex)
745+
test_node.sync_with_ping()
746+
729747
# Helper for enabling cb announcements
730748
# Send the sendcmpct request and sync headers
731749
def request_cb_announcements(self, peer):

0 commit comments

Comments
 (0)