diff --git a/lightningd/pay.c b/lightningd/pay.c index 3bba874d4..0d97ecadc 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -1690,6 +1690,52 @@ static const struct json_command waitsendpay_command = { }; AUTODATA(json_command, &waitsendpay_command); +static u64 sendpay_index_inc(struct lightningd *ld, + const struct sha256 *payment_hash, + u64 partid, + u64 groupid, + enum payment_status status, + enum wait_index idx) +{ + return wait_index_increment(ld, WAIT_SUBSYSTEM_SENDPAY, idx, + "status", payment_status_to_string(status), + "=partid", tal_fmt(tmpctx, "%"PRIu64, partid), + "=groupid", tal_fmt(tmpctx, "%"PRIu64, groupid), + "payment_hash", + type_to_string(tmpctx, struct sha256, payment_hash), + NULL); +} + +void sendpay_index_deleted(struct lightningd *ld, + const struct sha256 *payment_hash, + u64 partid, + u64 groupid, + enum payment_status status) +{ + sendpay_index_inc(ld, payment_hash, partid, groupid, status, WAIT_INDEX_DELETED); +} + +/* Fortuntely, dbids start at 1, not 0! */ +u64 sendpay_index_created(struct lightningd *ld, + const struct sha256 *payment_hash, + u64 partid, + u64 groupid, + enum payment_status status) +{ + return sendpay_index_inc(ld, payment_hash, partid, groupid, status, + WAIT_INDEX_CREATED); +} + +u64 sendpay_index_update_status(struct lightningd *ld, + const struct sha256 *payment_hash, + u64 partid, + u64 groupid, + enum payment_status status) +{ + return sendpay_index_inc(ld, payment_hash, partid, groupid, status, + WAIT_INDEX_UPDATED); +} + static struct command_result *param_payment_status(struct command *cmd, const char *name, const char *buffer, diff --git a/lightningd/pay.h b/lightningd/pay.h index d8444f4f9..20bef9ada 100644 --- a/lightningd/pay.h +++ b/lightningd/pay.h @@ -2,6 +2,7 @@ #define LIGHTNING_LIGHTNINGD_PAY_H #include "config.h" #include +#include struct htlc_out; struct lightningd; @@ -35,4 +36,20 @@ void json_sendpay_fail_fields(struct json_stream *js, const struct onionreply *onionreply, const struct routing_failure *fail); +/* wait() hooks in here */ +void sendpay_index_deleted(struct lightningd *ld, + const struct sha256 *payment_hash, + u64 partid, + u64 groupid, + enum payment_status status); +u64 sendpay_index_created(struct lightningd *ld, + const struct sha256 *payment_hash, + u64 partid, + u64 groupid, + enum payment_status status); +u64 sendpay_index_update_status(struct lightningd *ld, + const struct sha256 *payment_hash, + u64 partid, + u64 groupid, + enum payment_status status); #endif /* LIGHTNING_LIGHTNINGD_PAY_H */ diff --git a/lightningd/wait.c b/lightningd/wait.c index 70de05a9a..6409912c4 100644 --- a/lightningd/wait.c +++ b/lightningd/wait.c @@ -20,6 +20,7 @@ struct waiter { static const char *subsystem_names[] = { + "sendpays", "invoices", }; @@ -44,6 +45,8 @@ const char *wait_index_name(enum wait_index index) const char *wait_subsystem_name(enum wait_subsystem subsystem) { switch (subsystem) { + case WAIT_SUBSYSTEM_SENDPAY: + return subsystem_names[subsystem]; case WAIT_SUBSYSTEM_INVOICE: return subsystem_names[subsystem]; } diff --git a/lightningd/wait.h b/lightningd/wait.h index 35f50d45c..c9c40206d 100644 --- a/lightningd/wait.h +++ b/lightningd/wait.h @@ -7,7 +7,8 @@ struct lightningd; /* This WAIT_SUBSYSTEM_X corresponds to listX */ enum wait_subsystem { - WAIT_SUBSYSTEM_INVOICE + WAIT_SUBSYSTEM_SENDPAY, + WAIT_SUBSYSTEM_INVOICE, }; #define NUM_WAIT_SUBSYSTEM (WAIT_SUBSYSTEM_INVOICE+1) diff --git a/wallet/db.c b/wallet/db.c index c9d0dcee6..bdb7787ab 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -994,6 +994,8 @@ static struct migration dbmigrations[] = { " commitment_fee BIGINT," " commitment_weight INTEGER)"), NULL}, {SQL("CREATE INDEX local_anchors_idx ON local_anchors (channel_id)"), NULL}, + {SQL("ALTER TABLE payments ADD updated_index BIGINT DEFAULT 0"), NULL}, + {SQL("CREATE INDEX payments_update_idx ON payments (updated_index)"), NULL}, }; /**