pytest: fix flake when htlc_timeout_tx gets short sig:
What changed, and why it matters
This commit fixes a flaky test in Core Lightning's accounting test suite. The test sometimes failed because the amount of 'change' returned from a specific Bitcoin transaction could vary slightly depending on the signature length. The fix makes the test read the actual transaction output value from the blockchain instead of hardcoding an expected value. There is no security issue here—only a test reliability improvement.
No security action needed. This is a test-only fix improving CI reliability.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is in tests/test_coinmoves.py, inside test_coinmoves_unilateral_htlc_timeout. Previously the test hardcoded an expected HTLC timeout change amount of (15579000 + 6358000) - anchor_change_msats, assuming a fixed signature length. When the DER signature happens to be shorter (a normal, random occurrence), the change output increases to 6366000 msat, causing a test flake. The patch queries bitcoind.rpc.gettxout(htlc_timeout_txid, 1)[‘value’] at runtime and uses that value for both credit_msat and output_msat, eliminating the hardcoded assumption.
Changed components
tests/test_coinmoves.pyInspect captured patch +4 / −2
diff --git a/tests/test_coinmoves.py b/tests/test_coinmoves.py
index 2abd765e..291f857b 100644
--- a/tests/test_coinmoves.py
+++ b/tests/test_coinmoves.py
@@ -894,6 +894,8 @@ def test_coinmoves_unilateral_htlc_timeout(node_factory, bitcoind):
line = l1.daemon.wait_for_log('Resolved OUR_UNILATERAL/OUR_HTLC by our proposal OUR_HTLC_TIMEOUT_TX')
htlc_timeout_txid = re.search(r'by our proposal OUR_HTLC_TIMEOUT_TX \(([0-9a-f]{64})\)', line).group(1)
+ # Usually 6358000, but if we're lucky it's 6366000.
+ htlc_timeout_change_msats = bitcoind.rpc.gettxout(htlc_timeout_txid, 1)['value'] * 100_000_000_000
expected_chain1 += [{'account_id': 'wallet',
'blockheight': 115,
'credit_msat': 0,
@@ -906,10 +908,10 @@ def test_coinmoves_unilateral_htlc_timeout(node_factory, bitcoind):
# Change
{'account_id': 'wallet',
'blockheight': 115,
- 'credit_msat': (15579000 + 6358000) - anchor_change_msats,
+ 'credit_msat': htlc_timeout_change_msats,
'debit_msat': 0,
'extra_tags': [],
- 'output_msat': (15579000 + 6358000) - anchor_change_msats,
+ 'output_msat': htlc_timeout_change_msats,
'primary_tag': 'deposit',
'utxo': f"{htlc_timeout_txid}:1"},
{'account_id': fundchannel['channel_id'],
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.