Skip to content

Commit 14d1d8e

Browse files
committed
Merge bitcoin/bitcoin#31758: test: deduplicates p2p_tx_download constants
0a02e7f test: deduplicates p2p_tx_download constants (Sergi Delgado Segura) Pull request description: Some of the networking constants defined in p2p_tx_download.py are more generally defined in p2p.py ACKs for top commit: i-am-yuvi: re-ACK 0a02e7f maflcko: review ACK 0a02e7f 🔖 danielabrozzoni: re-ACK 0a02e7f tdb3: re ACK 0a02e7f Tree-SHA512: 05fc114a32b6b42a7c57563a38f1a8921e0bb224c4b124ae9d395c3a1105ae6e9cdfc62f603f4f2dee55cef5f6a6ed400d328740ad84fbd3093c5e0f3fb2982a
2 parents 2549fc6 + 0a02e7f commit 14d1d8e

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

test/functional/p2p_tx_download.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
from 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
)
2832
from test_framework.test_framework import BitcoinTestFramework
2933
from 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
5352
MAX_PEER_TX_ANNOUNCEMENTS = 5000
5453

5554
# Python test constants
5655
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
5857

5958
class ConnectionType(Enum):
6059
""" Different connection types
@@ -125,16 +124,16 @@ def test_inv_block(self):
125124
# * the first time it is re-requested from the outbound peer, plus
126125
# * 2 seconds to avoid races
127126
assert self.nodes[1].getpeerinfo()[0]['inbound'] == False
128-
timeout = 2 + INBOUND_PEER_TX_DELAY + GETDATA_TX_INTERVAL
127+
timeout = 2 + NONPREF_PEER_TX_DELAY + GETDATA_TX_INTERVAL
129128
self.log.info("Tx should be received at node 1 after {} seconds".format(timeout))
130129
self.nodes[0].bumpmocktime(timeout)
131130
self.sync_mempools()
132131

133132
self.nodes[0].setmocktime(0)
134133

135134
def test_in_flight_max(self):
136-
self.log.info("Test that we don't load peers with more than {} transaction requests immediately".format(MAX_GETDATA_IN_FLIGHT))
137-
txids = [i for i in range(MAX_GETDATA_IN_FLIGHT + 2)]
135+
self.log.info("Test that we don't load peers with more than {} transaction requests immediately".format(MAX_PEER_TX_REQUEST_IN_FLIGHT))
136+
txids = [i for i in range(MAX_PEER_TX_REQUEST_IN_FLIGHT + 2)]
138137

139138
p = self.nodes[0].p2ps[0]
140139

@@ -143,22 +142,22 @@ def test_in_flight_max(self):
143142

144143
mock_time = int(time.time() + 1)
145144
self.nodes[0].setmocktime(mock_time)
146-
for i in range(MAX_GETDATA_IN_FLIGHT):
145+
for i in range(MAX_PEER_TX_REQUEST_IN_FLIGHT):
147146
p.send_message(msg_inv([CInv(t=MSG_WTX, h=txids[i])]))
148147
p.sync_with_ping()
149-
mock_time += INBOUND_PEER_TX_DELAY
148+
mock_time += NONPREF_PEER_TX_DELAY
150149
self.nodes[0].setmocktime(mock_time)
151-
p.wait_until(lambda: p.tx_getdata_count >= MAX_GETDATA_IN_FLIGHT)
152-
for i in range(MAX_GETDATA_IN_FLIGHT, len(txids)):
150+
p.wait_until(lambda: p.tx_getdata_count >= MAX_PEER_TX_REQUEST_IN_FLIGHT)
151+
for i in range(MAX_PEER_TX_REQUEST_IN_FLIGHT, len(txids)):
153152
p.send_message(msg_inv([CInv(t=MSG_WTX, h=txids[i])]))
154153
p.sync_with_ping()
155-
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))
156-
self.nodes[0].setmocktime(mock_time + INBOUND_PEER_TX_DELAY + OVERLOADED_PEER_DELAY - 1)
154+
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))
155+
self.nodes[0].setmocktime(mock_time + NONPREF_PEER_TX_DELAY + OVERLOADED_PEER_TX_DELAY - 1)
157156
p.sync_with_ping()
158157
with p2p_lock:
159-
assert_equal(p.tx_getdata_count, MAX_GETDATA_IN_FLIGHT)
160-
self.log.info("If we wait {} seconds after announcement, we should eventually get more requests".format(INBOUND_PEER_TX_DELAY + OVERLOADED_PEER_DELAY))
161-
self.nodes[0].setmocktime(mock_time + INBOUND_PEER_TX_DELAY + OVERLOADED_PEER_DELAY)
158+
assert_equal(p.tx_getdata_count, MAX_PEER_TX_REQUEST_IN_FLIGHT)
159+
self.log.info("If we wait {} seconds after announcement, we should eventually get more requests".format(NONPREF_PEER_TX_DELAY + OVERLOADED_PEER_TX_DELAY))
160+
self.nodes[0].setmocktime(mock_time + NONPREF_PEER_TX_DELAY + OVERLOADED_PEER_TX_DELAY)
162161
p.wait_until(lambda: p.tx_getdata_count == len(txids))
163162

164163
def test_expiry_fallback(self):

0 commit comments

Comments
 (0)