Skip to content

Commit 8494ca6

Browse files
committed
pytest: fix flake in test_peer_anchor_push
If l3 does a short signature, our feerate will also be wrong. Adjust check_feerate to take a range of nodes for this case. ``` > check_feerate(l2, total_feerate_perkw, feerate) tests/test_closing.py:4054: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ node = <fixtures.LightningNode object at 0x7fd7e2cbfb20> actual_feerate = 14006.105538595726, expected_feerate = 14000 def check_feerate(node, actual_feerate, expected_feerate): # Feerate can't be lower. assert actual_feerate > expected_feerate - 2 if not did_short_sig(node): > assert actual_feerate < expected_feerate + 2 E AssertionError tests/utils.py:675: AssertionError ```
1 parent 3a0a02c commit 8494ca6

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

tests/test_closing.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3987,7 +3987,9 @@ def test_peer_anchor_push(node_factory, bitcoind, executor, chainparams):
39873987
{'min-emergency-msat': 546000,
39883988
'dev-warn-on-overgrind': None,
39893989
'broken_log': 'overgrind: short signature length'},
3990-
{'disconnect': ['-WIRE_UPDATE_FULFILL_HTLC']}],
3990+
{'disconnect': ['-WIRE_UPDATE_FULFILL_HTLC'],
3991+
'dev-warn-on-overgrind': None,
3992+
'broken_log': 'overgrind: short signature length'}],
39913993
wait_for_announce=True)
39923994

39933995
# We splinter l2's funds so it's forced to use more than one UTXO to push.
@@ -4051,7 +4053,7 @@ def test_peer_anchor_push(node_factory, bitcoind, executor, chainparams):
40514053
total_weight = sum([d['weight'] for d in details])
40524054
total_fees = sum([float(d['fees']['base']) * 100_000_000 for d in details])
40534055
total_feerate_perkw = total_fees / total_weight * 1000
4054-
check_feerate(l2, total_feerate_perkw, feerate)
4056+
check_feerate([l3, l2], total_feerate_perkw, feerate)
40554057
bitcoind.generate_block(1, needfeerate=16000)
40564058
sync_blockheight(bitcoind, [l2])
40574059
assert len(bitcoind.rpc.getrawmempool()) == 2

tests/test_wallet.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def test_txprepare(node_factory, bitcoind, chainparams):
328328
assert len(decode['vin']) == 4
329329
assert len(decode['vout']) == 2 if not chainparams['feeoutput'] else 3
330330
if not chainparams['elements']: # FIXME
331-
check_feerate(l1, feerate_from_psbt(chainparams, bitcoind, l1, prep['psbt']), normal_feerate_perkw)
331+
check_feerate([l1], feerate_from_psbt(chainparams, bitcoind, l1, prep['psbt']), normal_feerate_perkw)
332332

333333
# One output will be correct.
334334
outnum = [i for i, o in enumerate(decode['vout']) if o['value'] == Decimal(amount * 3) / 10**8][0]
@@ -357,7 +357,7 @@ def test_txprepare(node_factory, bitcoind, chainparams):
357357
assert decode['vout'][0]['scriptPubKey']['type'] == 'witness_v0_keyhash'
358358
assert scriptpubkey_addr(decode['vout'][0]['scriptPubKey']) == addr
359359
if not chainparams['elements']: # FIXME
360-
check_feerate(l1, feerate_from_psbt(chainparams, bitcoind, l1, prep2['psbt']), normal_feerate_perkw)
360+
check_feerate([l1], feerate_from_psbt(chainparams, bitcoind, l1, prep2['psbt']), normal_feerate_perkw)
361361

362362
# If I cancel the first one, I can get those first 4 outputs.
363363
discard = l1.rpc.txdiscard(prep['txid'])
@@ -377,7 +377,7 @@ def test_txprepare(node_factory, bitcoind, chainparams):
377377
assert decode['vout'][0]['scriptPubKey']['type'] == 'witness_v0_keyhash'
378378
assert scriptpubkey_addr(decode['vout'][0]['scriptPubKey']) == addr
379379
if not chainparams['elements']: # FIXME
380-
check_feerate(l1, feerate_from_psbt(chainparams, bitcoind, l1, prep3['psbt']), normal_feerate_perkw)
380+
check_feerate([l1], feerate_from_psbt(chainparams, bitcoind, l1, prep3['psbt']), normal_feerate_perkw)
381381

382382
# Cannot discard twice.
383383
with pytest.raises(RpcError, match=r'not an unreleased txid'):
@@ -399,7 +399,7 @@ def test_txprepare(node_factory, bitcoind, chainparams):
399399
assert decode['vout'][0]['scriptPubKey']['type'] == 'witness_v0_keyhash'
400400
assert scriptpubkey_addr(decode['vout'][0]['scriptPubKey']) == addr
401401
if not chainparams['elements']: # FIXME
402-
check_feerate(l1, feerate_from_psbt(chainparams, bitcoind, l1, prep4['psbt']), normal_feerate_perkw)
402+
check_feerate([l1], feerate_from_psbt(chainparams, bitcoind, l1, prep4['psbt']), normal_feerate_perkw)
403403
l1.rpc.txdiscard(prep4['txid'])
404404

