Skip to content

Commit c79c2d9

Browse files
committed
refactor: improve is-waiting helper by including mempool sync bump of mocktime
1 parent a0e4260 commit c79c2d9

9 files changed

Lines changed: 34 additions & 67 deletions

test/functional/feature_asset_locks.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,7 @@ def test_asset_unlocks(self, node_wallet, node, pubkey):
391391

392392
assert_equal(node.getmempoolentry(txid)['fees']['base'], Decimal("0.0007"))
393393
is_id = node_wallet.sendtoaddress(node_wallet.getnewaddress(), 1)
394-
self.bump_mocktime(30)
395-
self.sync_mempools()
396-
for node in self.nodes:
397-
self.wait_for_instantlock(is_id, node)
394+
self.wait_for_instantlock(is_id)
398395

399396
rawtx = node.getrawtransaction(txid, 1)
400397
rawtx_is = node.getrawtransaction(is_id, 1)

test/functional/feature_llmq_is_cl_conflicts.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,7 @@ def test_chainlock_overrides_islock(self, test_block_conflict, mine_confllicting
9999
rawtx4_txid = self.nodes[0].sendrawtransaction(rawtx4)
100100

101101
# wait for transactions to propagate
102-
self.bump_mocktime(30)
103-
self.sync_mempools()
104-
for node in self.nodes:
105-
self.wait_for_instantlock(rawtx1_txid, node)
106-
self.wait_for_instantlock(rawtx4_txid, node)
102+
self.wait_for_instantlock(rawtx1_txid, rawtx4_txid)
107103

108104
block = create_block_with_mnpayments(self.mninfo, self.nodes[0], [rawtx2_obj])
109105
if test_block_conflict:
@@ -160,10 +156,7 @@ def test_chainlock_overrides_islock(self, test_block_conflict, mine_confllicting
160156
rawtx5 = self.nodes[0].signrawtransactionwithwallet(rawtx5)['hex']
161157
rawtx5_txid = self.nodes[0].sendrawtransaction(rawtx5)
162158
# wait for the transaction to propagate
163-
self.bump_mocktime(30)
164-
self.sync_mempools()
165-
for node in self.nodes:
166-
self.wait_for_instantlock(rawtx5_txid, node)
159+
self.wait_for_instantlock(rawtx5_txid)
167160

168161
if mine_confllicting:
169162
# Lets verify that the ISLOCKs got pruned and conflicting txes were mined but never confirmed
@@ -243,18 +236,15 @@ def test_chainlock_overrides_islock_overrides_nonchainlock(self):
243236
# Should drop tx1 and accept tx2 because there is an isdlock waiting for it
244237
self.nodes[0].sendrawtransaction(rawtx2)
245238
# bump mocktime to force tx relay
246-
self.bump_mocktime(60)
247-
self.sync_mempools()
248-
for node in self.nodes:
249-
self.wait_for_instantlock(rawtx2_txid, node)
239+
self.wait_for_instantlock(rawtx2_txid)
250240

251241
# Should not allow competing txes now
252242
assert_raises_rpc_error(-26, "tx-txlock-conflict", self.nodes[0].sendrawtransaction, rawtx1)
253243

254244
islock_tip = self.generate(self.nodes[0], 1)[0]
255245

246+
self.wait_for_instantlock(rawtx2_txid, skip_sync=True)
256247
for node in self.nodes:
257-
self.wait_for_instantlock(rawtx2_txid, node)
258248
assert_equal(node.getrawtransaction(rawtx2_txid, True)['confirmations'], 1)
259249
assert_equal(node.getbestblockhash(), islock_tip)
260250

test/functional/feature_llmq_is_retroactive.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def run_test(self):
6565
# We have to wait in order to include tx in block
6666
self.bump_mocktime(10 * 60 + 1)
6767
block = self.generate(self.nodes[0], 1, sync_fun=self.no_op)[0]
68-
self.wait_for_instantlock(txid, self.nodes[0])
68+
self.wait_for_instantlock(txid, nodes=[self.nodes[0]], skip_sync=True)
6969
self.nodes[0].sporkupdate("SPORK_19_CHAINLOCKS_ENABLED", 0)
7070
self.wait_for_sporks_same()
7171
self.wait_for_chainlocked_block_all_nodes(block)
@@ -78,9 +78,7 @@ def run_test(self):
7878
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
7979
# 3 nodes should be enough to create an IS lock even if nodes 4 and 5 (which have no tx itself)
8080
# are the only "neighbours" in intra-quorum connections for one of them.
81-
self.bump_mocktime(30)
82-
self.sync_mempools(self.nodes[:3])
83-
self.wait_for_instantlock(txid, self.nodes[0])
81+
self.wait_for_instantlock(txid, nodes=self.nodes[:3])
8482
block = self.generate(self.nodes[0], 1, sync_fun=self.no_op)[0]
8583
self.wait_for_chainlocked_block_all_nodes(block)
8684

@@ -101,7 +99,7 @@ def run_test(self):
10199
self.nodes[3].sendrawtransaction(self.nodes[0].getrawtransaction(txid))
102100
# node 3 should vote on a tx now since it became aware of it via sendrawtransaction
103101
# and this should be enough to complete an IS lock
104-
self.wait_for_instantlock(txid, self.nodes[0])
102+
self.wait_for_instantlock(txid, nodes=[self.nodes[0]], skip_sync=True)
105103

106104
self.log.info("testing retroactive signing with unknown TX")
107105
self.isolate_node(3)

test/functional/feature_llmq_singlenode.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ def run_test(self):
106106

107107
self.log.info("Send funds and wait InstantSend lock")
108108
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
109-
self.bump_mocktime(30)
110-
self.wait_for_instantlock(txid, self.nodes[0])
109+
self.wait_for_instantlock(txid, nodes=[self.nodes[0]])
111110

112111
self.log.info("Test various options to sign messages with nodes")
113112
recsig_time = self.mocktime
@@ -184,9 +183,8 @@ def run_test(self):
184183
self.log.info(f"Chainlock on block: {block_hash} is expecting")
185184
self.wait_for_best_chainlock(self.nodes[0], block_hash)
186185
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
187-
self.bump_mocktime(30)
188186
self.log.info(f"InstantSend lock on tx: {txid} is expecting")
189-
self.wait_for_instantlock(txid, self.nodes[0])
187+
self.wait_for_instantlock(txid, nodes=[self.nodes[0]])
190188

191189

192190
if __name__ == '__main__':

test/functional/feature_notifications.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,7 @@ def run_test(self):
139139
tx_count = 10
140140
for _ in range(tx_count):
141141
txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1)
142-
self.bump_mocktime(30)
143-
self.sync_mempools()
144-
self.wait_for_instantlock(txid, self.nodes[0])
142+
self.wait_for_instantlock(txid, nodes=[self.nodes[0]])
145143

146144
# wait at most 10 seconds for expected number of files before reading the content
147145
self.bump_mocktime(30)

test/functional/interface_zmq_dash.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,7 @@ def test_instantsend_publishers(self):
296296
assert_equal(['None'], self.nodes[0].getislocks([rpc_raw_tx_1['txid']]))
297297
# Send the first transaction and wait for the InstantLock
298298
rpc_raw_tx_1_hash = self.nodes[0].sendrawtransaction(rpc_raw_tx_1['hex'])
299-
self.bump_mocktime(30)
300-
self.sync_mempools()
301-
self.wait_for_instantlock(rpc_raw_tx_1_hash, self.nodes[0])
299+
self.wait_for_instantlock(rpc_raw_tx_1_hash)
302300
# Validate hashtxlock
303301
zmq_tx_lock_hash = self.subscribers[ZMQPublisher.hash_tx_lock].receive().read(32).hex()
304302
assert_equal(zmq_tx_lock_hash, rpc_raw_tx_1['txid'])
@@ -350,9 +348,7 @@ def test_instantsend_publishers(self):
350348
pass
351349
# Now send the tx itself
352350
self.test_node.send_tx(from_hex(msg_tx(),rpc_raw_tx_3['hex']))
353-
self.bump_mocktime(30)
354-
self.sync_mempools()
355-
self.wait_for_instantlock(rpc_raw_tx_3['txid'], self.nodes[0])
351+
self.wait_for_instantlock(rpc_raw_tx_3['txid'])
356352
# Validate hashtxlock
357353
zmq_tx_lock_hash = self.subscribers[ZMQPublisher.hash_tx_lock].receive().read(32).hex()
358354
assert_equal(zmq_tx_lock_hash, rpc_raw_tx_3['txid'])
@@ -385,9 +381,7 @@ def test_governance_publishers(self):
385381
}
386382
proposal_hex = ''.join(format(x, '02x') for x in json.dumps(proposal_data).encode())
387383
collateral = self.nodes[0].gobject("prepare", "0", proposal_rev, proposal_time, proposal_hex)
388-
self.bump_mocktime(30)
389-
self.sync_mempools()
390-
self.wait_for_instantlock(collateral, self.nodes[0])
384+
self.wait_for_instantlock(collateral, nodes=[self.nodes[0]])
391385
self.generate(self.nodes[0], 6, sync_fun=lambda: self.sync_blocks())
392386
rpc_proposal_hash = self.nodes[0].gobject("submit", "0", proposal_rev, proposal_time, proposal_hex, collateral)
393387
# Validate hashgovernanceobject

