Skip to content

Commit 71ef10a

Browse files
committed
test: fix intermittent failures in p2p_instantsend.py and others
It bumps mocktime properly for all instantsend lock Dash Core sends transactions after random delay for privacy reason. tx_relay->m_next_inv_send_time = GetExponentialRand(current_time, OUTBOUND_INVENTORY_BROADCAST_INTERVAL) This expential random delay once in 1000 tries is longer than 2s * 10 = 20 seconds To be sure that helper wait_for_instantsend is reliable need to bump mocktime for 20+ second, or even better 30 seconds
1 parent 067aa25 commit 71ef10a

File tree

9 files changed

+28
-9
lines changed

9 files changed

+28
-9
lines changed

test/functional/feature_asset_locks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ def test_asset_unlocks(self, node_wallet, node, pubkey):
377377
txid = self.send_tx(asset_unlock_tx)
378378
assert_equal(node.getmempoolentry(txid)['fees']['base'], Decimal("0.0007"))
379379
is_id = node_wallet.sendtoaddress(node_wallet.getnewaddress(), 1)
380+
self.bump_mocktime(30)
380381
for node in self.nodes:
381382
self.wait_for_instantlock(is_id, node)
382383

test/functional/feature_llmq_is_cl_conflicts.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def test_chainlock_overrides_islock(self, test_block_conflict, mine_confllicting
9696
rawtx4_txid = self.nodes[0].sendrawtransaction(rawtx4)
9797

9898
# wait for transactions to propagate
99+
self.bump_mocktime(30)
99100
self.sync_mempools()
100101
for node in self.nodes:
101102
self.wait_for_instantlock(rawtx1_txid, node)
@@ -156,6 +157,7 @@ def test_chainlock_overrides_islock(self, test_block_conflict, mine_confllicting
156157
rawtx5 = self.nodes[0].signrawtransactionwithwallet(rawtx5)['hex']
157158
rawtx5_txid = self.nodes[0].sendrawtransaction(rawtx5)
158159
# wait for the transaction to propagate
160+
self.bump_mocktime(30)
159161
self.sync_mempools()
160162
for node in self.nodes:
161163
self.wait_for_instantlock(rawtx5_txid, node)

test/functional/feature_llmq_is_retroactive.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def run_test(self):
3939
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
4040
# 3 nodes should be enough to create an IS lock even if nodes 4 and 5 (which have no tx itself)
4141
# are the only "neighbours" in intra-quorum connections for one of them.
42+
self.bump_mocktime(30)
4243
self.wait_for_instantlock(txid, self.nodes[0], False, 5)
4344
# Have to disable ChainLocks to avoid signing a block with a "safe" tx too early
4445
self.nodes[0].sporkupdate("SPORK_19_CHAINLOCKS_ENABLED", 4000000000)
@@ -59,8 +60,8 @@ def run_test(self):
5960
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
6061
# 3 nodes should be enough to create an IS lock even if nodes 4 and 5 (which have no tx itself)
6162
# are the only "neighbours" in intra-quorum connections for one of them.
63+
self.bump_mocktime(30)
6264
self.wait_for_instantlock(txid, self.nodes[0])
63-
self.bump_mocktime(1)
6465
block = self.generate(self.nodes[0], 1, sync_fun=self.no_op)[0]
6566
self.wait_for_chainlocked_block_all_nodes(block)
6667

@@ -180,10 +181,10 @@ def test_single_node_session_timeout(self, do_cycle_llmqs):
180181
# Make sure nodes 1 and 2 received the TX
181182
self.wait_for_tx(txid, self.nodes[1])
182183
self.wait_for_tx(txid, self.nodes[2])
184+
self.bump_mocktime(30)
183185
# Make sure signing is done on nodes 1 and 2 (it's async)
184-
time.sleep(5)
185186
# node 3 fully reconnected but the signing session is already timed out on it, so no IS lock
186-
self.wait_for_instantlock(txid, self.nodes[0], False, 1)
187+
self.wait_for_instantlock(txid, self.nodes[0], False, 5)
187188
if do_cycle_llmqs:
188189
self.cycle_llmqs()
189190
self.wait_for_instantlock(txid, self.nodes[0], False, 5)

test/functional/feature_llmq_singlenode.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def run_test(self):
104104

105105
self.log.info("Send funds and wait InstantSend lock")
106106
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
107+
self.bump_mocktime(30)
107108
self.wait_for_instantlock(txid, self.nodes[0])
108109

109110
self.log.info("Test various options to sign messages with nodes")
@@ -181,6 +182,7 @@ def run_test(self):
181182
self.log.info(f"Chainlock on block: {block_hash} is expecting")
182183
self.wait_for_best_chainlock(self.nodes[0], block_hash)
183184
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
185+
self.bump_mocktime(30)
184186
self.log.info(f"InstantSend lock on tx: {txid} is expecting")
185187
self.wait_for_instantlock(txid, self.nodes[0])
186188

test/functional/feature_notifications.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,11 @@ def run_test(self):
132132
tx_count = 10
133133
for _ in range(tx_count):
134134
txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1)
135-
self.wait_for_instantlock(txid, self.nodes[1])
135+
self.bump_mocktime(30)
136+
self.wait_for_instantlock(txid, self.nodes[0])
136137

137138
# wait at most 10 seconds for expected number of files before reading the content
139+
self.bump_mocktime(30)
138140
self.wait_until(lambda: len(os.listdir(self.instantsendnotify_dir)) == tx_count, timeout=10)
139141

140142
# directory content should equal the generated transaction hashes

test/functional/interface_zmq_dash.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ def test_instantsend_publishers(self):
293293
assert_equal(['None'], self.nodes[0].getislocks([rpc_raw_tx_1['txid']]))
294294
# Send the first transaction and wait for the InstantLock
295295
rpc_raw_tx_1_hash = self.nodes[0].sendrawtransaction(rpc_raw_tx_1['hex'])
296+
self.bump_mocktime(30)
296297
self.wait_for_instantlock(rpc_raw_tx_1_hash, self.nodes[0])
297298
# Validate hashtxlock
298299
zmq_tx_lock_hash = self.subscribers[ZMQPublisher.hash_tx_lock].receive().read(32).hex()
@@ -345,6 +346,7 @@ def test_instantsend_publishers(self):
345346
pass
346347
# Now send the tx itself
347348
self.test_node.send_tx(from_hex(msg_tx(),rpc_raw_tx_3['hex']))
349+
self.bump_mocktime(30)
348350
self.wait_for_instantlock(rpc_raw_tx_3['txid'], self.nodes[0])
349351
# Validate hashtxlock
350352
zmq_tx_lock_hash = self.subscribers[ZMQPublisher.hash_tx_lock].receive().read(32).hex()
@@ -378,6 +380,7 @@ def test_governance_publishers(self):
378380
}
379381
proposal_hex = ''.join(format(x, '02x') for x in json.dumps(proposal_data).encode())
380382
collateral = self.nodes[0].gobject("prepare", "0", proposal_rev, proposal_time, proposal_hex)
383+
self.bump_mocktime(30)
381384
self.wait_for_instantlock(collateral, self.nodes[0])
382385
self.generate(self.nodes[0], 6, sync_fun=lambda: self.sync_blocks())
383386
rpc_proposal_hash = self.nodes[0].gobject("submit", "0", proposal_rev, proposal_time, proposal_hex, collateral)

