paymod: Maintain a list of current and past payments

We need to keep them around so we can inspect them later. We'll also need a
background cleanup every once in a while to free some memory. More on that in
a future commit.
This commit is contained in:
Christian Decker 2020-05-18 18:47:21 +02:00
parent 8207b4eac8
commit c35df400b2
2 changed files with 5 additions and 1 deletions

View file

@ -103,6 +103,7 @@ enum payment_step {
struct payment { struct payment {
/* The command that triggered this payment. */ /* The command that triggered this payment. */
struct command *cmd; struct command *cmd;
struct list_node list;
const char *json_buffer; const char *json_buffer;
const jsmntok_t *json_toks; const jsmntok_t *json_toks;

View file

@ -27,6 +27,8 @@ static struct node_id my_id;
static unsigned int maxdelay_default; static unsigned int maxdelay_default;
static LIST_HEAD(pay_status); static LIST_HEAD(pay_status);
static LIST_HEAD(payments);
struct pay_attempt { struct pay_attempt {
/* What we changed when starting this attempt. */ /* What we changed when starting this attempt. */
const char *why; const char *why;
@ -1719,7 +1721,7 @@ static struct command_result *json_paymod(struct command *cmd,
struct bolt11 *b11; struct bolt11 *b11;
char *fail; char *fail;
struct dummy_data *ddata; struct dummy_data *ddata;
p = payment_new(cmd, cmd, NULL /* No parent */, paymod_mods); p = payment_new(NULL, cmd, NULL /* No parent */, paymod_mods);
ddata = (struct dummy_data*)p->modifier_data[0]; ddata = (struct dummy_data*)p->modifier_data[0];
@ -1763,6 +1765,7 @@ static struct command_result *json_paymod(struct command *cmd,
p->destination = p->getroute_destination = &b11->receiver_id; p->destination = p->getroute_destination = &b11->receiver_id;
p->payment_hash = tal_dup(p, struct sha256, &b11->payment_hash); p->payment_hash = tal_dup(p, struct sha256, &b11->payment_hash);
payment_start(p); payment_start(p);
list_add_tail(&payments, &p->list);
return command_still_pending(cmd); return command_still_pending(cmd);
} }