test/functional/p2p_instantsend.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ def test_block_doublespend(self):
4545
# feed the sender with some balance
4646
sender_addr = sender.getnewaddress()
4747
is_id = self.nodes[0].sendtoaddress(sender_addr, 1)
48-
self.bump_mocktime(30)
49-
self.sync_mempools()
50-
for node in self.nodes:
51-
self.wait_for_instantlock(is_id, node)
48+
self.wait_for_instantlock(is_id)
5249
self.generate(self.nodes[0], 2)
5350

5451
# create doublespending transaction, but don't relay it
@@ -61,10 +58,7 @@ def test_block_doublespend(self):
6158
# wait for the transaction to propagate
6259
connected_nodes = self.nodes.copy()
6360
del connected_nodes[self.isolated_idx]
64-
self.sync_mempools(connected_nodes)
65-
self.bump_mocktime(30)
66-
for node in connected_nodes:
67-
self.wait_for_instantlock(is_id, node)
61+
self.wait_for_instantlock(is_id, nodes=connected_nodes)
6862
# send doublespend transaction to isolated node
6963
dblspnd_txid = isolated.sendrawtransaction(dblspnd_tx['hex'])
7064
# generate block on isolated node with doublespend transaction
@@ -106,10 +100,7 @@ def test_mempool_doublespend(self):
106100
# feed the sender with some balance
107101
sender_addr = sender.getnewaddress()
108102
is_id = self.nodes[0].sendtoaddress(sender_addr, 1)
109-
self.bump_mocktime(30)
110-
self.sync_mempools()
111-
for node in self.nodes:
112-
self.wait_for_instantlock(is_id, node)
103+
self.wait_for_instantlock(is_id)
113104
self.generate(self.nodes[0], 2)
114105

