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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-03-21 11:28:28 +10:30
parent 1751b1becc
commit f29890ed66
3 changed files with 18 additions and 1 deletions

View file

@ -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! */

View file

@ -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);

View file

@ -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):