Skip to content

Commit bf9617c

Browse files
committed
Merge #2948: [Tests] Actually wait for nodes to connect
5f8c06e test: Add possibility to skip awaiting for the connection (Alessandro Rezzi) 5374229 Merge bitcoin#30252: test: Remove redundant verack check (merge-script) e7c21c7 Merge bitcoin#30118: test: improve robustness of connect_nodes() (Ava Chow) 9beef8d Merge bitcoin#26854: test: Fix intermittent timeout in p2p_permissions.py (MarcoFalke) b3a3d78 Merge bitcoin#25443: test: Fail if connect_nodes fails (laanwj) 72709b9 test: Avoid connecting a peer to himself (Alessandro Rezzi) 77697b8 test: Do not connect the nodes in parallel (Alessandro Rezzi) 17c065d test: Avoid race after connect_nodes (MarcoFalke) d73ac82 test: refactor connect_nodes and disconnect_nodes to take two indices instead of index + node (Alessandro Rezzi) e19d72f Merge bitcoin#18866: test: Fix verack race to avoid intermittent test failures (MarcoFalke) Pull request description: This PR solves the failures of `wallet_listtransactions.py`, like the one of https://github.com/PIVX-Project/PIVX/actions/runs/11705208154/job/32601252220?pr=2947. They happen due to mempool sync timeout: ``` 2024-11-06T14:58:03.8489793Z AssertionError: Mempool sync timed out after 60s: 2024-11-06T14:58:03.8490785Z {'7364836e7eae24a75378b920373e303b99b4ff18db758defc4c057d784a43905'} ``` The issue is that the connection between nodes is established after the transaction is sent, as we can see from the logs: ``` 2024-11-06T14:58:03.9085473Z 2024-11-06T14:57:02Z (mocktime: 2019-10-31T18:21:20Z) Relaying wtx 7364836e7eae24a75378b920373e303b99b4ff18db758defc4c057d784a43905 ... 2024-11-06T14:58:03.9103287Z 2024-11-06T14:57:02Z (mocktime: 2019-10-31T18:21:20Z) New outbound peer connected: version: 70927, blocks=200, peer=0 ``` Hence the newly connected node will never receive the transaction and the mempool will never be synced. This bug is fixed by ensuring that `connect_nodes` actually wait for the connection to be established. As a consequence of those checks we cannot anymore connect nodes in parallel in `connect_nodes_clique` (which will make tests run slightly slower) ACKs for top commit: 5f8c06e Fuzzbawls: utACK 5f8c06e Duddino: utACK 5f8c06e Liquid369: tACK 5f8c06e Tree-SHA512: 88007d7302f3b7c3c5b9d446e7d8acc959cd03b0bb27409b1633cb86c57905a4814be148e2e5f6ccaa1da17eccdd44f68f81d00299696d1f47f52f9b12b32ec7
2 parents c6818fd + 5f8c06e commit bf9617c

37 files changed

+186
-219
lines changed

test/functional/example_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from test_framework.test_framework import PivxTestFramework
2727
from test_framework.util import (
2828
assert_equal,
29-
connect_nodes,
3029
wait_until,
3130
)
3231

@@ -111,7 +110,7 @@ def setup_network(self):
111110
# In this test, we're not connecting node2 to node0 or node1. Calls to
112111
# sync_all() should not include node2, since we're not expecting it to
113112
# sync.
114-
connect_nodes(self.nodes[0], 1)
113+
self.connect_nodes(0, 1)
115114
self.sync_all(self.nodes[0:1])
116115

117116
# Use setup_nodes() to customize the node start behaviour (for example if
@@ -182,7 +181,7 @@ def run_test(self):
182181
self.nodes[1].waitforblockheight(11)
183182

184183
self.log.info("Connect node2 and node1")
185-
connect_nodes(self.nodes[1], 2)
184+
self.connect_nodes(1, 2)
186185

187186
self.log.info("Add P2P connection to node2")
188187
self.nodes[0].disconnect_p2ps()

test/functional/feature_abortnode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import os
1414

1515
from test_framework.test_framework import PivxTestFramework
16-
from test_framework.util import wait_until, get_datadir_path, connect_nodes
16+
from test_framework.util import wait_until, get_datadir_path
1717

1818

