Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions test/functional/feature_governance.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,18 @@ def sync_gov(node):
assert_equal(self.nodes[0].gobject("list", "valid", "triggers")[isolated_trigger_hash]['NoCount'], self.mn_count - 1)

block_count = self.nodes[0].getblockcount()
n = sb_cycle - block_count % sb_cycle
n = sb_immaturity_window - block_count % sb_cycle
assert n > 0

self.log.info("Move remaining n blocks until the next Superblock")
for _ in range(n - 1):
self.log.info("Move remaining n blocks until the next maturity window")
self.bump_mocktime(n)
self.generate(self.nodes[0], n, sync_fun=self.sync_blocks())

self.log.info("Move inside maturity window until the next Superblock")
for _ in range(sb_maturity_window - 1):
self.bump_mocktime(1)
self.generate(self.nodes[0], 1, sync_fun=self.sync_blocks())
self.wait_until(lambda: have_trigger_for_height(self.nodes, 180), timeout=1, do_assert=False)
self.log.info("Wait for new trigger and votes")
self.wait_until(lambda: have_trigger_for_height(self.nodes, 180))
self.log.info("Mine superblock")
Expand All @@ -365,11 +371,14 @@ def sync_gov(node):

self.log.info("Mine and check a couple more superblocks")
for i in range(2):
for _ in range(sb_cycle - 1):
sb_block_height = 180 + (i + 1) * sb_cycle
self.bump_mocktime(sb_immaturity_window)
self.generate(self.nodes[0], sb_immaturity_window, sync_fun=self.sync_blocks())
for _ in range(sb_maturity_window - 1):
self.bump_mocktime(1)
self.generate(self.nodes[0], 1, sync_fun=self.sync_blocks())
self.wait_until(lambda: have_trigger_for_height(self.nodes, sb_block_height), timeout=1, do_assert=False)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: lambda captures sb_block_height from the loop iteration. Python's late binding means this works correctly only because wait_until is evaluated before the loop variable changes. Consider using a default argument if this pattern is reused elsewhere. Is there a risk that the lambda will capture the wrong sb_block_height if wait_until is deferred or if the loop iteration completes before evaluation?

Prompt To Fix With AI
This is a comment left during a code review.
Path: test/functional/feature_governance.py
Line: 382:382

Comment:
**style:** lambda captures `sb_block_height` from the loop iteration. Python's late binding means this works correctly only because `wait_until` is evaluated before the loop variable changes. Consider using a default argument if this pattern is reused elsewhere. Is there a risk that the lambda will capture the wrong `sb_block_height` if `wait_until` is deferred or if the loop iteration completes before evaluation?

How can I resolve this? If you propose a fix, please make it concise.

# Wait for new trigger and votes
sb_block_height = 180 + (i + 1) * sb_cycle
self.wait_until(lambda: have_trigger_for_height(self.nodes, sb_block_height))
# Mine superblock
self.bump_mocktime(1)
Expand Down
Loading