Skip to content

Commit 06efb31

Browse files
author
Antoine Riard
committed
Add functional test test_txid_inv_delay
Add a simple functional test to cover TXID_RELAY_DELAY as applied as a TxRequestTracker parameter in AddTxAnnoucement.
1 parent a07910a commit 06efb31

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/functional/p2p_tx_download.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,25 @@ def test_preferred_inv(self):
216216
with p2p_lock:
217217
assert_equal(peer.tx_getdata_count, 1)
218218

219+
def test_txid_inv_delay(self, glob_wtxid=False):
220+
self.log.info('Check that inv from a txid-relay peers are delayed by {} s, with a wtxid peer {}'.format(TXID_RELAY_DELAY, glob_wtxid))
221+
self.restart_node(0, extra_args=['[email protected]'])
222+
mock_time = int(time.time() + 1)
223+
self.nodes[0].setmocktime(mock_time)
224+
peer = self.nodes[0].add_p2p_connection(TestP2PConn(wtxidrelay=False))
225+
if glob_wtxid:
226+
# Add a second wtxid-relay connection otherwise TXID_RELAY_DELAY is waived in
227+
# lack of wtxid-relay peers
228+
self.nodes[0].add_p2p_connection(TestP2PConn(wtxidrelay=True))
229+
peer.send_message(msg_inv([CInv(t=MSG_TX, h=0xff11ff11)]))
230+
peer.sync_with_ping()
231+
with p2p_lock:
232+
assert_equal(peer.tx_getdata_count, 0 if glob_wtxid else 1)
233+
self.nodes[0].setmocktime(mock_time + TXID_RELAY_DELAY)
234+
peer.wait_until(lambda: peer.tx_getdata_count >= 1, timeout=1)
235+
with p2p_lock:
236+
assert_equal(peer.tx_getdata_count, 1)
237+
219238
def test_large_inv_batch(self):
220239
self.log.info('Test how large inv batches are handled with relay permission')
221240
self.restart_node(0, extra_args=['[email protected]'])
@@ -242,6 +261,8 @@ def run_test(self):
242261
self.test_disconnect_fallback()
243262
self.test_notfound_fallback()
244263
self.test_preferred_inv()
264+
self.test_txid_inv_delay()
265+
self.test_txid_inv_delay(True)
245266
self.test_large_inv_batch()
246267
self.test_spurious_notfound()
247268

0 commit comments

Comments
 (0)