mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-15 20:09:18 +01:00
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.
This commit is contained in:
parent
d60db28c41
commit
1eb878be82
3 changed files with 19 additions and 1 deletions
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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.",
|
||||
|
|
Loading…
Add table
Reference in a new issue