pytest: fix coinmoves flake, where routing credit/debit can appear in either order.

It's done as HTLCs finalize, but we can close the incoming HTLC as soon as we get the
preimage, so that entire thing could finish before the outgoing HTLC.

```
>       check_channel_moves(l1, expected_channel1)

tests/test_coinmoves.py:307: 
...
E         Full diff:
E           [
E               {
E                   'account_id': '58d371ab100e0ea847a11c9550add273ef8531bc12bb51b0e30c8f833506a772',
E                   'created_index': 1,
E                   'credit_msat': 0,
E                   'debit_msat': 1000000,
E                   'fees_msat': 0,
E                   'group_id': 1318196858430961660,
E                   'part_id': 1,
E                   'payment_hash': '8da829ab29715106a4e767facc0b58776ae5bfc11c4e9dcda3063013e1ef8ef0',
E                   'primary_tag': 'invoice',
E               },
E               {
E                   'account_id': '0b872506f67b363803cd85cf9ff6807ebc1dc8a4521aa191386b4c5366d490d7',
E                   'created_index': 2,
E                   'credit_msat': 100000,
E                   'debit_msat': 0,
E                   'fees_msat': 0,
E                   'primary_tag': 'pushed',
E               },
E               {
E         +         'account_id': '0b872506f67b363803cd85cf9ff6807ebc1dc8a4521aa191386b4c5366d490d7',
E         +         'created_index': 3,
E         +         'credit_msat': 10000100001,
E         +         'debit_msat': 0,
E         +         'fees_msat': 100001,
E         +         'payment_hash': '0ebfa5387de5fd12c15089833b0193fb6007e9f494ec24d479e327a96ac8e8c0',
E         +         'primary_tag': 'routed',
E         +     },
E         +     {
E                   'account_id': '58d371ab100e0ea847a11c9550add273ef8531bc12bb51b0e30c8f833506a772',
E         -         'created_index': 3,
E         ?                          ^
E         +         'created_index': 4,
E         ?                          ^
E                   'credit_msat': 0,
E                   'debit_msat': 10000000000,
E                   'fees_msat': 100001,
E                   'payment_hash': '0ebfa5387de5fd12c15089833b0193fb6007e9f494ec24d479e327a96ac8e8c0',
E                   'primary_tag': 'routed',
E               },
E         -     {
E         -         'account_id': '0b872506f67b363803cd85cf9ff6807ebc1dc8a4521aa191386b4c5366d490d7',
E         -         'created_index': 4,
E         -         'credit_msat': 10000100001,
E         -         'debit_msat': 0,
E         -         'fees_msat': 100001,
E         -         'payment_hash': '0ebfa5387de5fd12c15089833b0193fb6007e9f494ec24d479e327a96ac8e8c0',
E         -         'primary_tag': 'routed',
E         -     },
E           ]
```
This commit is contained in:
Rusty Russell
2026-01-08 11:49:56 +10:30
parent 25bad01bbe
commit 3d59af6f98

View File

@@ -286,18 +286,35 @@ def test_coinmoves(node_factory, bitcoind):
l3.rpc.xpay(inv['bolt11'], '10000000sat')
# Make sure it's fully settled.
wait_for(lambda: only_one(l3.rpc.listpeerchannels(l1.info['id'])['channels'])['htlcs'] == [])
expected_channel1 += [{'account_id': fundchannel['channel_id'],
'credit_msat': 0,
'debit_msat': 10000000000,
'fees_msat': 100001,
'payment_hash': inv['payment_hash'],
'primary_tag': 'routed'},
{'account_id': l3fundchannel['channel_id'],
'credit_msat': 10000100001,
'debit_msat': 0,
'fees_msat': 100001,
'payment_hash': inv['payment_hash'],
'primary_tag': 'routed'}]
# These can actually go in either order, since we record them when HTLC is *fully*
# resolved.
wait_for(lambda: len(l1.rpc.listchannelmoves()['channelmoves']) > len(expected_channel1))
if l1.rpc.listchannelmoves()['channelmoves'][len(expected_channel1)]['credit_msat'] == 0:
expected_channel1 += [{'account_id': fundchannel['channel_id'],
'credit_msat': 0,
'debit_msat': 10000000000,
'fees_msat': 100001,
'payment_hash': inv['payment_hash'],
'primary_tag': 'routed'},
{'account_id': l3fundchannel['channel_id'],
'credit_msat': 10000100001,
'debit_msat': 0,
'fees_msat': 100001,
'payment_hash': inv['payment_hash'],
'primary_tag': 'routed'}]
else:
expected_channel1 += [{'account_id': l3fundchannel['channel_id'],
'credit_msat': 10000100001,
'debit_msat': 0,
'fees_msat': 100001,
'payment_hash': inv['payment_hash'],
'primary_tag': 'routed'},
{'account_id': fundchannel['channel_id'],
'credit_msat': 0,
'debit_msat': 10000000000,
'fees_msat': 100001,
'payment_hash': inv['payment_hash'],
'primary_tag': 'routed'}]
expected_channel2 += [{'account_id': fundchannel['channel_id'],
'credit_msat': 10000000000,
'debit_msat': 0,