2424from test_framework .p2p import (
2525 P2PInterface ,
2626 p2p_lock ,
27+ NONPREF_PEER_TX_DELAY ,
28+ GETDATA_TX_INTERVAL ,
29+ TXID_RELAY_DELAY ,
30+ OVERLOADED_PEER_TX_DELAY
2731)
2832from test_framework .test_framework import BitcoinTestFramework
2933from test_framework .util import (
@@ -43,18 +47,13 @@ def on_getdata(self, message):
4347 self .tx_getdata_count += 1
4448
4549
46- # Constants from net_processing
47- GETDATA_TX_INTERVAL = 60 # seconds
48- NONPREF_PEER_TX_DELAY = 2 # seconds
49- INBOUND_PEER_TX_DELAY = NONPREF_PEER_TX_DELAY # inbound is non-preferred
50- TXID_RELAY_DELAY = 2 # seconds
51- OVERLOADED_PEER_DELAY = 2 # seconds
52- MAX_GETDATA_IN_FLIGHT = 100
50+ # Constants from txdownloadman
51+ MAX_PEER_TX_REQUEST_IN_FLIGHT = 100
5352MAX_PEER_TX_ANNOUNCEMENTS = 5000
5453
5554# Python test constants
5655NUM_INBOUND = 10
57- MAX_GETDATA_INBOUND_WAIT = GETDATA_TX_INTERVAL + INBOUND_PEER_TX_DELAY + TXID_RELAY_DELAY
56+ MAX_GETDATA_INBOUND_WAIT = GETDATA_TX_INTERVAL + NONPREF_PEER_TX_DELAY + TXID_RELAY_DELAY
5857
5958class ConnectionType (Enum ):
6059 """ Different connection types
@@ -123,13 +122,13 @@ def test_inv_block(self):
123122 # * the first time it is re-requested from the outbound peer, plus
124123 # * 2 seconds to avoid races
125124 assert self .nodes [1 ].getpeerinfo ()[0 ]['inbound' ] == False
126- timeout = 2 + INBOUND_PEER_TX_DELAY + GETDATA_TX_INTERVAL
125+ timeout = 2 + NONPREF_PEER_TX_DELAY + GETDATA_TX_INTERVAL
127126 self .log .info ("Tx should be received at node 1 after {} seconds" .format (timeout ))
128127 self .sync_mempools (timeout = timeout )
129128
130129 def test_in_flight_max (self ):
131- self .log .info ("Test that we don't load peers with more than {} transaction requests immediately" .format (MAX_GETDATA_IN_FLIGHT ))
132- txids = [i for i in range (MAX_GETDATA_IN_FLIGHT + 2 )]
130+ self .log .info ("Test that we don't load peers with more than {} transaction requests immediately" .format (MAX_PEER_TX_REQUEST_IN_FLIGHT ))
131+ txids = [i for i in range (MAX_PEER_TX_REQUEST_IN_FLIGHT + 2 )]
133132
134133 p = self .nodes [0 ].p2ps [0 ]
135134
@@ -138,22 +137,22 @@ def test_in_flight_max(self):
138137
139138 mock_time = int (time .time () + 1 )
140139 self .nodes [0 ].setmocktime (mock_time )
141- for i in range (MAX_GETDATA_IN_FLIGHT ):
140+ for i in range (MAX_PEER_TX_REQUEST_IN_FLIGHT ):
142141 p .send_message (msg_inv ([CInv (t = MSG_WTX , h = txids [i ])]))
143142 p .sync_with_ping ()
144- mock_time += INBOUND_PEER_TX_DELAY
143+ mock_time += NONPREF_PEER_TX_DELAY
145144 self .nodes [0 ].setmocktime (mock_time )
146- p .wait_until (lambda : p .tx_getdata_count >= MAX_GETDATA_IN_FLIGHT )
147- for i in range (MAX_GETDATA_IN_FLIGHT , len (txids )):
145+ p .wait_until (lambda : p .tx_getdata_count >= MAX_PEER_TX_REQUEST_IN_FLIGHT )
146+ for i in range (MAX_PEER_TX_REQUEST_IN_FLIGHT , len (txids )):
148147 p .send_message (msg_inv ([CInv (t = MSG_WTX , h = txids [i ])]))
149148 p .sync_with_ping ()
150- self .log .info ("No more than {} requests should be seen within {} seconds after announcement" .format (MAX_GETDATA_IN_FLIGHT , INBOUND_PEER_TX_DELAY + OVERLOADED_PEER_DELAY - 1 ))
151- self .nodes [0 ].setmocktime (mock_time + INBOUND_PEER_TX_DELAY + OVERLOADED_PEER_DELAY - 1 )
149+ self .log .info ("No more than {} requests should be seen within {} seconds after announcement" .format (MAX_PEER_TX_REQUEST_IN_FLIGHT , NONPREF_PEER_TX_DELAY + OVERLOADED_PEER_TX_DELAY - 1 ))
150+ self .nodes [0 ].setmocktime (mock_time + NONPREF_PEER_TX_DELAY + OVERLOADED_PEER_TX_DELAY - 1 )
152151 p .sync_with_ping ()
153152 with p2p_lock :
154- assert_equal (p .tx_getdata_count , MAX_GETDATA_IN_FLIGHT )
155- self .log .info ("If we wait {} seconds after announcement, we should eventually get more requests" .format (INBOUND_PEER_TX_DELAY + OVERLOADED_PEER_DELAY ))
156- self .nodes [0 ].setmocktime (mock_time + INBOUND_PEER_TX_DELAY + OVERLOADED_PEER_DELAY )
153+ assert_equal (p .tx_getdata_count , MAX_PEER_TX_REQUEST_IN_FLIGHT )
154+ self .log .info ("If we wait {} seconds after announcement, we should eventually get more requests" .format (NONPREF_PEER_TX_DELAY + OVERLOADED_PEER_TX_DELAY ))
155+ self .nodes [0 ].setmocktime (mock_time + NONPREF_PEER_TX_DELAY + OVERLOADED_PEER_TX_DELAY )
157156 p .wait_until (lambda : p .tx_getdata_count == len (txids ))
158157
159158 def test_expiry_fallback (self ):
0 commit comments