lightningd: trigger changed wait when delinvoice desconly used.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-07-22 17:16:17 +09:30
parent cbdfc75bde
commit 6782c2fef5
5 changed files with 43 additions and 8 deletions

View File

@ -1371,7 +1371,8 @@ static struct command_result *json_delinvoice(struct command *cmd,
return command_fail(cmd, INVOICE_NO_DESCRIPTION, return command_fail(cmd, INVOICE_NO_DESCRIPTION,
"Invoice description already removed"); "Invoice description already removed");
if (!invoices_delete_description(wallet->invoices, inv_dbid)) { if (!invoices_delete_description(wallet->invoices, inv_dbid,
details->label, details->description)) {
log_broken(cmd->ld->log, log_broken(cmd->ld->log,
"Error attempting to delete description of invoice %"PRIu64, "Error attempting to delete description of invoice %"PRIu64,
inv_dbid); inv_dbid);

View File

@ -374,7 +374,9 @@ bool invoices_delete(struct invoices *invoices UNNEEDED,
{ fprintf(stderr, "invoices_delete called!\n"); abort(); } { fprintf(stderr, "invoices_delete called!\n"); abort(); }
/* Generated stub for invoices_delete_description */ /* Generated stub for invoices_delete_description */
bool invoices_delete_description(struct invoices *invoices UNNEEDED, bool invoices_delete_description(struct invoices *invoices UNNEEDED,
u64 inv_dbid UNNEEDED) u64 inv_dbid UNNEEDED,
const struct json_escape *label UNNEEDED,
const char *description UNNEEDED)
{ fprintf(stderr, "invoices_delete_description called!\n"); abort(); } { fprintf(stderr, "invoices_delete_description called!\n"); abort(); }
/* Generated stub for invoices_delete_expired */ /* Generated stub for invoices_delete_expired */
void invoices_delete_expired(struct invoices *invoices UNNEEDED, void invoices_delete_expired(struct invoices *invoices UNNEEDED,

View File

@ -799,7 +799,7 @@ def test_wait_invoices(node_factory, executor):
# Creating a new on gives us 3, not another 2! # Creating a new on gives us 3, not another 2!
waitfut = executor.submit(l2.rpc.call, 'wait', {'subsystem': 'invoices', 'indexname': 'created', 'nextvalue': 3}) waitfut = executor.submit(l2.rpc.call, 'wait', {'subsystem': 'invoices', 'indexname': 'created', 'nextvalue': 3})
time.sleep(1) time.sleep(1)
inv = l2.rpc.invoice(42, 'invlabel2', 'invdesc2') inv = l2.rpc.invoice(42, 'invlabel2', 'invdesc2', deschashonly=True)
waitres = waitfut.result(TIMEOUT) waitres = waitfut.result(TIMEOUT)
assert waitres == {'subsystem': 'invoices', assert waitres == {'subsystem': 'invoices',
'created': 3, 'created': 3,
@ -807,6 +807,15 @@ def test_wait_invoices(node_factory, executor):
'bolt11': inv['bolt11'], 'bolt11': inv['bolt11'],
'status': 'unpaid'}} 'status': 'unpaid'}}
# Deleting a description causes updated to fire!
waitfut = executor.submit(l2.rpc.call, 'wait', {'subsystem': 'invoices', 'indexname': 'updated', 'nextvalue': 3})
time.sleep(1)
l2.rpc.delinvoice('invlabel2', status='unpaid', desconly=True)
waitres = waitfut.result(TIMEOUT)
assert waitres == {'subsystem': 'invoices',
'updated': 3,
'details': {'label': 'invlabel2', 'description': 'invdesc2'}}
def test_invoice_deschash(node_factory, chainparams): def test_invoice_deschash(node_factory, chainparams):
l1, l2 = node_factory.line_graph(2) l1, l2 = node_factory.line_graph(2)

View File

@ -421,14 +421,21 @@ bool invoices_delete(struct invoices *invoices, u64 inv_dbid,
return true; return true;
} }
bool invoices_delete_description(struct invoices *invoices, u64 inv_dbid) bool invoices_delete_description(struct invoices *invoices, u64 inv_dbid,
const struct json_escape *label,
const char *description)
{ {
struct db_stmt *stmt; struct db_stmt *stmt;
int changes; int changes;
stmt = db_prepare_v2(invoices->wallet->db, SQL("UPDATE invoices" stmt = db_prepare_v2(invoices->wallet->db,
" SET description = NULL" SQL("UPDATE invoices"
" WHERE ID = ?;")); " SET description = NULL,"
" updated_index = ?"
" WHERE ID = ?;"));
db_bind_u64(stmt,
invoice_index_update_deldesc(invoices->wallet->ld,
label, description));
db_bind_u64(stmt, inv_dbid); db_bind_u64(stmt, inv_dbid);
db_exec_prepared_v2(stmt); db_exec_prepared_v2(stmt);
@ -746,3 +753,12 @@ u64 invoice_index_update_status(struct lightningd *ld,
return invoice_index_inc(ld, &state, label, NULL, NULL, return invoice_index_inc(ld, &state, label, NULL, NULL,
WAIT_INDEX_UPDATED); WAIT_INDEX_UPDATED);
} }
u64 invoice_index_update_deldesc(struct lightningd *ld,
const struct json_escape *label,
const char *description)
{
assert(description);
return invoice_index_inc(ld, NULL, label, NULL, description,
WAIT_INDEX_UPDATED);
}

View File

@ -121,7 +121,9 @@ bool invoices_delete(struct invoices *invoices,
* Return false on failure. * Return false on failure.
*/ */
bool invoices_delete_description(struct invoices *invoices, bool invoices_delete_description(struct invoices *invoices,
u64 inv_dbid); u64 inv_dbid,
const struct json_escape *label,
const char *description);
/** /**
* invoices_delete_expired - Delete all expired invoices * invoices_delete_expired - Delete all expired invoices
@ -237,6 +239,11 @@ u64 invoice_index_update_status(struct lightningd *ld,
const struct json_escape *label, const struct json_escape *label,
enum invoice_status state); enum invoice_status state);
/* Returns the current updated_index, and increments it. */
u64 invoice_index_update_deldesc(struct lightningd *ld,
const struct json_escape *label,
const char *description);
void invoice_index_deleted(struct lightningd *ld, void invoice_index_deleted(struct lightningd *ld,
enum invoice_status state, enum invoice_status state,
const struct json_escape *label, const struct json_escape *label,