Skip to content

Commit 35f899a

Browse files
Lagrang3endothermicdev
authored andcommitted
fetch max total htlc value from listpeerchannel
The parameter max_htlc_value_in_flight_msat stablished by peers on channel opening (BOLT02) can now be retrived from the gossmods_from_listpeerchannels API. Adapted the corresponding callback functions in renepay and askrene to take into account that value as a constraint to the value we can send through a channel. Changelog-Add: fetch max_htlc_value_in_flight_msat from gossmods_listpeerchannels API Signed-off-by: Lagrang3 <[email protected]>
1 parent afb54ff commit 35f899a

File tree

7 files changed

+26
-6
lines changed

7 files changed

+26
-6
lines changed

common/gossmods_listpeerchannels.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ void gossmod_add_localchan(struct gossmap_localmods *mods,
1313
struct amount_msat htlcmin,
1414
struct amount_msat htlcmax,
1515
struct amount_msat spendable,
16+
struct amount_msat total_htlcmax,
1617
struct amount_msat fee_base,
1718
u32 fee_proportional,
1819
u16 cltv_delta,
@@ -52,6 +53,7 @@ gossmods_from_listpeerchannels_(const tal_t *ctx,
5253
struct amount_msat htlcmin,
5354
struct amount_msat htlcmax,
5455
struct amount_msat sr_able,
56+
struct amount_msat max_total_htlc,
5557
struct amount_msat fee_base,
5658
u32 fee_proportional,
5759
u16 cltv_delta,
@@ -72,6 +74,7 @@ gossmods_from_listpeerchannels_(const tal_t *ctx,
7274
bool enabled;
7375
struct node_id dst;
7476
struct amount_msat capacity_msat, spendable, receivable, fee_base[NUM_SIDES], htlc_min[NUM_SIDES], htlc_max[NUM_SIDES];
77+
struct amount_msat max_total_in_htlc, max_total_out_htlc;
7578
u32 fee_proportional[NUM_SIDES], cltv_delta[NUM_SIDES];
7679
const char *state, *err;
7780

@@ -87,6 +90,8 @@ gossmods_from_listpeerchannels_(const tal_t *ctx,
8790
"direction?:%,"
8891
"spendable_msat?:%,"
8992
"receivable_msat?:%,"
93+
"our_max_htlc_value_in_flight_msat?:%,"
94+
"their_max_htlc_value_in_flight_msat?:%,"
9095
"peer_connected:%,"
9196
"state:%,"
9297
"peer_id:%,"
@@ -109,6 +114,8 @@ gossmods_from_listpeerchannels_(const tal_t *ctx,
109114
JSON_SCAN(json_to_int, &scidd.dir),
110115
JSON_SCAN(json_to_msat, &spendable),
111116
JSON_SCAN(json_to_msat, &receivable),
117+
JSON_SCAN(json_to_msat, &max_total_in_htlc),
118+
JSON_SCAN(json_to_msat, &max_total_out_htlc),
112119
JSON_SCAN(json_to_bool, &enabled),
113120
JSON_SCAN_TAL(tmpctx, json_strdup, &state),
114121
JSON_SCAN(json_to_node_id, &dst),
@@ -155,7 +162,7 @@ gossmods_from_listpeerchannels_(const tal_t *ctx,
155162
/* We add both directions */
156163
cb(mods, self, &dst, &scidd, capacity_msat,
157164
htlc_min[LOCAL], htlc_max[LOCAL],
158-
spendable, fee_base[LOCAL], fee_proportional[LOCAL],
165+
spendable, max_total_out_htlc, fee_base[LOCAL], fee_proportional[LOCAL],
159166
cltv_delta[LOCAL], enabled, buf, channel, cbarg);
160167

161168
/* If we didn't have a remote update, it's not usable yet */
@@ -166,7 +173,7 @@ gossmods_from_listpeerchannels_(const tal_t *ctx,
166173

167174
cb(mods, self, &dst, &scidd, capacity_msat,
168175
htlc_min[REMOTE], htlc_max[REMOTE],
169-
receivable, fee_base[REMOTE], fee_proportional[REMOTE],
176+
receivable, max_total_in_htlc, fee_base[REMOTE], fee_proportional[REMOTE],
170177
cltv_delta[REMOTE], enabled, buf, channel, cbarg);
171178
}
172179

common/gossmods_listpeerchannels.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct gossmap_localmods *gossmods_from_listpeerchannels_(const tal_t *ctx,
3434
struct amount_msat htlcmin,
3535
struct amount_msat htlcmax,
3636
struct amount_msat spendable,
37+
struct amount_msat total_htlcmax,
3738
struct amount_msat fee_base,
3839
u32 fee_proportional,
3940
u16 cltv_delta,
@@ -55,6 +56,7 @@ struct gossmap_localmods *gossmods_from_listpeerchannels_(const tal_t *ctx,
5556
struct amount_msat, \
5657
struct amount_msat, \
5758
struct amount_msat, \
59+
struct amount_msat, \
5860
u32, \
5961
u16, \
6062
bool, \
@@ -71,6 +73,7 @@ void gossmod_add_localchan(struct gossmap_localmods *mods,
7173
struct amount_msat htlcmin,
7274
struct amount_msat htlcmax,
7375
struct amount_msat spendable,
76+
struct amount_msat total_htlcmax,
7477
struct amount_msat fee_base,
7578
u32 fee_proportional,
7679
u16 cltv_delta,

plugins/askrene/askrene.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ static void add_localchan(struct gossmap_localmods *mods,
699699
struct amount_msat htlcmin,
700700
struct amount_msat htlcmax,
701701
struct amount_msat spendable,
702+
struct amount_msat max_total_htlc,
702703
struct amount_msat fee_base,
703704
u32 fee_proportional,
704705
u16 cltv_delta,
@@ -759,8 +760,10 @@ static void add_localchan(struct gossmap_localmods *mods,
759760
additional_cost_htable_add(info->additional_costs, phc);
760761
}
761762

763+
/* can't send more than expendable and no more than max_total_htlc */
764+
struct amount_msat max_msat = amount_msat_min(spendable, max_total_htlc);
762765
/* Known capacity on local channels (ts = max) */
763-
layer_add_constraint(info->local_layer, scidd, UINT64_MAX, &spendable, &spendable);
766+
layer_add_constraint(info->local_layer, scidd, UINT64_MAX, &max_msat, &max_msat);
764767
}
765768

766769
static struct command_result *

plugins/renepay/mods.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ static void gossmod_cb(struct gossmap_localmods *mods,
343343
struct amount_msat htlcmin,
344344
struct amount_msat htlcmax,
345345
struct amount_msat spendable,
346+
struct amount_msat max_total_htlc,
346347
struct amount_msat fee_base,
347348
u32 fee_proportional,
348349
u16 cltv_delta,
@@ -354,9 +355,10 @@ static void gossmod_cb(struct gossmap_localmods *mods,
354355
struct amount_msat min, max;
355356

356357
if (scidd->dir == node_id_idx(self, peer)) {
357-
/* local channels can send up to what's spendable */
358+
/* local channels can send up to what's spendable but there is a
359+
* limit also the total amount in-flight */
358360
min = AMOUNT_MSAT(0);
359-
max = spendable;
361+
max = amount_msat_min(spendable, max_total_htlc);
360362
} else {
361363
/* remote channels can send up no more than spendable */
362364
min = htlcmin;

plugins/test/run-route-calc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ void gossmod_add_localchan(struct gossmap_localmods *mods UNNEEDED,
5454
struct amount_msat htlcmin UNNEEDED,
5555
struct amount_msat htlcmax UNNEEDED,
5656
struct amount_msat spendable UNNEEDED,
57+
struct amount_msat total_htlcmax UNNEEDED,
5758
struct amount_msat fee_base UNNEEDED,
5859
u32 fee_proportional UNNEEDED,
5960
u16 cltv_delta UNNEEDED,
@@ -76,6 +77,7 @@ struct gossmap_localmods *gossmods_from_listpeerchannels_(const tal_t *ctx UNNEE
7677
struct amount_msat htlcmin UNNEEDED,
7778
struct amount_msat htlcmax UNNEEDED,
7879
struct amount_msat spendable UNNEEDED,
80+
struct amount_msat total_htlcmax UNNEEDED,
7981
struct amount_msat fee_base UNNEEDED,
8082
u32 fee_proportional UNNEEDED,
8183
u16 cltv_delta UNNEEDED,

plugins/test/run-route-overlong.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ void gossmod_add_localchan(struct gossmap_localmods *mods UNNEEDED,
5151
struct amount_msat htlcmin UNNEEDED,
5252
struct amount_msat htlcmax UNNEEDED,
5353
struct amount_msat spendable UNNEEDED,
54+
struct amount_msat total_htlcmax UNNEEDED,
5455
struct amount_msat fee_base UNNEEDED,
5556
u32 fee_proportional UNNEEDED,
5657
u16 cltv_delta UNNEEDED,
@@ -73,6 +74,7 @@ struct gossmap_localmods *gossmods_from_listpeerchannels_(const tal_t *ctx UNNEE
7374
struct amount_msat htlcmin UNNEEDED,
7475
struct amount_msat htlcmax UNNEEDED,
7576
struct amount_msat spendable UNNEEDED,
77+
struct amount_msat total_htlcmax UNNEEDED,
7678
struct amount_msat fee_base UNNEEDED,
7779
u32 fee_proportional UNNEEDED,
7880
u16 cltv_delta UNNEEDED,

plugins/topology.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ static void gossmod_add_unknown_localchan(struct gossmap_localmods *mods,
355355
struct amount_msat min,
356356
struct amount_msat max,
357357
struct amount_msat spendable,
358+
struct amount_msat max_total_htlc,
358359
struct amount_msat fee_base,
359360
u32 fee_proportional,
360361
u16 cltv_delta,
@@ -367,7 +368,7 @@ static void gossmod_add_unknown_localchan(struct gossmap_localmods *mods,
367368
return;
368369

369370
gossmod_add_localchan(mods, self, peer, scidd, capacity_msat,
370-
min, max, spendable,
371+
min, max, spendable, max_total_htlc,
371372
fee_base, fee_proportional, cltv_delta, enabled,
372373
buf, chantok, gossmap);
373374
}

0 commit comments

Comments
 (0)