mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-26 20:30:59 +01:00
askrene: fix up our handling of htlc_max.
It seems we didn't handle it correctly: we need to cap the first segment as well as the others, as far as I can tell. Also, it can be less than the maximum capacity. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
975326ab5d
commit
fafda82d82
1 changed files with 9 additions and 4 deletions
|
@ -436,6 +436,13 @@ static struct arc node_adjacency_next(
|
|||
return linear_network->node_adjacency_next_arc[arc.idx];
|
||||
}
|
||||
|
||||
/* Set *capacity to value, up to *cap_on_capacity. Reduce cap_on_capacity */
|
||||
static void set_capacity(s64 *capacity, u64 value, u64 *cap_on_capacity)
|
||||
{
|
||||
*capacity = MIN(value, *cap_on_capacity);
|
||||
*cap_on_capacity -= *capacity;
|
||||
}
|
||||
|
||||
// TODO(eduardo): unit test this
|
||||
/* Split a directed channel into parts with linear cost function. */
|
||||
static void linearize_channel(const struct pay_parameters *params,
|
||||
|
@ -457,13 +464,11 @@ static void linearize_channel(const struct pay_parameters *params,
|
|||
* that it does not exceed htlcmax. */
|
||||
u64 cap_on_capacity = fp16_to_u64(c->half[dir].htlc_max) / 1000;
|
||||
|
||||
capacity[0]=a;
|
||||
set_capacity(&capacity[0], a, &cap_on_capacity);
|
||||
cost[0]=0;
|
||||
for(size_t i=1;i<CHANNEL_PARTS;++i)
|
||||
{
|
||||
capacity[i] = MIN(params->cap_fraction[i]*(b-a), cap_on_capacity);
|
||||
assert(cap_on_capacity >= capacity[i]);
|
||||
cap_on_capacity -= capacity[i];
|
||||
set_capacity(&capacity[i], params->cap_fraction[i]*(b-a), &cap_on_capacity);
|
||||
|
||||
cost[i] = params->cost_fraction[i]
|
||||
*params->amount.millisatoshis /* Raw: linearize_channel */
|
||||
|
|
Loading…
Add table
Reference in a new issue