mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-25 06:21:13 +02:00
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: ```
This commit is contained in:
@@ -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()
|
||||
|
||||
|
Reference in New Issue
Block a user