Skip to content

Commit 2d07384

Browse files
committed
Merge bitcoin#31658: test: p2p: fix sending of manual INVs in tx download test
8996fef test: p2p: check that INV messages not matching wtxidrelay are ignored (Sebastian Falbesoner) e0b3336 test: p2p: fix sending of manual INVs in tx download test (Sebastian Falbesoner) Pull request description: The `test_inv_block` sub-test in p2p_tx_download.py has a subtle bug: the manual msg_inv announcements from peers currently have no effect, since they don't match the wtxidrelay setting (=true by default for `P2PInterface` instances) and are hence ignored by the nodes (since 2d282e0 / PR bitcoin#18044): https://github.com/bitcoin/bitcoin/blob/e7c479495509c068215b73f6df070af2d406ae15/src/net_processing.cpp#L3904-L3911 Though the test still passes on master, it does so without the intended scenario of asking an additional peer (triggering the GETDATA_TX_INTERVAL delay). Fix this by sending the INV message with MSG_WTX instead of MSG_TX. This increases the test run time by about one minute intentionally. It might be good to avoid issues like this in the future, happy to add test framework improvements if someone has a concrete idea. (Got into the topic of tx/wtx announcements via the discussion bitcoin#31397 (comment)) ACKs for top commit: maflcko: ACK 8996fef 😸 danielabrozzoni: ACK 8996fef mzumsande: Code Review ACK 8996fef Tree-SHA512: 3da26f9539c89d64c3b0d0579d9af2a6a4577615eed192506e1fb4318421b235f99a6672a497dea3050fba85dad32678f37fd2cda9ecb70cbf52982db37982e8
2 parents 796e1a4 + 8996fef commit 2d07384

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

test/functional/p2p_tx_download.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ def getdata_found(peer_index):
9393
def test_inv_block(self):
9494
self.log.info("Generate a transaction on node 0")
9595
tx = self.wallet.create_self_transfer()
96-
txid = int(tx['txid'], 16)
96+
wtxid = int(tx['wtxid'], 16)
9797

9898
self.log.info(
9999
"Announce the transaction to all nodes from all {} incoming peers, but never send it".format(NUM_INBOUND))
100-
msg = msg_inv([CInv(t=MSG_TX, h=txid)])
100+
msg = msg_inv([CInv(t=MSG_WTX, h=wtxid)])
101101
for p in self.peers:
102102
p.send_and_ping(msg)
103103

@@ -270,6 +270,36 @@ def test_rejects_filter_reset(self):
270270
node.bumpmocktime(MAX_GETDATA_INBOUND_WAIT)
271271
peer.wait_for_getdata([int(low_fee_tx['wtxid'], 16)])
272272

273+
def test_inv_wtxidrelay_mismatch(self):
274+
self.log.info("Check that INV messages that don't match the wtxidrelay setting are ignored")
275+
node = self.nodes[0]
276+
wtxidrelay_on_peer = node.add_p2p_connection(TestP2PConn(wtxidrelay=True))
277+
wtxidrelay_off_peer = node.add_p2p_connection(TestP2PConn(wtxidrelay=False))
278+
random_tx = self.wallet.create_self_transfer()
279+
280+
# MSG_TX INV from wtxidrelay=True peer -> mismatch, ignored
281+
wtxidrelay_on_peer.send_and_ping(msg_inv([CInv(t=MSG_TX, h=int(random_tx['txid'], 16))]))
282+
node.setmocktime(int(time.time()))
283+
node.bumpmocktime(MAX_GETDATA_INBOUND_WAIT)
284+
wtxidrelay_on_peer.sync_with_ping()
285+
assert_equal(wtxidrelay_on_peer.tx_getdata_count, 0)
286+
287+
# MSG_WTX INV from wtxidrelay=False peer -> mismatch, ignored
288+
wtxidrelay_off_peer.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=int(random_tx['wtxid'], 16))]))
289+
node.bumpmocktime(MAX_GETDATA_INBOUND_WAIT)
290+
wtxidrelay_off_peer.sync_with_ping()
291+
assert_equal(wtxidrelay_off_peer.tx_getdata_count, 0)
292+
293+
# MSG_TX INV from wtxidrelay=False peer works
294+
wtxidrelay_off_peer.send_and_ping(msg_inv([CInv(t=MSG_TX, h=int(random_tx['txid'], 16))]))
295+
node.bumpmocktime(MAX_GETDATA_INBOUND_WAIT)
296+
wtxidrelay_off_peer.wait_for_getdata([int(random_tx['txid'], 16)])
297+
298+
# MSG_WTX INV from wtxidrelay=True peer works
299+
wtxidrelay_on_peer.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=int(random_tx['wtxid'], 16))]))
300+
node.bumpmocktime(MAX_GETDATA_INBOUND_WAIT)
301+
wtxidrelay_on_peer.wait_for_getdata([int(random_tx['wtxid'], 16)])
302+
273303
def run_test(self):
274304
self.wallet = MiniWallet(self.nodes[0])
275305

@@ -291,6 +321,7 @@ def run_test(self):
291321
(self.test_inv_block, True),
292322
(self.test_tx_requests, True),
293323
(self.test_rejects_filter_reset, False),
324+
(self.test_inv_wtxidrelay_mismatch, False),
294325
]:
295326
self.stop_nodes()
296327
self.start_nodes()

0 commit comments

Comments
 (0)