pytest: fix flake in test_closing_anchorspend_htlc_tx_rbf
What changed, and why it matters
This commit fixes a flaky automated test in Core Lightning. The test was occasionally failing because of tiny floating-point rounding differences when calculating transaction fees, not because of a real bug or security issue. The change replaces a strict hand-rolled tolerance check with a more forgiving helper function already designed for this purpose. There is no security impact.
No security action needed. This is a test-only flake fix. Reviewers may optionally verify that check_feerate's ±2 tolerance and did_short_sig escape hatch are appropriate for the test's intent.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies tests/test_closing.py in the test_closing_anchorspend_htlc_tx_rbf test. It removes the did_short_sig helper import and replaces two assertions of the form assert did_short_sig(l1) or target - 1 < total_feerate_perkw < target + 1 with calls to check_feerate([l1], total_feerate_perkw, target). The commit message explains that the previous fix (#9027) misdiagnosed the flakiness as signature-length variation; the actual cause is deterministic floating-point rounding in fees / weight * 1000 for this specific transaction structure. This is purely a test robustness change.
Changed components
tests/test_closing.pytest_closing_anchorspend_htlc_tx_rbfInspect captured patch +3 / −3
diff --git a/tests/test_closing.py b/tests/test_closing.py
index 63ff6ad..8ff587a 100644
--- a/tests/test_closing.py
+++ b/tests/test_closing.py
@@ -8,7 +8,7 @@ from utils import (
scriptpubkey_addr, calc_lease_fee,
check_utxos_channel, check_coin_moves,
mine_funding_to_announce, check_inspect_channel,
- first_scid, check_feerate, did_short_sig
+ first_scid, check_feerate
)
from typing import List, Optional
@@ -3836,7 +3836,7 @@ def test_closing_anchorspend_htlc_tx_rbf(node_factory, bitcoind):
total_weight = sum([d['weight'] for d in details])
total_fees = sum([float(d['fees']['base']) * 100_000_000 for d in details])
total_feerate_perkw = total_fees / total_weight * 1000
- assert did_short_sig(l1) or 2000 - 1 < total_feerate_perkw < 2000 + 1
+ check_feerate([l1], total_feerate_perkw, 2000)
# But we don't mine it! And fees go up again!
l1.set_feerates((3000, 3000, 3000, 3000))
@@ -3851,7 +3851,7 @@ def test_closing_anchorspend_htlc_tx_rbf(node_factory, bitcoind):
total_weight = sum([d['weight'] for d in details])
total_fees = sum([float(d['fees']['base']) * 100_000_000 for d in details])
total_feerate_perkw = total_fees / total_weight * 1000
- assert did_short_sig(l1) or 3000 - 1 < total_feerate_perkw < 3000 + 1
+ check_feerate([l1], total_feerate_perkw, 3000)
# And now we'll get it in (there's some rounding, so feerate a bit lower!)
bitcoind.generate_block(1, needfeerate=2990)
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.