115106
# create doublespending transaction, but don't relay it
@@ -130,17 +121,11 @@ def test_mempool_doublespend(self):
130121
receiver_addr = receiver.getnewaddress()
131122
is_id = sender.sendtoaddress(receiver_addr, 0.9)
132123
# wait for the transaction to propagate
133-
self.bump_mocktime(30)
134-
self.sync_mempools()
135-
for node in self.nodes:
136-
self.wait_for_instantlock(is_id, node)
124+
self.wait_for_instantlock(is_id)
137125
assert dblspnd_txid not in set(isolated.getrawmempool())
138126
# send coins back to the controller node without waiting for confirmations
139127
sentback_id = receiver.sendtoaddress(self.nodes[0].getnewaddress(), 0.9, "", "", True)
140-
self.bump_mocktime(30)
141-
self.sync_mempools()
142-
for node in self.nodes:
143-
self.wait_for_instantlock(sentback_id, node)
128+
self.wait_for_instantlock(sentback_id)
144129
assert_equal(receiver.getwalletinfo()["balance"], 0)
145130
# mine more blocks
146131
self.generate(self.nodes[0], 2)

test/functional/rpc_verifyislock.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ def run_test(self):
4141
self.generate(self.nodes[0], 8, sync_fun=self.sync_blocks())
4242

4343
txid = node.sendtoaddress(node.getnewaddress(), 1)
44-
self.bump_mocktime(30)
45-
self.sync_mempools()
46-
self.wait_for_instantlock(txid, node)
44+
self.wait_for_instantlock(txid, nodes=[node])
4745

4846
request_id = self.get_request_id(self.nodes[0].getrawtransaction(txid))
4947
request_id_rpc = self.nodes[0].getislocks([txid])[0]["id"]

test/functional/test_framework/test_framework.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,17 +1945,26 @@ def create_isdlock(self, hextx):
19451945
return isdlock
19461946

19471947
# due to privacy reasons random delay is used before sending transaction by network
1948-
# most times is just 2-5 seconds, but once in 1000 it's up to 1000 seconds.
1949-
# it's recommended to bump mocktime for 30 seconds before wait_for_instantlock
1950-
def wait_for_instantlock(self, txid, node, timeout=60):
1948+
# most times it's just 2-5 seconds, but once in 1000 times it's up to 10 seconds and has no bound from the top.
1949+
def wait_for_instantlock(self, *txids, nodes=None, timeout=60, skip_sync=False):
1950+
nodes = nodes or self.nodes
1951+
1952+
if not skip_sync:
1953+
self.bump_mocktime(30)
1954+
self.sync_mempools(nodes)
1955+
1956+
self.log.info(f"Expecting InstantLock for {list(txids)}")
19511957

19521958
def check_instantlock():
19531959
try:
1954-
return node.getrawtransaction(txid, True)["instantlock"]
1960+
return all(
1961+
node.getrawtransaction(txid, True)["instantlock"]
1962+
for txid in txids
1963+
for node in nodes
1964+
)
19551965
except Exception:
19561966
return False
19571967

1958-
self.log.info(f"Expecting InstantLock for {txid}")
19591968
self.wait_until(check_instantlock, timeout=timeout)
19601969

19611970
def wait_for_chainlocked_block(self, node, block_hash, expected=True, timeout=15):

0 commit comments

Comments
 (0)