Skip to content

Commit 82ebba1

Browse files
authored
Few fixes for wait_for_instantlock (#3123)
* Fix `wait_for_instantlock` to make it fail if instantlock wasn't aquired, use `wait_until` Currently it simply returns False if islock failed but that's not the way we use it (we never check results). * Wait for txes to propagate before checking for instantlock
1 parent 7ba50d9 commit 82ebba1

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

test/functional/llmq-is-cl-conflicts.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from test_framework.blocktools import get_masternode_payment, create_coinbase, create_block
1010
from test_framework.mininode import *
1111
from test_framework.test_framework import DashTestFramework
12-
from test_framework.util import sync_blocks, p2p_port, assert_raises_rpc_error, set_node_times
12+
from test_framework.util import sync_blocks, sync_mempools, p2p_port, assert_raises_rpc_error, set_node_times
1313

1414
'''
1515
llmq-is-cl-conflicts.py
@@ -102,6 +102,8 @@ def test_chainlock_overrides_islock(self, test_block_conflict):
102102
rawtx4 = self.nodes[0].signrawtransaction(rawtx4)['hex']
103103
rawtx4_txid = self.nodes[0].sendrawtransaction(rawtx4)
104104

105+
# wait for transactions to propagate
106+
sync_mempools(self.nodes)
105107
for node in self.nodes:
106108
self.wait_for_instantlock(rawtx1_txid, node)
107109
self.wait_for_instantlock(rawtx4_txid, node)
@@ -143,6 +145,8 @@ def test_chainlock_overrides_islock(self, test_block_conflict):
143145
rawtx5 = self.nodes[0].createrawtransaction(inputs, {self.nodes[0].getnewaddress(): 0.999})
144146
rawtx5 = self.nodes[0].signrawtransaction(rawtx5)['hex']
145147
rawtx5_txid = self.nodes[0].sendrawtransaction(rawtx5)
148+
# wait for the transaction to propagate
149+
sync_mempools(self.nodes)
146150
for node in self.nodes:
147151
self.wait_for_instantlock(rawtx5_txid, node)
148152

test/functional/p2p-instantsend.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from test_framework.mininode import *
77
from test_framework.test_framework import DashTestFramework
8-
from test_framework.util import isolate_node, set_node_times, reconnect_isolated_node, assert_equal, \
8+
from test_framework.util import isolate_node, sync_mempools, set_node_times, reconnect_isolated_node, assert_equal, \
99
assert_raises_rpc_error
1010

1111
'''
@@ -50,9 +50,12 @@ def test_block_doublespend(self):
5050
# instantsend to receiver
5151
receiver_addr = receiver.getnewaddress()
5252
is_id = sender.sendtoaddress(receiver_addr, 0.9)
53-
for node in self.nodes:
54-
if node is not isolated:
55-
self.wait_for_instantlock(is_id, node)
53+
# wait for the transaction to propagate
54+
connected_nodes = self.nodes.copy()
55+
del connected_nodes[self.isolated_idx]
56+
sync_mempools(connected_nodes)
57+
for node in connected_nodes:
58+
self.wait_for_instantlock(is_id, node)
5659
# send doublespend transaction to isolated node
5760
isolated.sendrawtransaction(dblspnd_tx['hex'])
5861
# generate block on isolated node with doublespend transaction
@@ -109,6 +112,8 @@ def test_mempool_doublespend(self):
109112
# TX from other nodes.
110113
receiver_addr = receiver.getnewaddress()
111114
is_id = sender.sendtoaddress(receiver_addr, 0.9)
115+
# wait for the transaction to propagate
116+
sync_mempools(self.nodes)
112117
for node in self.nodes:
113118
self.wait_for_instantlock(is_id, node)
114119
assert_raises_rpc_error(-5, "No such mempool or blockchain transaction", isolated.getrawtransaction, dblspnd_txid)

test/functional/test_framework/test_framework.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
sync_blocks,
3939
sync_mempools,
4040
sync_masternodes,
41-
wait_to_sync)
41+
wait_to_sync,
42+
wait_until,
43+
)
4244

4345
class TestStatus(Enum):
4446
PASSED = 1
@@ -687,22 +689,12 @@ def create_raw_tx(self, node_from, node_to, amount, min_inputs, max_inputs):
687689
return ret
688690

689691
def wait_for_instantlock(self, txid, node):
690-
# wait for instantsend locks
691-
start = time.time()
692-
locked = False
693-
while True:
692+
def check_instantlock():
694693
try:
695-
is_tx = node.getrawtransaction(txid, True)
696-
if is_tx['instantlock']:
697-
locked = True
698-
break
694+
return node.getrawtransaction(txid, True)["instantlock"]
699695
except:
700-
# TX not received yet?
701-
pass
702-
if time.time() > start + 10:
703-
break
704-
time.sleep(0.5)
705-
return locked
696+
return False
697+
wait_until(check_instantlock, timeout=10, sleep=0.5)
706698

707699
def wait_for_sporks_same(self, timeout=30):
708700
st = time.time()

0 commit comments

Comments
 (0)