plugin: Call invoice_payment hook before the matching notification

As @fiatjaf points out we were notifying before we were actually set
on accepting, since the hook could also still reject. Switched them
around does and calling the notification only once it's been decided
is the correct thing to do.

Changelog-Fixed: plugin: The `invoice_payment` notification was being sent before the hook was called, which could still abort it.
Suggested-by: Fiatjaf <@fiatjaf>
Signed-off-by: Christian Decker <@cdecker>
This commit is contained in:
Christian Decker 2021-03-17 13:22:17 +01:00 committed by Rusty Russell
parent 6cfb72ea1b
commit 71c45dc55c

View file

@ -287,6 +287,9 @@ invoice_payment_hooks_done(struct invoice_payment_hook_payload *payload STEALS)
type_to_string(tmpctx, struct amount_msat, &payload->msat),
tal_count(payload->set->htlcs));
htlc_set_fulfill(payload->set, &payload->preimage);
notify_invoice_payment(ld, payload->msat, payload->preimage,
payload->label);
}
static bool
@ -431,8 +434,6 @@ void invoice_try_pay(struct lightningd *ld,
payload->set = set;
tal_add_destructor2(set, invoice_payload_remove_set, payload);
notify_invoice_payment(ld, payload->msat, payload->preimage, payload->label);
plugin_hook_call_invoice_payment(ld, payload);
}