Skip to content

Commit cd6c5b4

Browse files
authored
Multiple fixes for ChainLock tests (#3129)
* Add timeout params to wait_for*_chainlock methods * Give chainlocks more time in specific case * Add logs to llmq-chainlock.py * Replace wait_for_chainlocked_tip_all_nodes with wait_for_chainlocked_block_all_nodes wait_for_chainlocked_tip_all_nodes did wait for the tip of each individual node, which would not necessarily be the same. We should only allow to explicitly specify which block to wait for. * Get rid of wait_for_chainlocked_tip Same as with wait_for_chainlocked_tip_all_nodes
1 parent e06c116 commit cd6c5b4

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
lines changed

test/functional/llmq-chainlocks.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def set_test_params(self):
2222

2323
def run_test(self):
2424

25+
self.log.info("Wait for dip0008 activation")
26+
2527
while self.nodes[0].getblockchaininfo()["bip9_softforks"]["dip0008"]["status"] != "active":
2628
self.nodes[0].generate(10)
2729
sync_blocks(self.nodes, timeout=60*5)
@@ -30,97 +32,100 @@ def run_test(self):
3032
self.nodes[0].spork("SPORK_19_CHAINLOCKS_ENABLED", 0)
3133
self.wait_for_sporks_same()
3234

35+
self.log.info("Mining 4 quorums")
3336
for i in range(4):
3437
self.mine_quorum()
3538

36-
# mine single block, wait for chainlock
39+
self.log.info("Mine single block, wait for chainlock")
3740
self.nodes[0].generate(1)
38-
self.wait_for_chainlocked_tip_all_nodes()
41+
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash())
3942

40-
# mine many blocks, wait for chainlock
43+
self.log.info("Mine many blocks, wait for chainlock")
4144
self.nodes[0].generate(20)
42-
self.wait_for_chainlocked_tip_all_nodes()
45+
# We need more time here due to 20 blocks being generated at once
46+
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash(), timeout=30)
4347

44-
# assert that all blocks up until the tip are chainlocked
48+
self.log.info("Assert that all blocks up until the tip are chainlocked")
4549
for h in range(1, self.nodes[0].getblockcount()):
4650
block = self.nodes[0].getblock(self.nodes[0].getblockhash(h))
4751
assert(block['chainlock'])
4852

49-
# Isolate node, mine on another, and reconnect
53+
self.log.info("Isolate node, mine on another, and reconnect")
5054
isolate_node(self.nodes[0])
5155
node0_mining_addr = self.nodes[0].getnewaddress()
5256
node0_tip = self.nodes[0].getbestblockhash()
5357
self.nodes[1].generatetoaddress(5, node0_mining_addr)
54-
self.wait_for_chainlocked_tip(self.nodes[1])
58+
self.wait_for_chainlocked_block(self.nodes[1], self.nodes[1].getbestblockhash())
5559
assert(self.nodes[0].getbestblockhash() == node0_tip)
5660
reconnect_isolated_node(self.nodes[0], 1)
5761
self.nodes[1].generatetoaddress(1, node0_mining_addr)
5862
self.wait_for_chainlocked_block(self.nodes[0], self.nodes[1].getbestblockhash())
5963

60-
# Isolate node, mine on both parts of the network, and reconnect
64+
self.log.info("Isolate node, mine on both parts of the network, and reconnect")
6165
isolate_node(self.nodes[0])
6266
self.nodes[0].generate(5)
6367
self.nodes[1].generatetoaddress(1, node0_mining_addr)
6468
good_tip = self.nodes[1].getbestblockhash()
65-
self.wait_for_chainlocked_tip(self.nodes[1])
69+
self.wait_for_chainlocked_block(self.nodes[1], good_tip)
6670
assert(not self.nodes[0].getblock(self.nodes[0].getbestblockhash())["chainlock"])
6771
reconnect_isolated_node(self.nodes[0], 1)
6872
self.nodes[1].generatetoaddress(1, node0_mining_addr)
6973
self.wait_for_chainlocked_block(self.nodes[0], self.nodes[1].getbestblockhash())
7074
assert(self.nodes[0].getblock(self.nodes[0].getbestblockhash())["previousblockhash"] == good_tip)
7175
assert(self.nodes[1].getblock(self.nodes[1].getbestblockhash())["previousblockhash"] == good_tip)
7276

73-
# Keep node connected and let it try to reorg the chain
77+
self.log.info("Keep node connected and let it try to reorg the chain")
7478
good_tip = self.nodes[0].getbestblockhash()
75-
# Restart it so that it forgets all the chainlocks from the past
79+
self.log.info("Restart it so that it forgets all the chainlocks from the past")
7680
self.stop_node(0)
7781
self.start_node(0)
7882
connect_nodes(self.nodes[0], 1)
7983
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
80-
# Now try to reorg the chain
84+
self.log.info("Now try to reorg the chain")
8185
self.nodes[0].generate(2)
8286
time.sleep(6)
8387
assert(self.nodes[1].getbestblockhash() == good_tip)
8488
self.nodes[0].generate(2)
8589
time.sleep(6)
8690
assert(self.nodes[1].getbestblockhash() == good_tip)
8791

