Skip to content

Commit 17f588b

Browse files
committed
sendpays: add to wait subsystem.
Adding an index means: 1. Add the new subsystem, and new updated_index field to the db, and create xxx_index_deleted/created/updated APIs. 2. Hook up these functions to the points they need to be called. 3. Add index, start and limit fields to the list command. 4. Add created_index and updated_index into the list command. This does #1. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent f43c930 commit 17f588b

File tree

5 files changed

+70
-1
lines changed

5 files changed

+70
-1
lines changed

lightningd/pay.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,52 @@ static const struct json_command waitsendpay_command = {
16821682
};
16831683
AUTODATA(json_command, &waitsendpay_command);
16841684

1685+
static u64 sendpay_index_inc(struct lightningd *ld,
1686+
const struct sha256 *payment_hash,
1687+
u64 partid,
1688+
u64 groupid,
1689+
enum payment_status status,
1690+
enum wait_index idx)
1691+
{
1692+
return wait_index_increment(ld, WAIT_SUBSYSTEM_SENDPAY, idx,
1693+
"status", payment_status_to_string(status),
1694+
"=partid", tal_fmt(tmpctx, "%"PRIu64, partid),
1695+
"=groupid", tal_fmt(tmpctx, "%"PRIu64, groupid),
1696+
"payment_hash",
1697+
type_to_string(tmpctx, struct sha256, payment_hash),
1698+
NULL);
1699+
}
1700+
1701+
void sendpay_index_deleted(struct lightningd *ld,
1702+
const struct sha256 *payment_hash,
1703+
u64 partid,
1704+
u64 groupid,
1705+
enum payment_status status)
1706+
{
1707+
sendpay_index_inc(ld, payment_hash, partid, groupid, status, WAIT_INDEX_DELETED);
1708+
}
1709+
1710+
/* Fortuntely, dbids start at 1, not 0! */
1711+
u64 sendpay_index_created(struct lightningd *ld,
1712+
const struct sha256 *payment_hash,
1713+
u64 partid,
1714+
u64 groupid,
1715+
enum payment_status status)
1716+
{
1717+
return sendpay_index_inc(ld, payment_hash, partid, groupid, status,
1718+
WAIT_INDEX_CREATED);
1719+
}
1720+
1721+
u64 sendpay_index_update_status(struct lightningd *ld,
1722+
const struct sha256 *payment_hash,
1723+
u64 partid,
1724+
u64 groupid,
1725+
enum payment_status status)
1726+
{
1727+
return sendpay_index_inc(ld, payment_hash, partid, groupid, status,
1728+
WAIT_INDEX_UPDATED);
1729+
}
1730+
16851731
static struct command_result *param_payment_status(struct command *cmd,
16861732
const char *name,
16871733
const char *buffer,

lightningd/pay.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define LIGHTNING_LIGHTNINGD_PAY_H
33
#include "config.h"
44
#include <common/errcode.h>
5+
#include <wallet/wallet.h>
56

67
struct htlc_out;
78
struct lightningd;
@@ -35,4 +36,20 @@ void json_sendpay_fail_fields(struct json_stream *js,
3536
const struct onionreply *onionreply,
3637
const struct routing_failure *fail);
3738

39+
/* wait() hooks in here */
40+
void sendpay_index_deleted(struct lightningd *ld,
41+
const struct sha256 *payment_hash,
42+
u64 partid,
43+
u64 groupid,
44+
enum payment_status status);
45+
u64 sendpay_index_created(struct lightningd *ld,
46+
const struct sha256 *payment_hash,
47+
u64 partid,
48+
u64 groupid,
49+
enum payment_status status);
50+
u64 sendpay_index_update_status(struct lightningd *ld,
51+
const struct sha256 *payment_hash,
52+
u64 partid,
53+
u64 groupid,
54+
enum payment_status status);
3855
#endif /* LIGHTNING_LIGHTNINGD_PAY_H */

lightningd/wait.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct waiter {
2020

2121

2222
static const char *subsystem_names[] = {
23+
"sendpays",
2324
"invoices",
2425
};
2526

@@ -44,6 +45,8 @@ const char *wait_index_name(enum wait_index index)
4445
const char *wait_subsystem_name(enum wait_subsystem subsystem)
4546
{
4647
switch (subsystem) {
48+
case WAIT_SUBSYSTEM_SENDPAY:
49+
return subsystem_names[subsystem];
4750
case WAIT_SUBSYSTEM_INVOICE:
4851
return subsystem_names[subsystem];
4952
}

lightningd/wait.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ struct lightningd;
77

88
/* This WAIT_SUBSYSTEM_X corresponds to listX */
99
enum wait_subsystem {
10-
WAIT_SUBSYSTEM_INVOICE
10+
WAIT_SUBSYSTEM_SENDPAY,
11+
WAIT_SUBSYSTEM_INVOICE,
1112
};
1213
#define NUM_WAIT_SUBSYSTEM (WAIT_SUBSYSTEM_INVOICE+1)
1314

wallet/db.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,8 @@ static struct migration dbmigrations[] = {
978978
{SQL("ALTER TABLE runes ADD last_used_nsec BIGINT DEFAULT NULL"), NULL},
979979
{NULL, migrate_runes_idfix},
980980
{SQL("DELETE FROM vars WHERE name = 'runes_uniqueid'"), NULL},
981+
{SQL("ALTER TABLE payments ADD updated_index BIGINT DEFAULT 0"), NULL},
982+
{SQL("CREATE INDEX payments_update_idx ON payments (updated_index)"), NULL},
981983
};
982984

983985
/**

0 commit comments

Comments
 (0)