diff --git a/common/deprecation.c b/common/deprecation.c index 49012b1b0b12..6adabb7fa5ef 100644 --- a/common/deprecation.c +++ b/common/deprecation.c @@ -115,7 +115,7 @@ bool deprecated_ok_(bool deprecated_apis, level = deprecation(start, end); switch (level) { case DEPRECATED_SOON: - return false; + return true; case DEPRECATED: /* Complain if we're disallowing becuase it's deprecated */ allow = deprecated_apis; diff --git a/common/features.c b/common/features.c index 41daa405527f..88207aa66a19 100644 --- a/common/features.c +++ b/common/features.c @@ -24,7 +24,10 @@ const char *feature_place_names[] = { NULL, "node", "channel", - "invoice" + "invoice", + "bolt12_offer", + "bolt12_invreq", + "bolt12_invoice", }; static const struct feature_style feature_styles[] = { diff --git a/contrib/msggen/msggen/schema.json b/contrib/msggen/msggen/schema.json index 7174ef5cb855..96f7ff57d793 100644 --- a/contrib/msggen/msggen/schema.json +++ b/contrib/msggen/msggen/schema.json @@ -16046,7 +16046,7 @@ "", "Layers are generally maintained by plugins, either to contain persistent information about capacities which have been discovered, or to contain transient information for this particular payment (such as blinded paths or routehints).", "", - "There are two automatic layers: *auto.localchans* contains information on local channels from this node (including non-public ones), and their exact current spendable capacities, and *auto.sourcefree* overrides all channels (including those from previous layers) leading out of the *source* to be zero fee and zero delay. These are both useful in the case where the source is the current node." + "There are trehee automatic layers: *auto.localchans* contains information on local channels from this node (including non-public ones), and their exact current spendable capacities. *auto.sourcefree* overrides all channels (including those from previous layers) leading out of the *source* to be zero fee and zero delay. These are both useful in the case where the source is the current node. And *auto.no_mpp_support* forces getroutes to return a single flow, though only basic checks are done that the result is useful." ], "categories": [ "readonly" diff --git a/devtools/bolt11-cli.c b/devtools/bolt11-cli.c index e28762bea779..5553822c6738 100644 --- a/devtools/bolt11-cli.c +++ b/devtools/bolt11-cli.c @@ -142,9 +142,10 @@ static void encode(const tal_t *ctx, b11->timestamp = strtoul(val, &endp, 10); if (!b11->timestamp || *endp != '\0') errx(ERROR_USAGE, "Invalid amount %s", val); - /* Allow raw numbered fields */ + /* Allow raw numbered fields (except 9, that's below) */ } else if ((fieldnum = strtoul(fname, &endp, 10)) != 0 - && fieldnum < 256) { + && fieldnum < 256 + && fieldnum != 9) { struct bolt11_field *extra = tal(b11, struct bolt11_field); extra->tag = fieldnum; extra->data = tal_hexdata(extra, val, strlen(val)); diff --git a/doc/developers-guide/deprecations.md b/doc/developers-guide/deprecations.md index ebe6ae1b0e43..e82670369ead 100644 --- a/doc/developers-guide/deprecations.md +++ b/doc/developers-guide/deprecations.md @@ -37,6 +37,7 @@ hidden: false | close.tx | Field | v24.11 | v25.11 | Use txs array instead | | close.txid | Field | v24.11 | v25.11 | Use txids array instead | | experimental-offers | Config | v24.11 | v25.05 | Now the default | +| xpay.ignore_bolt12_mpp | Field | v25.05 | v25.11 | Try MPP even if the BOLT12 invoice doesn't explicitly allow it (CLN didn't until 25.02) | Inevitably there are features which need to change: either to be generalized, or removed when they can no longer be supported. diff --git a/doc/schemas/lightning-getroutes.json b/doc/schemas/lightning-getroutes.json index ee3f913ab4c6..7965897d9bb9 100644 --- a/doc/schemas/lightning-getroutes.json +++ b/doc/schemas/lightning-getroutes.json @@ -11,7 +11,7 @@ "", "Layers are generally maintained by plugins, either to contain persistent information about capacities which have been discovered, or to contain transient information for this particular payment (such as blinded paths or routehints).", "", - "There are two automatic layers: *auto.localchans* contains information on local channels from this node (including non-public ones), and their exact current spendable capacities, and *auto.sourcefree* overrides all channels (including those from previous layers) leading out of the *source* to be zero fee and zero delay. These are both useful in the case where the source is the current node." + "There are trehee automatic layers: *auto.localchans* contains information on local channels from this node (including non-public ones), and their exact current spendable capacities. *auto.sourcefree* overrides all channels (including those from previous layers) leading out of the *source* to be zero fee and zero delay. These are both useful in the case where the source is the current node. And *auto.no_mpp_support* forces getroutes to return a single flow, though only basic checks are done that the result is useful." ], "categories": [ "readonly" diff --git a/plugins/askrene/askrene.c b/plugins/askrene/askrene.c index d8c82883fde9..46922254d21c 100644 --- a/plugins/askrene/askrene.c +++ b/plugins/askrene/askrene.c @@ -82,6 +82,7 @@ static struct command_result *param_layer_names(struct command *cmd, /* Must be a known layer name */ if (streq((*arr)[i], "auto.localchans") + || streq((*arr)[i], "auto.no_mpp_support") || streq((*arr)[i], "auto.sourcefree")) continue; if (!find_layer(get_askrene(cmd->plugin), (*arr)[i])) { @@ -209,6 +210,44 @@ static struct layer *source_free_layer(const tal_t *ctx, return layer; } +/* We're going to abuse MCF, and take the largest flow it gives and ram everything + * through it. This is more effective if there's at least a *chance* that can handle + * the full amount. + * + * It's far from perfect, but I have very little sympathy: if you want + * to receive amounts reliably, enable MPP. + */ +static struct layer *remove_small_channel_layer(const tal_t *ctx, + struct askrene *askrene, + struct amount_msat min_amount, + struct gossmap_localmods *localmods) +{ + struct layer *layer = new_temp_layer(ctx, askrene, "auto.no_mpp_support"); + struct gossmap *gossmap = askrene->gossmap; + struct gossmap_chan *c; + + /* We apply this so we see any created channels */ + gossmap_apply_localmods(gossmap, localmods); + + for (c = gossmap_first_chan(gossmap); c; c = gossmap_next_chan(gossmap, c)) { + struct short_channel_id_dir scidd; + if (amount_msat_greater_eq(gossmap_chan_get_capacity(gossmap, c), + min_amount)) + continue; + + scidd.scid = gossmap_chan_scid(gossmap, c); + /* Layer will disable this in both directions */ + for (scidd.dir = 0; scidd.dir < 2; scidd.dir++) { + const bool enabled = false; + layer_add_update_channel(layer, &scidd, &enabled, + NULL, NULL, NULL, NULL, NULL); + } + } + gossmap_remove_localmods(gossmap, localmods); + + return layer; +} + struct amount_msat get_additional_per_htlc_cost(const struct route_query *rq, const struct short_channel_id_dir *scidd) { @@ -321,6 +360,7 @@ static const char *get_routes(const tal_t *ctx, const char **layers, struct gossmap_localmods *localmods, const struct layer *local_layer, + bool single_path, struct route ***routes, struct amount_msat **amounts, const struct additional_cost_htable *additional_costs, @@ -355,8 +395,10 @@ static const char *get_routes(const tal_t *ctx, if (streq(layers[i], "auto.localchans")) { plugin_log(rq->plugin, LOG_DBG, "Adding auto.localchans"); l = local_layer; + } else if (streq(layers[i], "auto.no_mpp_support")) { + plugin_log(rq->plugin, LOG_DBG, "Adding auto.no_mpp_support, sorry"); + l = remove_small_channel_layer(layers, askrene, amount, localmods); } else { - /* Handled below, after other layers */ assert(streq(layers[i], "auto.sourcefree")); plugin_log(rq->plugin, LOG_DBG, "Adding auto.sourcefree"); l = source_free_layer(layers, askrene, source, localmods); @@ -406,7 +448,7 @@ static const char *get_routes(const tal_t *ctx, /* First up, don't care about fees (well, just enough to tiebreak!) */ mu = 1; flows = minflow(rq, rq, srcnode, dstnode, amount, - mu, delay_feefactor); + mu, delay_feefactor, single_path); if (!flows) { ret = explain_failure(ctx, rq, srcnode, dstnode, amount); goto fail; @@ -419,7 +461,7 @@ static const char *get_routes(const tal_t *ctx, "The worst flow delay is %"PRIu64" (> %i), retrying with delay_feefactor %f...", flows_worst_delay(flows), maxdelay - finalcltv, delay_feefactor); flows = minflow(rq, rq, srcnode, dstnode, amount, - mu, delay_feefactor); + mu, delay_feefactor, single_path); if (!flows || delay_feefactor > 10) { ret = rq_log(ctx, rq, LOG_UNUSUAL, "Could not find route without excessive delays"); @@ -442,7 +484,7 @@ static const char *get_routes(const tal_t *ctx, fmt_amount_msat(tmpctx, maxfee), mu); new_flows = minflow(rq, rq, srcnode, dstnode, amount, - mu > 100 ? 100 : mu, delay_feefactor); + mu > 100 ? 100 : mu, delay_feefactor, single_path); if (!flows || mu >= 100) { ret = rq_log(ctx, rq, LOG_UNUSUAL, "Could not find route without excessive cost"); @@ -616,6 +658,7 @@ static struct command_result *do_getroutes(struct command *cmd, info->source, info->dest, *info->amount, *info->maxfee, *info->finalcltv, *info->maxdelay, info->layers, localmods, info->local_layer, + have_layer(info->layers, "auto.no_mpp_support"), &routes, &amounts, info->additional_costs, &probability); if (err) return command_fail(cmd, PAY_ROUTE_NOT_FOUND, "%s", err); diff --git a/plugins/askrene/mcf.c b/plugins/askrene/mcf.c index 740b4fe4c921..ef7eef2d8742 100644 --- a/plugins/askrene/mcf.c +++ b/plugins/askrene/mcf.c @@ -961,7 +961,8 @@ struct flow **minflow(const tal_t *ctx, const struct gossmap_node *target, struct amount_msat amount, u32 mu, - double delay_feefactor) + double delay_feefactor, + bool single_part) { struct flow **flow_paths; /* We allocate everything off this, and free it at the end, @@ -1044,6 +1045,31 @@ struct flow **minflow(const tal_t *ctx, goto fail; } tal_free(working_ctx); + + /* This is dumb, but if you don't support MPP you don't deserve any + * better. Pile it into the largest part if not already. */ + if (single_part) { + struct flow *best = flow_paths[0]; + for (size_t i = 1; i < tal_count(flow_paths); i++) { + if (amount_msat_greater(flow_paths[i]->delivers, best->delivers)) + best = flow_paths[i]; + } + for (size_t i = 0; i < tal_count(flow_paths); i++) { + if (flow_paths[i] == best) + continue; + if (!amount_msat_accumulate(&best->delivers, + flow_paths[i]->delivers)) { + rq_log(tmpctx, rq, LOG_BROKEN, + "%s: failed to extract accumulate flow paths %s+%s", + __func__, + fmt_amount_msat(tmpctx, best->delivers), + fmt_amount_msat(tmpctx, flow_paths[i]->delivers)); + goto fail; + } + } + flow_paths[0] = best; + tal_resize(&flow_paths, 1); + } return flow_paths; fail: diff --git a/plugins/askrene/mcf.h b/plugins/askrene/mcf.h index 2a1b8fcf0cd2..f8100e766dd6 100644 --- a/plugins/askrene/mcf.h +++ b/plugins/askrene/mcf.h @@ -16,6 +16,8 @@ struct route_query; * @target: the target to pay * @amount: the amount we want to reach @target * @mu: 0 = corresponds to only probabilities, 100 corresponds to only fee. + * @delay_feefactor: convert 1 block delay into msat. + * @single_part: don't do MCF at all, just create a single flow. * * @delay_feefactor converts 1 block delay into msat, as if it were an additional * fee. So if a CLTV delay on a node is 5 blocks, that's treated as if it @@ -29,7 +31,8 @@ struct flow **minflow(const tal_t *ctx, const struct gossmap_node *target, struct amount_msat amount, u32 mu, - double delay_feefactor); + double delay_feefactor, + bool single_part); /* To sanity check: this is the approximation mcf uses for the cost * of each channel. */ diff --git a/plugins/libplugin.c b/plugins/libplugin.c index abec6103831f..f4c19bad1fbc 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -1475,6 +1475,12 @@ static struct feature_set *json_to_feature_set(struct plugin *plugin, p = CHANNEL_FEATURE; else if (json_tok_streq(buf, t, "invoice")) p = BOLT11_FEATURE; + else if (json_tok_streq(buf, t, "bolt12_offer")) + p = BOLT12_OFFER_FEATURE; + else if (json_tok_streq(buf, t, "bolt12_invreq")) + p = BOLT12_INVREQ_FEATURE; + else if (json_tok_streq(buf, t, "bolt12_invoice")) + p = BOLT12_INVOICE_FEATURE; else continue; fset->bits[p] = json_tok_bin_from_hex(fset, buf, t + 1); diff --git a/plugins/offers_invreq_hook.c b/plugins/offers_invreq_hook.c index a0c18428bb9f..ab84e11dc717 100644 --- a/plugins/offers_invreq_hook.c +++ b/plugins/offers_invreq_hook.c @@ -357,7 +357,7 @@ static struct command_result *add_blindedpaths(struct command *cmd, /* Don't bother if we're public */ node_id_from_pubkey(&local_nodeid, &id); if (gossmap_find_node(get_gossmap(cmd->plugin), &local_nodeid)) - create_invoicereq(cmd, ir); + return create_invoicereq(cmd, ir); return find_best_peer(cmd, OPT_ROUTE_BLINDING, found_best_peer, ir); diff --git a/plugins/xpay/xpay.c b/plugins/xpay/xpay.c index 2bc4c36e9602..284872375682 100644 --- a/plugins/xpay/xpay.c +++ b/plugins/xpay/xpay.c @@ -76,6 +76,8 @@ struct payment { struct amount_msat maxfee; /* Maximum delay on the route we're ok with */ u32 *maxdelay; + /* Do we have to do it all in a single part? */ + bool disable_mpp; /* BOLT11 payment secret (NULL for BOLT12, it uses blinded paths) */ const struct secret *payment_secret; /* BOLT11 payment metadata (NULL for BOLT12, it uses blinded paths) */ @@ -1192,6 +1194,8 @@ static struct command_result *getroutes_for(struct command *aux_cmd, /* Add user-specified layers */ for (size_t i = 0; i < tal_count(payment->layers); i++) json_add_string(req->js, NULL, payment->layers[i]); + if (payment->disable_mpp) + json_add_string(req->js, NULL, "auto.no_mpp_support"); json_array_end(req->js); json_add_amount_msat(req->js, "maxfee_msat", maxfee); json_add_u32(req->js, "final_cltv", payment->final_cltv); @@ -1551,6 +1555,10 @@ static struct command_result *json_xpay_core(struct command *cmd, if (payment->payinfos[i]->cltv_expiry_delta > payment->final_cltv) payment->final_cltv = payment->payinfos[i]->cltv_expiry_delta; } + /* We will start honoring this flag in future */ + payment->disable_mpp = !feature_offered(b12inv->invoice_features, OPT_BASIC_MPP); + if (payment->disable_mpp && command_deprecated_in_ok(cmd, "ignore_bolt12_mpp", "v25.05", "v25.11")) + payment->disable_mpp = false; } else { struct bolt11 *b11 = bolt11_decode(tmpctx, payment->invstring, @@ -1586,12 +1594,16 @@ static struct command_result *json_xpay_core(struct command *cmd, else payment->full_amount = *msat; + payment->disable_mpp = !feature_offered(b11->features, OPT_BASIC_MPP); if (amount_msat_is_zero(payment->full_amount)) return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Cannot pay bolt11 invoice with zero amount"); invexpiry = b11->timestamp + b11->expiry; } + if (payment->disable_mpp) + payment_log(payment, LOG_INFORM, "No MPP support: this is going to be hard to pay"); + now = time_now().ts.tv_sec; if (now > invexpiry) return command_fail(cmd, PAY_INVOICE_EXPIRED, diff --git a/tests/test_askrene.py b/tests/test_askrene.py index 44e029194a33..69a68bb73d5c 100644 --- a/tests/test_askrene.py +++ b/tests/test_askrene.py @@ -551,6 +551,26 @@ def test_getroutes(node_factory): 'amount_msat': 5500005, 'delay': 99 + 6}]]) + # We realize that this is impossible in a single path: + with pytest.raises(RpcError, match="The shortest path is 0x2x1, but 0x2x1/1 marked disabled by layer auto.no_mpp_support."): + l1.rpc.getroutes(source=nodemap[0], + destination=nodemap[2], + amount_msat=10000000, + layers=['auto.no_mpp_support'], + maxfee_msat=1000, + final_cltv=99) + + # But this will work. + check_getroute_paths(l1, + nodemap[0], + nodemap[2], + 9000000, + [[{'short_channel_id_dir': '0x2x3/1', + 'next_node_id': nodemap[2], + 'amount_msat': 9000009, + 'delay': 99 + 6}]], + layers=['auto.no_mpp_support']) + def test_getroutes_fee_fallback(node_factory): """Test getroutes call takes into account fees, if excessive""" diff --git a/tests/test_xpay.py b/tests/test_xpay.py index ac8ab95847d8..b2ccf0af2f68 100644 --- a/tests/test_xpay.py +++ b/tests/test_xpay.py @@ -254,6 +254,7 @@ def test_xpay_fake_channeld(node_factory, bitcoind, chainparams): f"currency={chainparams['bip173_prefix']}", f"p={hash_hex}", f"s={'00' * 32}", + "9=020000", # option_basic_mpp f"d=Paying node {n}", f"amount={AMOUNT}msat"]).decode('utf-8').strip() assert l1.rpc.decode(inv)['payee'] == nodeids[n] @@ -286,6 +287,7 @@ def test_xpay_fake_channeld(node_factory, bitcoind, chainparams): "encode", n.to_bytes(length=8, byteorder=sys.byteorder).hex() + '01' * 24, f"p={hash_hex}", + "9=020000", # option_basic_mpp f"s={'00' * 32}", f"d=Paying node {n}", f"amount={AMOUNT}msat"]).decode('utf-8').strip() @@ -533,6 +535,7 @@ def test_xpay_maxfee(node_factory, bitcoind, chainparams): n.to_bytes(length=8, byteorder=sys.byteorder).hex() + '01' * 24, f"currency={chainparams['bip173_prefix']}", f"p={hash_hex}", + "9=020000", # option_basic_mpp f"s={'00' * 32}", f"d=Paying node {n} with maxfee", f"amount={AMOUNT}msat"]).decode('utf-8').strip() @@ -593,3 +596,58 @@ def test_xpay_zeroconf(node_factory): offer = l2.rpc.offer('any')['bolt12'] b12 = l1.rpc.fetchinvoice(offer, '100000msat')['invoice'] l1.rpc.xpay(b12) + + +def test_xpay_no_mpp(node_factory, chainparams): + """Suppress mpp, resulting in a single payment part""" + l1, l2, l3, l4 = node_factory.get_nodes(4) + node_factory.join_nodes([l1, l2, l3], wait_for_announce=True) + node_factory.join_nodes([l1, l4, l3], wait_for_announce=True) + + # Amount needs to be enought that it bothers splitting, but not + # so much that it can't pay without mpp. + AMOUNT=500000000 + + # We create a version of this which doesn't support MPP + no_mpp = l3.rpc.invoice(AMOUNT, 'test_xpay_no_mpp2', 'test_xpay_no_mpp without mpp') + b11_no_mpp = subprocess.check_output(["devtools/bolt11-cli", + "encode", + # secret for l3 + "dae24b3853e1443a176daba5544ee04f7db33ebe38e70bdfdb1da34e89512c10", + f"currency={chainparams['bip173_prefix']}", + f"p={no_mpp['payment_hash']}", + f"s={no_mpp['payment_secret']}", + f"d=Paying l3 without mpp", + f"amount={AMOUNT}"]).decode('utf-8').strip() + + # This should not mpp! + ret = l1.rpc.xpay(b11_no_mpp) + assert ret['failed_parts'] == 0 + assert ret['successful_parts'] == 1 + assert ret['amount_msat'] == AMOUNT + assert ret['amount_sent_msat'] == AMOUNT + AMOUNT//100000 + 1 + + +def test_xpay_bolt12_no_mpp(node_factory, chainparams): + """We should not (yet!) avoid mpp if BOLT12 invoice doesn't say we should""" + l1, l2, l3, l4 = node_factory.get_nodes(4) + node_factory.join_nodes([l1, l2, l3], wait_for_announce=True) + node_factory.join_nodes([l1, l4, l3], wait_for_announce=True) + + # Amount needs to be enought that it bothers splitting, but not + # so much that it can't pay without mpp. + AMOUNT=500000000 + + # We create a version of this which doesn't advertize support for MPP + # (I grabbed this from a real instance) + inv = l3.rpc.createinvoice(invstring="lni1qqg00rlfqualt5wvj9meezlx202qwq3qqc3xu3s3rg94nj40zfsy866mhu5vxne6tcej5878k2mneuvgjy8sspqae4jsqzshw3jhxazl0pcxz72lvfhkcap3xf0kum6ld4c8q93pqdwjkyvjm7apxnssu4qgwhfkd67ghs6n6k48v6uqczgt88p6tky965pqqc3xu3s3rg94nj40zfsy866mhu5vxne6tcej5878k2mneuvgjy84sggrv4a2zv5mfvds5pz9ehe40uws375pc4u6ausees3xuezw7d4kssx6gpr854lme2pqavazfzxk4pgv4pvnamxv7e26787e3zm53kpek3qzmpjx50jc6t625pqae4jspvppqdwjkyvjm7apxnssu4qgwhfkd67ghs6n6k48v6uqczgt88p6tky96", + preimage="637f5b64ae540986826288ed24db980e756b2eb680b6db17f1072643c12ae531", + label="b53c2f55f53a0f979df864d36fff53bbf10454130df9bbf478f1727386f6ef93-03657aa1329b4b1b0a0445cdf357f1d08fa81c579aef219cc226e644ef36b6840d-0")['bolt12'] + + # This will MPP ANYWAY, even though MPP is not specified! + ret = l1.rpc.xpay(inv) + assert ret['failed_parts'] == 0 + assert ret['successful_parts'] == 2 + assert ret['amount_msat'] == AMOUNT + assert ret['amount_sent_msat'] == AMOUNT + AMOUNT//100000 + 1 +