lightningd: expose created_index and updated_index fields.

If you miss a wait event, you can catch up by doing listinvoices and
getting the max of these fields.  It's also a good debugging clue.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-07-22 20:29:17 +09:30
parent 284262d006
commit d25a8ca0fd
27 changed files with 559 additions and 325 deletions

View File

@@ -727,6 +727,8 @@ def test_wait_invoices(node_factory, executor):
'details': {'label': 'invlabel',
'bolt11': inv['bolt11'],
'status': 'unpaid'}}
assert only_one(l2.rpc.listinvoices('invlabel')['invoices'])['created_index'] == 1
assert 'updated_index' not in only_one(l2.rpc.listinvoices('invlabel')['invoices'])
# Second returns instantly, without any details.
waitres = l2.rpc.call('wait', {'subsystem': 'invoices', 'indexname': 'created', 'nextvalue': 1})
@@ -745,6 +747,8 @@ def test_wait_invoices(node_factory, executor):
assert waitres == {'subsystem': 'invoices',
'updated': 1,
'details': {'label': 'invlabel', 'status': 'paid'}}
assert only_one(l2.rpc.listinvoices('invlabel')['invoices'])['created_index'] == 1
assert only_one(l2.rpc.listinvoices('invlabel')['invoices'])['updated_index'] == 1
# Second returns instantly, without any details.
waitres = l2.rpc.call('wait', {'subsystem': 'invoices', 'indexname': 'updated', 'nextvalue': 1})
@@ -761,6 +765,9 @@ def test_wait_invoices(node_factory, executor):
# {'label': 'invlabel2', 'bolt11': inv2['bolt11'], 'status': 'expired'}
'details': {'status': 'expired'}}
assert only_one(l2.rpc.listinvoices('invlabel2')['invoices'])['created_index'] == 2
assert only_one(l2.rpc.listinvoices('invlabel2')['invoices'])['updated_index'] == 2
# Now for deletions
waitres = l2.rpc.call('wait', {'subsystem': 'invoices', 'indexname': 'deleted', 'nextvalue': 0})
assert waitres == {'subsystem': 'invoices',
@@ -804,6 +811,8 @@ def test_wait_invoices(node_factory, executor):
'details': {'label': 'invlabel2',
'bolt11': inv['bolt11'],
'status': 'unpaid'}}
assert only_one(l2.rpc.listinvoices('invlabel2')['invoices'])['created_index'] == 3
assert 'updated_index' not in only_one(l2.rpc.listinvoices('invlabel2')['invoices'])
# Deleting a description causes updated to fire!
waitfut = executor.submit(l2.rpc.call, 'wait', {'subsystem': 'invoices', 'indexname': 'updated', 'nextvalue': 3})
@@ -884,6 +893,14 @@ def test_listinvoices_index(node_factory, executor):
# They're all still there!
assert set([inv['label'] for inv in l2.rpc.listinvoices(index='updated')['invoices']]) == set([str(i) for i in range(1, 100)])
# index values are correct.
for inv in l2.rpc.listinvoices(index='updated')['invoices']:
assert inv['created_index'] == int(inv['label'])
if int(inv['label']) in range(70, 60, -1):
assert inv['updated_index'] == 70 - int(inv['label']) + 1
else:
assert 'updated_index' not in inv
# Last 10 are in a defined order:
assert [inv['label'] for inv in l2.rpc.listinvoices(index='updated', start=1)['invoices']] == [str(i) for i in range(70, 60, -1)]
assert [inv['label'] for inv in l2.rpc.listinvoices(index='updated', start=2)['invoices']] == [str(i) for i in range(69, 60, -1)]

View File

@@ -1017,6 +1017,7 @@ def test_cli(node_factory):
' "amount_msat": 123000,',
' "status": "unpaid",',
r' "description": "d\"[]{}",',
' "created_index": 1',
' }',
' ]',
'}']

View File

@@ -3679,6 +3679,10 @@ def test_sql(node_factory, bitcoind):
'type': 'hex'},
{'name': 'invreq_payer_note',
'type': 'string'},
{'name': 'created_index',
'type': 'u64'},
{'name': 'updated_index',
'type': 'u64'},
{'name': 'pay_index',
'type': 'u64'},
{'name': 'amount_received_msat',