24
24
from test_framework .p2p import (
25
25
P2PInterface ,
26
26
p2p_lock ,
27
+ NONPREF_PEER_TX_DELAY ,
28
+ GETDATA_TX_INTERVAL ,
29
+ TXID_RELAY_DELAY ,
30
+ OVERLOADED_PEER_TX_DELAY
27
31
)
28
32
from test_framework .test_framework import BitcoinTestFramework
29
33
from test_framework .util import (
@@ -43,18 +47,13 @@ def on_getdata(self, message):
43
47
self .tx_getdata_count += 1
44
48
45
49
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
53
52
MAX_PEER_TX_ANNOUNCEMENTS = 5000
54
53
55
54
# Python test constants
56
55
NUM_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
58
57
59
58
class ConnectionType (Enum ):
60
59
""" Different connection types
@@ -123,13 +122,13 @@ def test_inv_block(self):
123
122
# * the first time it is re-requested from the outbound peer, plus
124
123
# * 2 seconds to avoid races
125
124
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
127
126
self .log .info ("Tx should be received at node 1 after {} seconds" .format (timeout ))
128
127
self .sync_mempools (timeout = timeout )
129
128
130
129
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 )]
133
132
134
133
p = self .nodes [0 ].p2ps [0 ]
135
134
@@ -138,22 +137,22 @@ def test_in_flight_max(self):
138
137
139
138
mock_time = int (time .time () + 1 )
140
139
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 ):
142
141
p .send_message (msg_inv ([CInv (t = MSG_WTX , h = txids [i ])]))
143
142
p .sync_with_ping ()
144
- mock_time += INBOUND_PEER_TX_DELAY
143
+ mock_time += NONPREF_PEER_TX_DELAY
145
144
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 )):
148
147
p .send_message (msg_inv ([CInv (t = MSG_WTX , h = txids [i ])]))
149
148
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 )
152
151
p .sync_with_ping ()
153
152
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 )
157
156
p .wait_until (lambda : p .tx_getdata_count == len (txids ))
158
157
159
158
def test_expiry_fallback (self ):
0 commit comments