This seems to be lacking precision now that we ignore some CMPCTBLOCK messages.
 0--- a/test/functional/p2p_compactblocks.py
 1+++ b/test/functional/p2p_compactblocks.py
 2@@ -904,7 +904,7 @@ class CompactBlocksTest(BitcoinTestFramework):
 3         node = self.nodes[0]
 4         assert len(self.utxos)
 5 
 6-        def announce_cmpct_block(node, peer, txn_count):
 7+        def announce_cmpct_block(node, peer, txn_count, expect_success):
 8             utxo = self.utxos.pop(0)
 9             block = self.build_block_with_transactions(node, utxo, txn_count)
10 
11@@ -914,12 +914,18 @@ class CompactBlocksTest(BitcoinTestFramework):
12             peer.send_and_ping(msg)
13             with p2p_lock:
14                 assert "getblocktxn" in peer.last_message
15+                if expect_success:
16+                    assert peer.last_message["getblocktxn"].block_txn_request.blockhash == block.hash_int, \
17+                           f'Mismatching blocks - message: {peer.last_message["getblocktxn"].block_txn_request.blockhash:x}, expected: {block.hash_hex}'
18+                else:
19+                    assert peer.last_message["getblocktxn"].block_txn_request.blockhash != block.hash_int
20+
21             return block, cmpct_block
22 
23         for name, peer in [("delivery", delivery_peer), ("inbound", inbound_peer), ("outbound", outbound_peer)]:
24             self.log.info(f"Setting {name} as high bandwidth peer")
25             self.make_peer_hb_to_candidate(node, peer)
26-            block, cmpct_block = announce_cmpct_block(node, peer, 1)
27+            block, cmpct_block = announce_cmpct_block(node, peer, 1, expect_success=True)
28             msg = msg_blocktxn()
29             msg.block_transactions.blockhash = block.hash_int
30             msg.block_transactions.transactions = block.vtx[1:]
31@@ -933,12 +939,13 @@ class CompactBlocksTest(BitcoinTestFramework):
32             # Remaining low-bandwidth peer is stalling_peer, who announces first
33             assert_equal([peer['bip152_hb_to'] for peer in node.getpeerinfo()], [False, True, True, True])
34 
35-            block, cmpct_block = announce_cmpct_block(node, stalling_peer, num_missing)
36+            block, cmpct_block = announce_cmpct_block(node, stalling_peer, num_missing, expect_success=False)
37 
38             delivery_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
39             with p2p_lock:
40                 # The second peer to announce should still get a getblocktxn
41                 assert "getblocktxn" in delivery_peer.last_message
42+                assert delivery_peer.last_message["getblocktxn"].block_txn_request.blockhash == cmpct_block.header.hash_int
43             assert_not_equal(node.getbestblockhash(), block.hash_hex)
44 
45             inbound_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
46@@ -951,6 +958,7 @@ class CompactBlocksTest(BitcoinTestFramework):
47             with p2p_lock:
48                 # The third peer to announce should get a getblocktxn if outbound
49                 assert "getblocktxn" in outbound_peer.last_message
50+                assert outbound_peer.last_message["getblocktxn"].block_txn_request.blockhash == cmpct_block.header.hash_int
51             assert_not_equal(node.getbestblockhash(), block.hash_hex)
52 
53             # Second peer completes the compact block first
 0--- a/test/functional/p2p_compactblocks.py
 1+++ b/test/functional/p2p_compactblocks.py
 2@@ -904,36 +904,42 @@ class CompactBlocksTest(BitcoinTestFramework):
 3         node = self.nodes[0]
 4         assert len(self.utxos)
 5 
 6-        def announce_cmpct_block(node, peer, txn_count):
 7+        def announce_cmpct_block(node, peer, txn_count, expect_success):
 8             utxo = self.utxos.pop(0)
 9             block = self.build_block_with_transactions(node, utxo, txn_count)
10 
11+            peer.clear_getblocktxn()
12             cmpct_block = HeaderAndShortIDs()
13             cmpct_block.initialize_from_block(block)
14             msg = msg_cmpctblock(cmpct_block.to_p2p())
15             peer.send_and_ping(msg)
16             with p2p_lock:
17-                assert "getblocktxn" in peer.last_message
18+                if expect_success:
19+                    assert "getblocktxn" in peer.last_message
20+                else:
21+                    assert "getblocktxn" not in peer.last_message
22             return block, cmpct_block
23 
24         for name, peer in [("delivery", delivery_peer), ("inbound", inbound_peer), ("outbound", outbound_peer)]:
25             self.log.info(f"Setting {name} as high bandwidth peer")
26             self.make_peer_hb_to_candidate(node, peer)
27-            block, cmpct_block = announce_cmpct_block(node, peer, 1)
28+            block, cmpct_block = announce_cmpct_block(node, peer, 1, expect_success=True)
29             msg = msg_blocktxn()
30             msg.block_transactions.blockhash = block.hash_int
31             msg.block_transactions.transactions = block.vtx[1:]
32             peer.send_and_ping(msg)
33             assert_equal(node.getbestblockhash(), block.hash_hex)
34-            peer.clear_getblocktxn()
35 
36         # Test the simple parallel download case...
37         for num_missing in [1, 5, 20]:
38+            delivery_peer.clear_getblocktxn()
39+            inbound_peer.clear_getblocktxn()
40+            outbound_peer.clear_getblocktxn()
41 
42             # Remaining low-bandwidth peer is stalling_peer, who announces first
43             assert_equal([peer['bip152_hb_to'] for peer in node.getpeerinfo()], [False, True, True, True])
44 
45-            block, cmpct_block = announce_cmpct_block(node, stalling_peer, num_missing)
46+            block, cmpct_block = announce_cmpct_block(node, stalling_peer, num_missing, expect_success=False)
47 
48             delivery_peer.send_and_ping(msg_cmpctblock(cmpct_block.to_p2p()))
49             with p2p_lock:
50@@ -964,10 +970,6 @@ class CompactBlocksTest(BitcoinTestFramework):
51             stalling_peer.send_and_ping(msg)
52             self.utxos.append([block.vtx[-1].txid_int, 0, block.vtx[-1].vout[0].nValue])
53 
54-            delivery_peer.clear_getblocktxn()
55-            inbound_peer.clear_getblocktxn()
56-            outbound_peer.clear_getblocktxn()
57-
58     def test_unsolicited_compact_blocks_ignored(self):
59         node = self.nodes[0]
60         # create new p2p connection for a fresh state w/o any prior sendcmpct messages sent