Skip to content

Commit

Permalink
pytest: fix flake in test_htlc_in_timeout with anchors.
Browse files Browse the repository at this point in the history
If we try to reuse the same UTXO for the HTLC as the anchor, it will clash.
One block later we can spend the anchor change, all good.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Feb 7, 2024
1 parent bbf6a89 commit a005ec1
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,14 @@ def test_htlc_out_timeout(node_factory, bitcoind, executor):
# We hit deadline (we give 1 block grace), then mined another.
assert blocks2 == -2

bitcoind.generate_block(1, wait_for_mempool=txid)
# If we try to reuse the same output as we used for the anchor spend, then
# bitcoind can reject it. In that case we'll try again after we get change
# from anchor spend.
if txid not in bitcoind.rpc.getrawmempool():
bitcoind.generate_block(1)
bitcoind.generate_block(1, wait_for_mempool=1)
else:
bitcoind.generate_block(1)

rawtx, txid, blocks = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
'OUR_HTLC_TIMEOUT_TX/DELAYED_OUTPUT_TO_US')
Expand Down Expand Up @@ -424,7 +431,16 @@ def test_htlc_in_timeout(node_factory, bitcoind, executor):
_, txid, blocks = l2.wait_for_onchaind_tx('OUR_HTLC_SUCCESS_TX',
'OUR_UNILATERAL/THEIR_HTLC')
assert blocks == 0
bitcoind.generate_block(1, wait_for_mempool=txid)

# If we try to reuse the same output as we used for the anchor spend, then
# bitcoind can reject it. In that case we'll try again after we get change
# from anchor spend.
if txid not in bitcoind.rpc.getrawmempool():
bitcoind.generate_block(1)
bitcoind.generate_block(1, wait_for_mempool=1)
else:
bitcoind.generate_block(1)

rawtx, txid, blocks = l2.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
'OUR_HTLC_SUCCESS_TX/DELAYED_OUTPUT_TO_US')
assert blocks == 4
Expand Down

0 comments on commit a005ec1

Please sign in to comment.