Browse Source

keysend: Check that the destination supports keysend upon init

We were blindly initiating the keysend payment, which could lead to
confusing outcomes. This adds a very specific error message to the
error returned.

Changelog-Fixed: keysend: Keysend now checks whether the destination supports keysend before attempting a payment. If not a more informative error is returned.
fix-mocks
Christian Decker 4 years ago
parent
commit
3b599b846e
  1. 19
      plugins/keysend.c
  2. 2
      tests/test_pay.py

19
plugins/keysend.c

@ -1,6 +1,7 @@
#include <bitcoin/preimage.h> #include <bitcoin/preimage.h>
#include <ccan/array_size/array_size.h> #include <ccan/array_size/array_size.h>
#include <ccan/tal/str/str.h> #include <ccan/tal/str/str.h>
#include <common/gossmap.h>
#include <plugins/libplugin-pay.h> #include <plugins/libplugin-pay.h>
#include <plugins/libplugin.h> #include <plugins/libplugin.h>
#include <wire/onion_wire.h> #include <wire/onion_wire.h>
@ -54,6 +55,24 @@ static struct keysend_data *keysend_init(struct payment *p)
static void keysend_cb(struct keysend_data *d, struct payment *p) { static void keysend_cb(struct keysend_data *d, struct payment *p) {
struct createonion_hop *last_payload; struct createonion_hop *last_payload;
size_t hopcount; size_t hopcount;
struct gossmap_node *node;
bool enabled;
const struct gossmap *gossmap = get_gossmap(p->plugin);
/* On the root payment we perform the featurebit check. */
if (p->parent == NULL && p->step == PAYMENT_STEP_INITIALIZED) {
node = gossmap_find_node(gossmap, p->destination);
enabled = gossmap_node_get_feature(gossmap, node,
KEYSEND_FEATUREBIT) != -1;
if (!enabled)
return payment_fail(
p,
"Recipient %s does not support keysend payments "
"(feature bit %d missing in node announcement)",
node_id_to_hexstr(tmpctx, p->destination),
KEYSEND_FEATUREBIT);
}
if (p->step != PAYMENT_STEP_ONION_PAYLOAD) if (p->step != PAYMENT_STEP_ONION_PAYLOAD)
return payment_continue(p); return payment_continue(p);

2
tests/test_pay.py

@ -3373,7 +3373,7 @@ def test_listpay_result_with_paymod(node_factory, bitcoind):
amount_sat = 10 ** 6 amount_sat = 10 ** 6
l1, l2, l3 = node_factory.line_graph(3) l1, l2, l3 = node_factory.line_graph(3, wait_for_announce=True)
invl2 = l2.rpc.invoice(amount_sat * 2, "inv_l2", "inv_l2") invl2 = l2.rpc.invoice(amount_sat * 2, "inv_l2", "inv_l2")
l1.rpc.pay(invl2['bolt11']) l1.rpc.pay(invl2['bolt11'])

Loading…
Cancel
Save