Skip to content

Commit 356cdf1

Browse files
committed
tests: fix test_htlc_no_force_close flake
l3 was watching its own (censored) commitment tx, so it can take a while before it notices l2's commitment is the one onchain and tries to fulfill the HTLC. If we released the censored txs before that, we only broadcast l3's own commitment txs, which conflict with l2's already-mined commitment and are rejected, leaving the mempool empty and making the final generate_block(wait_for_mempool=1) time out. Wait for l3's fulfill attempt (a tx spending an output of l2's commitment) before releasing. Also release only those txs, deduped by txid and in capture order, so duplicate or RBF fulfill attempts are not broadcast as stale versions. Changelog-None
1 parent 836b4e8 commit 356cdf1

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

‎tests/test_closing.py‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4377,11 +4377,30 @@ def censoring_sendrawtx(r):
43774377

43784378
# Now, surprise! l3 fulfills htlc (l2 loses out!)
43794379
assert htlc_txs != []
4380+
# l3 was watching its own (censored) commitment tx, so it takes a while
4381+
# before it notices l2's commitment is the one onchain and tries to fulfill
4382+
# the HTLC by spending its HTLC output. Wait for that attempt before we
4383+
# release the censored txs, otherwise we only broadcast l3's own commitment
4384+
# txs, which conflict with l2's (already mined) commitment and are rejected.
4385+
commit_txid = only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels'])['scratch_txid']
4386+
wait_for(lambda: any(vin['txid'] == commit_txid
4387+
for tx in htlc_txs
4388+
for vin in bitcoind.rpc.decoderawtransaction(tx)['vin']))
4389+
4390+
# l3 can try the fulfill more than once (it rebroadcasts the same tx, or
4391+
# RBFs it if the feerate estimate changed), so keep only the txs spending
4392+
# l2's commitment, deduped by txid and in capture order (so a later RBF
4393+
# version replaces an earlier one). l3's own commitment txs conflict with
4394+
# l2's mined commitment and can never be mined, so don't bother releasing
4395+
# them.
4396+
fulfill_txs = {}
43804397
for tx in htlc_txs:
4381-
try:
4382-
bitcoind.rpc.sendrawtransaction(tx)
4383-
except bitcoin.rpc.VerifyError:
4384-
pass
4398+
d = bitcoind.rpc.decoderawtransaction(tx)
4399+
if any(vin['txid'] == commit_txid for vin in d['vin']):
4400+
fulfill_txs[d['txid']] = tx
4401+
4402+
for tx in fulfill_txs.values():
4403+
bitcoind.rpc.sendrawtransaction(tx)
43854404

43864405
# l2 should note this, but not crash, at least.
43874406
bitcoind.generate_block(1, wait_for_mempool=1)

0 commit comments

Comments
 (0)