From f29890ed66e3ac112e7ac3312268607c03e3279d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 21 Mar 2022 11:28:28 +1030 Subject: [PATCH] lightningd: check htlc_maximum_msat of channels for routehints. We still use the channel hint here (as it's the only option), we just warn about lack of capacity. Signed-off-by: Rusty Russell --- lightningd/routehint.c | 10 +++++++++- plugins/topology.c | 3 +++ tests/test_pay.py | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lightningd/routehint.c b/lightningd/routehint.c index 4d4ebd6ad..b5f37776a 100644 --- a/lightningd/routehint.c +++ b/lightningd/routehint.c @@ -61,7 +61,7 @@ routehint_candidates(const tal_t *ctx, struct amount_msat capacity; const char *err; struct routehint_candidate candidate; - struct amount_msat fee_base; + struct amount_msat fee_base, htlc_max; struct route_info *r; struct peer *peer; bool is_public; @@ -74,6 +74,7 @@ routehint_candidates(const tal_t *ctx, ",fee_base_msat:%" ",fee_proportional_millionths:%" ",cltv_expiry_delta:%" + ",htlc_max_msat:%" ",incoming_capacity_msat:%" "}", JSON_SCAN(json_to_node_id, &r->pubkey), @@ -83,6 +84,7 @@ routehint_candidates(const tal_t *ctx, JSON_SCAN(json_to_u32, &r->fee_proportional_millionths), JSON_SCAN(json_to_u16, &r->cltv_expiry_delta), + JSON_SCAN(json_to_msat, &htlc_max), JSON_SCAN(json_to_msat, &capacity)); if (err) { @@ -112,7 +114,13 @@ routehint_candidates(const tal_t *ctx, continue; } + /* If they set an htlc_maximum_msat, consider that the + * capacity ceiling. We *could* do multiple HTLCs, + * but presumably that would defeat the spirit of the + * limit anyway */ candidate.capacity = channel_amount_receivable(candidate.c); + if (amount_msat_greater(candidate.capacity, htlc_max)) + candidate.capacity = htlc_max; /* Now we can tell if it's public. If so (even if it's otherwise * unusable), we *don't* expose private channels! */ diff --git a/plugins/topology.c b/plugins/topology.c index 12be328e5..b6f733704 100644 --- a/plugins/topology.c +++ b/plugins/topology.c @@ -607,6 +607,9 @@ static struct command_result *json_listincoming(struct command *cmd, json_add_amount_msat_only(js, "fee_base_msat", amount_msat(ourchan->half[!dir] .base_fee)); + json_add_amount_msat_only(js, "htlc_max_msat", + amount_msat(fp16_to_u64(ourchan->half[!dir] + .htlc_max))); json_add_u32(js, "fee_proportional_millionths", ourchan->half[!dir].proportional_fee); json_add_u32(js, "cltv_expiry_delta", ourchan->half[!dir].delay); diff --git a/tests/test_pay.py b/tests/test_pay.py index 25c03eb52..0e532248d 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -2153,6 +2153,12 @@ def test_setchannel_routing(node_factory, bitcoind): l1.rpc.sendpay(route_ok, inv['payment_hash'], payment_secret=inv['payment_secret']) l1.rpc.waitsendpay(inv['payment_hash']) + # Check that this one warns about capacity! + inv = l3.rpc.call('invoice', {'msatoshi': 4001793, + 'label': 'test_setchannel_3', + 'description': 'desc'}) + assert 'warning_capacity' in inv + @pytest.mark.developer("gossip without DEVELOPER=1 is slow") def test_setchannel_zero(node_factory, bitcoind):