Skip to content

Commit 8996fef

Browse files
committed
test: p2p: check that INV messages not matching wtxidrelay are ignored
1 parent e0b3336 commit 8996fef

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/functional/p2p_tx_download.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)