Skip to content

Commit

Permalink
Merge bitcoin#29753: test: fix StopIteration exception in p2p_node_ne…
Browse files Browse the repository at this point in the history
…twork_limited.py

2eb5175 test: fix StopIteration exception in p2p_node_network_limited.py (furszy)

Pull request description:

  Fixes bitcoin#29731

  The `next()` call throws an exception if the default parameter is omitted and the iterator is exhausted.
  Fix it by providing a default value.

  The failure can be tested by commenting out lines 90 and 91 in the test (the `self.connect_nodes(2, 0)`). Since there is no connection, the node in question retrieves a single element in the 'getchaintips()' call. This scenario without the fix, aborts the test right away, throwing an `StopIteration` exception, and with the fix, the test properly waits until the timeout (`wait_until()` call).

ACKs for top commit:
  maflcko:
    review ACK 2eb5175
  brunoerg:
    crACK 2eb5175
  BrandonOdiwuor:
    crACK 2eb5175
  tdb3:
    Tested ACK for 2eb5175.

Tree-SHA512: b0873eb4d3334146fd250cd2cd23add3e744877033c8bfa4eb8dff36633100604adf49dd7846856ddfa88c9768663f095db705c00eef3641618df8fc13f8c2c5
  • Loading branch information
fanquake committed Apr 1, 2024
2 parents 948ecf1 + 2eb5175 commit 23ba394
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/functional/p2p_node_network_limited.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def test_avoid_requesting_historical_blocks(self):

# Wait until the full_node is headers-wise sync
best_block_hash = pruned_node.getbestblockhash()
self.wait_until(lambda: next(filter(lambda x: x['hash'] == best_block_hash, full_node.getchaintips()))['status'] == "headers-only")
default_value = {'status': ''} # No status
self.wait_until(lambda: next(filter(lambda x: x['hash'] == best_block_hash, full_node.getchaintips()), default_value)['status'] == "headers-only")

# Now, since the node aims to download a window of 1024 blocks,
# ensure it requests the blocks below the threshold only (with a
Expand Down

0 comments on commit 23ba394

Please sign in to comment.