405405
# Try passing in a utxo set
@@ -408,7 +408,7 @@ def test_txprepare(node_factory, bitcoind, chainparams):
408408
prep5 = l1.rpc.txprepare([{addr:
409409
Millisatoshi(amount * 3.5 * 1000)}], utxos=utxos)
410410
if not chainparams['elements']: # FIXME
411-
check_feerate(l1, feerate_from_psbt(chainparams, bitcoind, l1, prep3['psbt']), normal_feerate_perkw)
411+
check_feerate([l1], feerate_from_psbt(chainparams, bitcoind, l1, prep3['psbt']), normal_feerate_perkw)
412412

413413
# Try passing unconfirmed utxos
414414
unconfirmed_utxo = l1.rpc.withdraw(l1.rpc.newaddr()["bech32"], 10**5)
@@ -420,7 +420,7 @@ def test_txprepare(node_factory, bitcoind, chainparams):
420420
unconfirmed_tx = bitcoind.rpc.getrawmempool(True)[unconfirmed_utxo["txid"]]
421421
feerate_perkw = int(unconfirmed_tx['fees']['base'] * 100_000_000) * 1000 / unconfirmed_tx['weight']
422422
if not chainparams['elements']: # FIXME
423-
check_feerate(l1, feerate_perkw, normal_feerate_perkw)
423+
check_feerate([l1], feerate_perkw, normal_feerate_perkw)
424424

425425
decode = bitcoind.rpc.decoderawtransaction(prep5['unsigned_tx'])
426426
assert decode['txid'] == prep5['txid']
@@ -451,7 +451,7 @@ def test_txprepare(node_factory, bitcoind, chainparams):
451451
{addr: 'all'}])
452452
# Feerate should be ~ as we asked for
453453
if not chainparams['elements']: # FIXME
454-
check_feerate(l1, feerate_from_psbt(chainparams, bitcoind, l1, prep5['psbt']), normal_feerate_perkw)
454+
check_feerate([l1], feerate_from_psbt(chainparams, bitcoind, l1, prep5['psbt']), normal_feerate_perkw)
455455
l1.rpc.txdiscard(prep5['txid'])
456456
with pytest.raises(RpcError, match=r"'all'"):
457457
prep5 = l1.rpc.txprepare([{addr: 'all'}, {addr: 'all'}])
@@ -460,7 +460,7 @@ def test_txprepare(node_factory, bitcoind, chainparams):
460460
{addr: Millisatoshi(amount * 3 * 500 - 100000)}])
461461
# Feerate should be ~ as we asked for
462462
if not chainparams['elements']: # FIXME
463-
check_feerate(l1, feerate_from_psbt(chainparams, bitcoind, l1, prep5['psbt']), normal_feerate_perkw)
463+
check_feerate([l1], feerate_from_psbt(chainparams, bitcoind, l1, prep5['psbt']), normal_feerate_perkw)
464464
decode = bitcoind.rpc.decoderawtransaction(prep5['unsigned_tx'])
465465
assert decode['txid'] == prep5['txid']
466466
# 4 inputs, 3 outputs(include change).
@@ -574,7 +574,7 @@ def test_fundpsbt_feerates(node_factory, bitcoind, chainparams, addrtype):
574574
# We never actually added that `amount` output to PSBT, so that appears as "fee"
575575
fee = int(txinfo['fees']['base'] * 100_000_000) - amount
576576
actual_feerate = fee / (txinfo['weight'] / 1000)
577-
check_feerate(l1, actual_feerate, feerate)
577+
check_feerate([l1], actual_feerate, feerate)
578578

579579

580580
def test_reserveinputs(node_factory, bitcoind, chainparams):

tests/utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,11 @@ def did_short_sig(node):
668668
return node.daemon.is_in_log('overgrind: short signature length')
669669

670670

671-
def check_feerate(node, actual_feerate, expected_feerate):
671+
def check_feerate(nodes, actual_feerate, expected_feerate):
672672
# Feerate can't be lower.
673673
assert actual_feerate > expected_feerate - 2
674-
if not did_short_sig(node):
675-
assert actual_feerate < expected_feerate + 2
674+
if actual_feerate >= expected_feerate + 2:
675+
if any([did_short_sig(n) for n in nodes]):
676+
return
677+
# Use assert as it shows the actual values on failure
678+
assert actual_feerate < expected_feerate + 2

0 commit comments

Comments
 (0)