88-
# Now let the node which is on the wrong chain reorg back to the locked chain
92+
self.log.info("Now let the node which is on the wrong chain reorg back to the locked chain")
8993
self.nodes[0].reconsiderblock(good_tip)
9094
assert(self.nodes[0].getbestblockhash() != good_tip)
9195
self.nodes[1].generatetoaddress(1, node0_mining_addr)
9296
self.wait_for_chainlocked_block(self.nodes[0], self.nodes[1].getbestblockhash())
9397
assert(self.nodes[0].getbestblockhash() == self.nodes[1].getbestblockhash())
9498

95-
# Enable LLMQ bases InstantSend, which also enables checks for "safe" transactions
99+
self.log.info("Enable LLMQ bases InstantSend, which also enables checks for \"safe\" transactions")
96100
self.nodes[0].spork("SPORK_2_INSTANTSEND_ENABLED", 0)
97101
self.nodes[0].spork("SPORK_3_INSTANTSEND_BLOCK_FILTERING", 0)
98102
self.wait_for_sporks_same()
99103

100-
# Isolate a node and let it create some transactions which won't get IS locked
104+
self.log.info("Isolate a node and let it create some transactions which won't get IS locked")
101105
isolate_node(self.nodes[0])
102106
txs = []
103107
for i in range(3):
104108
txs.append(self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1))
105109
txs += self.create_chained_txs(self.nodes[0], 1)
106-
# Assert that after block generation these TXs are NOT included (as they are "unsafe")
110+
self.log.info("Assert that after block generation these TXs are NOT included (as they are \"unsafe\")")
107111
self.nodes[0].generate(1)
108112
for txid in txs:
109113
tx = self.nodes[0].getrawtransaction(txid, 1)
110114
assert("confirmations" not in tx)
111115
time.sleep(1)
112116
assert(not self.nodes[0].getblock(self.nodes[0].getbestblockhash())["chainlock"])
113-
# Disable LLMQ based InstantSend for a very short time (this never gets propagated to other nodes)
117+
self.log.info("Disable LLMQ based InstantSend for a very short time (this never gets propagated to other nodes)")
114118
self.nodes[0].spork("SPORK_2_INSTANTSEND_ENABLED", 4070908800)
115-
# Now the TXs should be included
119+
self.log.info("Now the TXs should be included")
116120
self.nodes[0].generate(1)
117121
self.nodes[0].spork("SPORK_2_INSTANTSEND_ENABLED", 0)
118-
# Assert that TXs got included now
122+
self.log.info("Assert that TXs got included now")
119123
for txid in txs:
120124
tx = self.nodes[0].getrawtransaction(txid, 1)
121125
assert("confirmations" in tx and tx["confirmations"] > 0)
122126
# Enable network on first node again, which will cause the blocks to propagate and IS locks to happen retroactively
123127
# for the mined TXs, which will then allow the network to create a CLSIG
128+
self.log.info("Reenable network on first node and wait for chainlock")
124129
reconnect_isolated_node(self.nodes[0], 1)
125130
self.wait_for_chainlocked_block(self.nodes[0], self.nodes[0].getbestblockhash(), 30)
126131

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def run_test(self):
7272

7373
# mine single block, wait for chainlock
7474
self.nodes[0].generate(1)
75-
self.wait_for_chainlocked_tip_all_nodes()
75+
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash())
7676

7777
self.test_chainlock_overrides_islock(False)
7878
self.test_chainlock_overrides_islock(True)

test/functional/test_framework/test_framework.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -705,16 +705,12 @@ def check_chainlocked_block():
705705
return False
706706
wait_until(check_chainlocked_block, timeout=timeout, sleep=0.1)
707707

708-
def wait_for_chainlocked_tip(self, node):
709-
tip = node.getbestblockhash()
710-
self.wait_for_chainlocked_block(node, tip)
711-
712-
def wait_for_chainlocked_tip_all_nodes(self):
708+
def wait_for_chainlocked_block_all_nodes(self, block_hash, timeout=15):
713709
for node in self.nodes:
714-
self.wait_for_chainlocked_tip(node)
710+
self.wait_for_chainlocked_block(node, block_hash, timeout)
715711

716-
def wait_for_best_chainlock(self, node, block_hash):
717-
wait_until(lambda: node.getbestchainlock()["blockhash"] == block_hash, timeout=15, sleep=0.1)
712+
def wait_for_best_chainlock(self, node, block_hash, timeout=15):
713+
wait_until(lambda: node.getbestchainlock()["blockhash"] == block_hash, timeout=timeout, sleep=0.1)
718714

719715
def wait_for_sporks_same(self, timeout=30):
720716
def check_sporks_same():

0 commit comments

Comments
 (0)