test/functional/p2p_instantsend.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def test_block_doublespend(self):
4242
# feed the sender with some balance
4343
sender_addr = sender.getnewaddress()
4444
is_id = self.nodes[0].sendtoaddress(sender_addr, 1)
45+
self.bump_mocktime(30)
4546
for node in self.nodes:
4647
self.wait_for_instantlock(is_id, node)
47-
self.bump_mocktime(1)
4848
self.generate(self.nodes[0], 2)
4949

5050
# create doublespending transaction, but don't relay it
@@ -58,6 +58,7 @@ def test_block_doublespend(self):
5858
connected_nodes = self.nodes.copy()
5959
del connected_nodes[self.isolated_idx]
6060
self.sync_mempools(connected_nodes)
61+
self.bump_mocktime(30)
6162
for node in connected_nodes:
6263
self.wait_for_instantlock(is_id, node)
6364
# send doublespend transaction to isolated node
@@ -101,9 +102,9 @@ def test_mempool_doublespend(self):
101102
# feed the sender with some balance
102103
sender_addr = sender.getnewaddress()
103104
is_id = self.nodes[0].sendtoaddress(sender_addr, 1)
105+
self.bump_mocktime(30)
104106
for node in self.nodes:
105107
self.wait_for_instantlock(is_id, node)
106-
self.bump_mocktime(1)
107108
self.generate(self.nodes[0], 2)
108109

