From 1eb878be825d9397ce2d45983f30ad5f2eeb4060 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 25 Jul 2024 17:38:57 +0200 Subject: [PATCH] route: Add the total capacity to route_hops We need to know the overall channel capacity, i.e., the amount_msat that the channel was funded with, in order to relax the channel_hint to refill over time. --- common/route.c | 6 ++++++ common/route.h | 2 ++ plugins/libplugin-pay.c | 12 +++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/common/route.c b/common/route.c index 19ee2215c..06bf205a2 100644 --- a/common/route.c +++ b/common/route.c @@ -81,6 +81,7 @@ static bool dijkstra_to_hops(struct route_hop **hops, const struct gossmap_node *next; size_t num_hops = tal_count(*hops); const struct half_chan *h; + struct amount_sat total; if (dist == 0) return true; @@ -92,6 +93,11 @@ static bool dijkstra_to_hops(struct route_hop **hops, /* OK, populate other fields. */ c = dijkstra_best_chan(dij, curidx); + + gossmap_chan_get_capacity(gossmap, c, &total); + if (!amount_sat_to_msat(&(*hops)[num_hops].total_amount, total)) + abort(); + if (c->half[0].nodeidx == curidx) { (*hops)[num_hops].direction = 0; } else { diff --git a/common/route.h b/common/route.h index d6ea2b066..6d8936220 100644 --- a/common/route.h +++ b/common/route.h @@ -18,6 +18,7 @@ struct gossmap_node; * @direction: 0 (dest node_id < src node_id), 1 (dest node_id > src). * @node_id: the node_id of the destination of this hop. * @amount: amount to send through this hop. + * @total_amount: The amount the channel was funded with. * @delay: total cltv delay at this hop. */ struct route_hop { @@ -25,6 +26,7 @@ struct route_hop { int direction; struct node_id node_id; struct amount_msat amount; + struct amount_msat total_amount; u32 delay; }; diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 4fdad99c3..c166111fa 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -3215,7 +3215,15 @@ static void routehint_step_cb(struct routehints_data *d, struct payment *p) routehint_pre_getroute(d, p); } else if (p->step == PAYMENT_STEP_GOT_ROUTE && d->current_routehint != NULL) { /* Now it's time to stitch the two partial routes together. */ - struct amount_msat dest_amount; + struct amount_msat dest_amount, estimate; + /* We do not have the exact final amount, however we + * know that we should be able to use the channel in + * the routehint, so let's fake it as being 2x the + * amount we want to route. */ + + if(!amount_msat_mul(&estimate, p->final_amount, 2)) + abort(); + struct route_info *routehint = d->current_routehint; struct route_hop *prev_hop; for (ssize_t i = 0; i < tal_count(routehint); i++) { @@ -3233,6 +3241,7 @@ static void routehint_step_cb(struct routehints_data *d, struct payment *p) hop.amount = dest_amount; hop.delay = route_cltv(d->final_cltv, routehint + i + 1, tal_count(routehint) - i - 1); + hop.total_amount = estimate; /* Should we get a failure inside the routehint we'll * need the direction so we can exclude it. Luckily @@ -3601,6 +3610,7 @@ static void direct_pay_override(struct payment *p) { p->route[0].scid = hint->scid.scid; p->route[0].direction = hint->scid.dir; p->route[0].node_id = *p->route_destination; + p->route[0].total_amount = hint->overall_capacity; paymod_log(p, LOG_DBG, "Found a direct channel (%s) with sufficient " "capacity, skipping route computation.",