Skip to content

Commit ccb8d4b

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 34692ec commit ccb8d4b

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
@@ -1690,6 +1690,52 @@ static const struct json_command waitsendpay_command = {
16901690
};
16911691
AUTODATA(json_command, &waitsendpay_command);
16921692

1693+
static u64 sendpay_index_inc(struct lightningd *ld,
1694+
const struct sha256 *payment_hash,
1695+
u64 partid,
1696+
u64 groupid,
1697+
enum payment_status status,
1698+
enum wait_index idx)
1699+
{
1700+
return wait_index_increment(ld, WAIT_SUBSYSTEM_SENDPAY, idx,
1701+
"status", payment_status_to_string(status),
1702+
"=partid", tal_fmt(tmpctx, "%"PRIu64, partid),
1703+
"=groupid", tal_fmt(tmpctx, "%"PRIu64, groupid),
1704+
"payment_hash",
1705+
type_to_string(tmpctx, struct sha256, payment_hash),
1706+
NULL);
1707+
}
1708+
1709+
void sendpay_index_deleted(struct lightningd *ld,
1710+
const struct sha256 *payment_hash,
1711+
u64 partid,
1712+
u64 groupid,
1713+
enum payment_status status)
1714+
{
1715+
sendpay_index_inc(ld, payment_hash, partid, groupid, status, WAIT_INDEX_DELETED);
1716+
}
1717+
1718+
/* Fortuntely, dbids start at 1, not 0! */
1719+
u64 sendpay_index_created(struct lightningd *ld,
1720+
const struct sha256 *payment_hash,
1721+
u64 partid,
1722+
u64 groupid,
1723+
enum payment_status status)
1724+
{
1725+
return sendpay_index_inc(ld, payment_hash, partid, groupid, status,
1726+
WAIT_INDEX_CREATED);
1727+
}
1728+
1729+
u64 sendpay_index_update_status(struct lightningd *ld,
1730+
const struct sha256 *payment_hash,
1731+
u64 partid,
1732+
u64 groupid,
1733+
enum payment_status status)
1734+
{
1735+
return sendpay_index_inc(ld, payment_hash, partid, groupid, status,
1736+
WAIT_INDEX_UPDATED);
1737+
}
1738+
16931739
static struct command_result *param_payment_status(struct command *cmd,
16941740
const char *name,
16951741
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
@@ -994,6 +994,8 @@ static struct migration dbmigrations[] = {
994994
" commitment_fee BIGINT,"
995995
" commitment_weight INTEGER)"), NULL},
996996
{SQL("CREATE INDEX local_anchors_idx ON local_anchors (channel_id)"), NULL},
997+
{SQL("ALTER TABLE payments ADD updated_index BIGINT DEFAULT 0"), NULL},
998+
{SQL("CREATE INDEX payments_update_idx ON payments (updated_index)"), NULL},
997999
};
9981000

9991001
/**

0 commit comments

Comments
 (0)