diff --git a/lightningd/pay.c b/lightningd/pay.c index b483884328e1..f4e999e23c73 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -1682,6 +1682,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 d8444f4f97cc..20bef9ada2e3 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 70de05a9ad4f..6409912c403f 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 35f50d45c469..c9c40206d4ff 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 bfa98e2e62ac..196eaaf5d00c 100644 --- a/wallet/db.c +++ b/wallet/db.c @@ -978,6 +978,8 @@ static struct migration dbmigrations[] = { {NULL, migrate_runes_idfix}, {SQL("ALTER TABLE runes ADD last_used_nsec BIGINT DEFAULT NULL"), NULL}, {SQL("DELETE FROM vars WHERE name = 'runes_uniqueid'"), NULL}, + {SQL("ALTER TABLE payments ADD updated_index BIGINT DEFAULT 0"), NULL}, + {SQL("CREATE INDEX payments_update_idx ON payments (updated_index)"), NULL}, }; /**