1919
class AbortNodeTest(PivxTestFramework):
@@ -37,7 +37,7 @@ def run_test(self):
3737
# attempt.
3838
self.nodes[1].generate(3)
3939
with self.nodes[0].assert_debug_log(["Failed to disconnect block"]):
40-
connect_nodes(self.nodes[0], 1)
40+
self.connect_nodes(0, 1)
4141
self.nodes[1].generate(1)
4242

4343
# Check that node0 aborted

test/functional/feature_fee_estimation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from test_framework.messages import CTransaction, CTxIn, CTxOut, COutPoint, ToHex, COIN
1111
from test_framework.script import CScript, OP_1, OP_DROP, OP_2, OP_HASH160, OP_EQUAL, hash160, OP_TRUE
1212
from test_framework.test_framework import PivxTestFramework
13-
from test_framework.util import connect_nodes, satoshi_round
13+
from test_framework.util import satoshi_round
1414

1515

1616
# Use as minTxFee
@@ -247,9 +247,9 @@ def run_test(self):
247247
# so the estimates would not be affected by the splitting transactions
248248
self.start_node(1)
249249
self.start_node(2)
250-
connect_nodes(self.nodes[1], 0)
251-
connect_nodes(self.nodes[0], 2)
252-
connect_nodes(self.nodes[2], 1)
250+
self.connect_nodes(1, 0)
251+
self.connect_nodes(0, 2)
252+
self.connect_nodes(2, 1)
253253

254254
self.sync_all()
255255

test/functional/feature_minchainwork.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import time
1919

2020
from test_framework.test_framework import PivxTestFramework
21-
from test_framework.util import connect_nodes, assert_equal
21+
from test_framework.util import assert_equal
2222

2323

2424
# 2 hashes required per regtest block (with no difficulty adjustment)
@@ -40,7 +40,7 @@ def setup_network(self):
4040
# block relay to inbound peers.
4141
self.setup_nodes()
4242
for i in range(self.num_nodes-1):
43-
connect_nodes(self.nodes[i+1], i)
43+
self.connect_nodes(i+1, i)
4444

4545
def run_test(self):
4646
# Start building a chain on node0. node2 shouldn't be able to sync until node1's

test/functional/feature_notifications.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
from test_framework.test_framework import PivxTestFramework
1010
from test_framework.util import (
1111
assert_equal,
12-
wait_until,
13-
connect_nodes,
12+
wait_until
1413
)
1514

1615

@@ -66,7 +65,7 @@ def run_test(self):
6665
self.log.info("test -walletnotify after rescan")
6766
# restart node to rescan to force wallet notifications
6867
self.start_node(1)
69-
connect_nodes(self.nodes[0], 1)
68+
self.connect_nodes(0, 1)
7069

7170
wait_until(lambda: len(os.listdir(self.walletnotify_dir)) == block_count, timeout=10)
7271

test/functional/interface_rest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import urllib.parse
1414

1515
from test_framework.test_framework import PivxTestFramework
16-
from test_framework.util import assert_equal, assert_greater_than, connect_nodes, hex_str_to_bytes
16+
from test_framework.util import assert_equal, assert_greater_than, hex_str_to_bytes
1717

1818

1919
def deser_uint256(f):
@@ -52,7 +52,7 @@ def set_test_params(self):
5252

5353
def setup_network(self, split=False):
5454
super().setup_network()
55-
connect_nodes(self.nodes[0], 2)
55+
self.connect_nodes(0, 2)
5656

5757
def run_test(self):
5858
url = urllib.parse.urlparse(self.nodes[0].url)

test/functional/mining_pos_reorg.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
from test_framework.util import (
88
assert_equal,
99
assert_raises_rpc_error,
10-
connect_nodes,
11-
connect_nodes_clique,
12-
disconnect_nodes,
1310
set_node_times,
1411
DecimalAmt,
1512
)
@@ -28,7 +25,7 @@ def setup_chain(self):
2825
def setup_network(self):
2926
# connect all nodes between each other
3027
self.setup_nodes()
31-
connect_nodes_clique(self.nodes)
28+
self.connect_nodes_clique(self.nodes)
3229
self.sync_all()
3330

3431
def log_title(self):
@@ -42,7 +39,7 @@ def disconnect_all(self):
4239
for i in range(self.num_nodes):
4340
for j in range(self.num_nodes):
4441
if j != i:
45-
disconnect_nodes(self.nodes[i], j)
42+
self.disconnect_nodes(i, j)
4643
self.log.info("Nodes disconnected")
4744

