From adfe494b0842c7db548cda4d12372595d3eadf27 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 13 Nov 2017 16:13:35 +0100 Subject: [PATCH] invoice: Fix waitanyinvoice There were two bugs: we weren't returning the next from the given label but the one matching the label, and we were appending new invoices to the head instead of the tail, which meant we'd be traversing in the wrong order. Signed-off-by: Christian Decker --- lightningd/invoice.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lightningd/invoice.c b/lightningd/invoice.c index 5c21c8b2d..334b42388 100644 --- a/lightningd/invoice.c +++ b/lightningd/invoice.c @@ -191,7 +191,7 @@ static void json_invoice(struct command *cmd, /* OK, connect it to main state, respond with hash */ tal_steal(invs, invoice); - list_add(&invs->invlist, &invoice->list); + list_add_tail(&invs->invlist, &invoice->list); json_object_start(response, NULL); json_add_hex(response, "rhash", @@ -342,6 +342,8 @@ static void json_waitanyinvoice(struct command *cmd, command_fail(cmd, "Label not found"); return; } + /* Skip this particular invoice */ + i = list_next(&invs->invlist, i, list); while (i && i->state == UNPAID) { i = list_next(&invs->invlist, i, list); }