From fb2dcbb160bd7d61d53d8150df7f2aaabc32f78c Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Mon, 28 Jul 2025 17:40:19 -0400 Subject: [PATCH] qa: test cached failure for compact block Submit the block with an invalid transaction Script again, leading to CACHED_INVALID being returned by AcceptBlockHeader(). Ensure that also this code path does not lead to a disconnection. This was previously untested, as can be checked with the following diff: ```diff diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 0c4a89c44cb..e8e0c805367 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1814,10 +1814,10 @@ void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati { // Discourage outbound (but not inbound) peers if on an invalid chain. // Exempt HB compact block peers. Manual connections are always protected from discouragement. - if (peer && !via_compact_block && !peer->m_is_inbound) { + //if (peer && !via_compact_block && !peer->m_is_inbound) { if (peer) Misbehaving(*peer, message); return; - } + //} break; } case BlockValidationResult::BLOCK_INVALID_HEADER: ``` --- test/functional/p2p_compactblocks.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/functional/p2p_compactblocks.py b/test/functional/p2p_compactblocks.py index 0d44943d6f3..724a5874373 100755 --- a/test/functional/p2p_compactblocks.py +++ b/test/functional/p2p_compactblocks.py @@ -744,6 +744,13 @@ class CompactBlocksTest(BitcoinTestFramework): assert_not_equal(node.getbestblockhash(), block.hash_hex) test_node.sync_with_ping() + # The failure above was cached. Submitting the compact block again will returned a cached + # consensus error (the code path is different) and still not get us disconnected (nor + # advance the tip). + test_node.send_and_ping(msg) + assert_not_equal(node.getbestblockhash(), block.hash_hex) + test_node.sync_with_ping() + # Helper for enabling cb announcements # Send the sendcmpct request and sync headers def request_cb_announcements(self, peer):