4845
def get_tot_balance(self, nodeid):
@@ -109,7 +106,7 @@ def findUtxoInList(txid, vout, utxo_list):
109106

110107
# Connect with node 2 and sync
111108
self.log.info("Reconnecting node 0 and node 2")
112-
connect_nodes(self.nodes[0], 2)
109+
self.connect_nodes(0, 2)
113110
self.sync_blocks([self.nodes[i] for i in [0, 2]])
114111

115112
# verify that the stakeinput can't be spent
@@ -140,7 +137,7 @@ def findUtxoInList(txid, vout, utxo_list):
140137
new_best_hash = self.nodes[1].getbestblockhash()
141138
self.log.info("Connecting and syncing nodes...")
142139
set_node_times(self.nodes, self.mocktime)
143-
connect_nodes_clique(self.nodes)
140+
self.connect_nodes_clique(self.nodes)
144141
self.sync_blocks()
145142
for i in [0, 2]:
146143
assert_equal(self.nodes[i].getbestblockhash(), new_best_hash)

test/functional/p2p_disconnect_ban.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from test_framework.test_framework import PivxTestFramework
1010
from test_framework.util import (
1111
assert_equal,
12-
connect_nodes,
1312
assert_raises_rpc_error,
1413
wait_until,
1514
)
@@ -21,8 +20,8 @@ def set_test_params(self):
2120

2221
def run_test(self):
2322
self.log.info("Connect nodes both way")
24-
connect_nodes(self.nodes[0], 1)
25-
connect_nodes(self.nodes[1], 0)
23+
self.connect_nodes(0, 1)
24+
self.connect_nodes(1, 0)
2625

2726
self.log.info("Test setban and listbanned RPCs")
2827

@@ -81,8 +80,8 @@ def run_test(self):
8180
# Clear ban lists
8281
self.nodes[1].clearbanned()
8382
self.log.info("Connect nodes both way")
84-
connect_nodes(self.nodes[0], 1)
85-
connect_nodes(self.nodes[1], 0)
83+
self.connect_nodes(0, 1)
84+
self.connect_nodes(1, 0)
8685

8786
self.log.info("Test disconnectnode RPCs")
8887

@@ -101,7 +100,7 @@ def run_test(self):
101100
assert not [node for node in self.nodes[0].getpeerinfo() if node['addr'] == address1]
102101

103102
self.log.info("disconnectnode: successfully reconnect node")
104-
connect_nodes(self.nodes[0], 1) # reconnect the node
103+
self.connect_nodes(0, 1) # reconnect the node
105104
assert_equal(len(self.nodes[0].getpeerinfo()), 2)
106105
assert [node for node in self.nodes[0].getpeerinfo() if node['addr'] == address1]
107106

test/functional/p2p_quorum_connect.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from test_framework.messages import msg_version
1414
from test_framework.util import (
1515
assert_equal,
16-
connect_nodes,
1716
hash256,
1817
wait_until,
1918
)
@@ -174,7 +173,7 @@ def run_test(self):
174173
self.clean_conns_and_disconnect(mn6_node)
175174

176175
# Create the regular connection
177-
connect_nodes(mn5_node, mn6.idx)
176+
self.connect_nodes(mn5.idx, mn6.idx)
178177
self.wait_for_peers_count([mn5_node], 1)
179178
assert self.has_single_regular_connection(mn5_node)
180179
assert self.has_single_regular_connection(mn6_node)

test/functional/p2p_sendheaders.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
)
8989
from test_framework.mininode import mininode_lock, NetworkThread, P2PInterface
9090
from test_framework.test_framework import PivxTestFramework
91-
from test_framework.util import assert_equal, wait_until, connect_nodes, p2p_port
91+
from test_framework.util import assert_equal, wait_until, p2p_port
9292
9393
9494
direct_fetch_response_time = 0.05
@@ -242,7 +242,7 @@ def __init__(self):
242242
def setup_network(self):
243243
self.nodes = []
244244
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, [["-debug", "-logtimemicros=1"]]*2)
245-
connect_nodes(self.nodes[0], 1)
245+
self.connect_nodes(0, 1)
246246
247247
# mine count blocks and return the new tip
248248
def mine_blocks(self, count):

0 commit comments

Comments
 (0)