From c1574381168573c561ebddf1945d2debefb340f7 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Tue, 29 Jul 2025 09:52:32 -0400 Subject: [PATCH] qa: test that we do disconnect upon a second invalid compact block being announced This was in fact untested until now. This can be checked with the following diff. ```diff diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 0c4a89c44cb..f8b9adf910a 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1822,7 +1822,7 @@ void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati } case BlockValidationResult::BLOCK_INVALID_HEADER: case BlockValidationResult::BLOCK_INVALID_PREV: - if (peer) Misbehaving(*peer, message); + if (!via_compact_block && peer) Misbehaving(*peer, message); return; // Conflicting (but not necessarily invalid) data or different policy: case BlockValidationResult::BLOCK_MISSING_PREV: ``` --- test/functional/p2p_compactblocks.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/functional/p2p_compactblocks.py b/test/functional/p2p_compactblocks.py index 724a5874373..80041e2b59a 100755 --- a/test/functional/p2p_compactblocks.py +++ b/test/functional/p2p_compactblocks.py @@ -751,6 +751,13 @@ class CompactBlocksTest(BitcoinTestFramework): assert_not_equal(node.getbestblockhash(), block.hash_hex) test_node.sync_with_ping() + # Now, announcing a second block building on top of the invalid one will get us disconnected. + block.hashPrevBlock = block.hash_int + block.solve() + comp_block.initialize_from_block(block, prefill_list=list(range(len(block.vtx))), use_witness=True) + msg = msg_cmpctblock(comp_block.to_p2p()) + test_node.send_await_disconnect(msg) + # Helper for enabling cb announcements # Send the sendcmpct request and sync headers def request_cb_announcements(self, peer): @@ -967,6 +974,9 @@ class CompactBlocksTest(BitcoinTestFramework): self.log.info("Testing handling of invalid compact blocks...") self.test_invalid_tx_in_compactblock(self.segwit_node) + # The previous test will lead to a disconnection. Reconnect before continuing. + self.segwit_node = self.nodes[0].add_p2p_connection(TestP2PConn()) + self.log.info("Testing invalid index in cmpctblock message...") self.test_invalid_cmpctblock_message()