Returns the greatest amount we can deliver to the destination using this * route. It takes into account the current knowledge, pending HTLC, * htlc_max and fees. * * It fails if the maximum that we can * deliver at node i is smaller than the minimum required to forward the least * amount greater than zero to the next node. */
| 73 | * deliver at node i is smaller than the minimum required to forward the least |
| 74 | * amount greater than zero to the next node. */ |
| 75 | enum renepay_errorcode |
| 76 | flow_maximum_deliverable(struct amount_msat *max_deliverable, |
| 77 | const struct flow *flow, |
| 78 | const struct gossmap *gossmap, |
| 79 | struct chan_extra_map *chan_extra_map, |
| 80 | const struct gossmap_chan **bad_channel) |
| 81 | { |
| 82 | assert(tal_count(flow->path) > 0); |
| 83 | assert(tal_count(flow->dirs) > 0); |
| 84 | assert(tal_count(flow->path) == tal_count(flow->dirs)); |
| 85 | struct amount_msat x; |
| 86 | enum renepay_errorcode err; |
| 87 | |
| 88 | err = channel_liquidity(&x, gossmap, chan_extra_map, flow->path[0], |
| 89 | flow->dirs[0]); |
| 90 | if(err){ |
| 91 | if(bad_channel)*bad_channel = flow->path[0]; |
| 92 | return err; |
| 93 | } |
| 94 | x = amount_msat_min(x, gossmap_chan_htlc_max(flow->path[0], flow->dirs[0])); |
| 95 | |
| 96 | if(amount_msat_is_zero(x)) |
| 97 | { |
| 98 | if(bad_channel)*bad_channel = flow->path[0]; |
| 99 | return RENEPAY_BAD_CHANNEL; |
| 100 | } |
| 101 | |
| 102 | for (size_t i = 1; i < tal_count(flow->path); ++i) { |
| 103 | // ith node can forward up to 'liquidity_cap' because of the ith |
| 104 | // channel liquidity bound |
| 105 | struct amount_msat liquidity_cap; |
| 106 | |
| 107 | err = channel_liquidity(&liquidity_cap, gossmap, chan_extra_map, |
| 108 | flow->path[i], flow->dirs[i]); |
| 109 | if(err) { |
| 110 | if(bad_channel)*bad_channel = flow->path[i]; |
| 111 | return err; |
| 112 | } |
| 113 | |
| 114 | /* ith node can receive up to 'x', therefore he will not forward |
| 115 | * more than 'forward_cap' that we compute below inverting the |
| 116 | * fee equation. */ |
| 117 | struct amount_msat forward_cap; |
| 118 | err = channel_maximum_forward(&forward_cap, flow->path[i], |
| 119 | flow->dirs[i], x); |
| 120 | if(err) |
| 121 | { |
| 122 | if(bad_channel)*bad_channel = flow->path[i]; |
| 123 | return err; |
| 124 | } |
| 125 | struct amount_msat x_new = |
| 126 | amount_msat_min(forward_cap, liquidity_cap); |
| 127 | x_new = amount_msat_min( |
| 128 | x_new, gossmap_chan_htlc_max(flow->path[i], flow->dirs[i])); |
| 129 | |
| 130 | /* safety check: amounts decrease along the route */ |
| 131 | assert(amount_msat_less_eq(x_new, x)); |
| 132 |
no test coverage detected