109110
# create doublespending transaction, but don't relay it
@@ -124,18 +125,19 @@ def test_mempool_doublespend(self):
124125
receiver_addr = receiver.getnewaddress()
125126
is_id = sender.sendtoaddress(receiver_addr, 0.9)
126127
# wait for the transaction to propagate
128+
self.bump_mocktime(30)
127129
self.sync_mempools()
128130
for node in self.nodes:
129131
self.wait_for_instantlock(is_id, node)
130132
assert dblspnd_txid not in set(isolated.getrawmempool())
131133
# send coins back to the controller node without waiting for confirmations
132134
sentback_id = receiver.sendtoaddress(self.nodes[0].getnewaddress(), 0.9, "", "", True)
135+
self.bump_mocktime(30)
133136
self.sync_mempools()
134137
for node in self.nodes:
135138
self.wait_for_instantlock(sentback_id, node)
136139
assert_equal(receiver.getwalletinfo()["balance"], 0)
137140
# mine more blocks
138-
self.bump_mocktime(1)
139141
self.generate(self.nodes[0], 2)
140142

141143
if __name__ == '__main__':

test/functional/rpc_verifyislock.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def run_test(self):
3838
self.generate(self.nodes[0], 8, sync_fun=self.sync_blocks())
3939

4040
txid = node.sendtoaddress(node.getnewaddress(), 1)
41+
self.bump_mocktime(30)
4142
self.wait_for_instantlock(txid, node)
4243

4344
request_id = self.get_request_id(self.nodes[0].getrawtransaction(txid))

test/functional/test_framework/test_framework.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,7 @@ def make_change(from_node, amount_in, amount_out, fee):
19031903
ret = {**decoded, **ret}
19041904
return ret
19051905

1906+
# TODO: move it to feature_llmq_is_retroactive.py
19061907
def wait_for_tx(self, txid, node, expected=True, timeout=60):
19071908
def check_tx():
19081909
try:
@@ -1935,15 +1936,19 @@ def create_isdlock(self, hextx):
19351936

19361937
return isdlock
19371938

1939+
# due to privacy reasons random delay is used before sending transaction by network
1940+
# most times is just 2-5 seconds, but once in 1000 it's up to 1000 seconds.
1941+
# it's recommended to bump mocktime for 30 seconds before wait_for_instantlock
19381942
def wait_for_instantlock(self, txid, node, expected=True, timeout=60):
1943+
19391944
def check_instantlock():
1940-
self.bump_mocktime(1)
19411945
try:
19421946
return node.getrawtransaction(txid, True)["instantlock"]
19431947
except:
19441948
return False
1949+
19451950
self.log.info(f"Expecting InstantLock for {txid}")
1946-
if self.wait_until(check_instantlock, timeout=timeout, sleep=1, do_assert=expected) and not expected:
1951+
if self.wait_until(check_instantlock, timeout=timeout, do_assert=expected) and not expected:
19471952
raise AssertionError("waiting unexpectedly succeeded")
19481953

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

0 commit comments

Comments
 (0)