Skip to content

Commit

Permalink
sendpays: add to wait subsystem.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rustyrussell committed Oct 28, 2023
1 parent 34692ec commit ccb8d4b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
46 changes: 46 additions & 0 deletions lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions lightningd/pay.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define LIGHTNING_LIGHTNINGD_PAY_H
#include "config.h"
#include <common/errcode.h>
#include <wallet/wallet.h>

struct htlc_out;
struct lightningd;
Expand Down Expand Up @@ -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 */
3 changes: 3 additions & 0 deletions lightningd/wait.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct waiter {


static const char *subsystem_names[] = {
"sendpays",
"invoices",
};

Expand All @@ -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];
}
Expand Down
3 changes: 2 additions & 1 deletion lightningd/wait.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions wallet/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

/**
Expand Down

0 comments on commit ccb8d4b

Please sign in to comment.