In thinking about #33050 and #33012 (comment), i went through the code paths for peer disconnection upon submitting an invalid block. It turns out that the fact we exempt a peer from disconnection upon submitting an invalid compact block was not properly tested, as can be checked with these diffs:
0diff --git a/src/net_processing.cpp b/src/net_processing.cpp
1index https://github.com/bitcoin/bitcoin/commit/0c4a89c44cb6e9a61fdd486d576781e5b66c618c..d243fb88d4b 100644
2--- a/src/net_processing.cpp
3+++ b/src/net_processing.cpp
4@@ -1805,10 +1805,10 @@ void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati
5 // The node is providing invalid data:
6 case BlockValidationResult::BLOCK_CONSENSUS:
7 case BlockValidationResult::BLOCK_MUTATED:
8- if (!via_compact_block) {
9+ //if (!via_compact_block) {
10 if (peer) Misbehaving(*peer, message);
11 return;
12- }
13+ //}
14 break;
15 case BlockValidationResult::BLOCK_CACHED_INVALID:
16 {
0diff --git a/src/net_processing.cpp b/src/net_processing.cpp
1index 0c4a89c44cb..e8e0c805367 100644
2--- a/src/net_processing.cpp
3+++ b/src/net_processing.cpp
4@@ -1814,10 +1814,10 @@ void PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidati
5 {
6 // Discourage outbound (but not inbound) peers if on an invalid chain.
7 // Exempt HB compact block peers. Manual connections are always protected from discouragement.
8- if (peer && !via_compact_block && !peer->m_is_inbound) {
9+ //if (peer && !via_compact_block && !peer->m_is_inbound) {
10 if (peer) Misbehaving(*peer, message);
11 return;
12- }
13+ //}
14 break;
15 }
16 case BlockValidationResult::BLOCK_INVALID_HEADER:
We do have a test for this, but it actually uses a coinbase witness commitment error, which is checked much earlier in FillBlock
. This PR adds coverage for the two exemptions in MaybePunishNodeForBlock
.