|
2 | 2 | #include <common/json_stream.h> |
3 | 3 | #include <common/jsonrpc_errors.h> |
4 | 4 | #include <plugins/renepay/renepay.h> |
| 5 | +#include <plugins/renepay/renepayconfig.h> |
5 | 6 | #include <plugins/renepay/routefail.h> |
6 | 7 | #include <plugins/renepay/routetracker.h> |
7 | 8 | #include <plugins/renepay/utils.h> |
8 | 9 | #include <wire/peer_wiregen.h> |
9 | 10 |
|
| 11 | +#define MIN(x, y) ((x) < (y) ? (x) : (y)) |
| 12 | + |
10 | 13 | enum node_type { |
11 | 14 | FINAL_NODE, |
12 | 15 | INTERMEDIATE_NODE, |
@@ -102,6 +105,32 @@ static void bias_channel(struct routefail *r, struct short_channel_id_dir scidd, |
102 | 105 | send_outreq(req); |
103 | 106 | } |
104 | 107 |
|
| 108 | +static void channel_can_send(struct routefail *r, |
| 109 | + struct short_channel_id_dir scidd, |
| 110 | + struct amount_msat amount) |
| 111 | +{ |
| 112 | + struct out_req *req = add_to_rpcbatch( |
| 113 | + r->batch, "askrene-inform-channel", NULL, log_routefail_err, r); |
| 114 | + json_add_string(req->js, "layer", RENEPAY_LAYER); |
| 115 | + json_add_short_channel_id_dir(req->js, "short_channel_id_dir", scidd); |
| 116 | + json_add_amount_msat(req->js, "amount_msat", amount); |
| 117 | + json_add_string(req->js, "inform", "unconstrained"); |
| 118 | + send_outreq(req); |
| 119 | +} |
| 120 | + |
| 121 | +static void channel_cannot_send(struct routefail *r, |
| 122 | + struct short_channel_id_dir scidd, |
| 123 | + struct amount_msat amount) |
| 124 | +{ |
| 125 | + struct out_req *req = add_to_rpcbatch( |
| 126 | + r->batch, "askrene-inform-channel", NULL, log_routefail_err, r); |
| 127 | + json_add_string(req->js, "layer", RENEPAY_LAYER); |
| 128 | + json_add_short_channel_id_dir(req->js, "short_channel_id_dir", scidd); |
| 129 | + json_add_amount_msat(req->js, "amount_msat", amount); |
| 130 | + json_add_string(req->js, "inform", "constrained"); |
| 131 | + send_outreq(req); |
| 132 | +} |
| 133 | + |
105 | 134 | /***************************************************************************** |
106 | 135 | * update_gossip |
107 | 136 | * |
@@ -301,6 +330,25 @@ static void handle_failure(struct routefail *r) |
301 | 330 | node_type = ORIGIN_NODE; |
302 | 331 | else |
303 | 332 | node_type = INTERMEDIATE_NODE; |
| 333 | + |
| 334 | + /* All channels before the hop that failed have supposedly the |
| 335 | + * ability to forward the payment. This is information. */ |
| 336 | + const int last_good_channel = |
| 337 | + MIN(*result->erring_index, path_len) - 1; |
| 338 | + for (int i = 0; i <= last_good_channel; i++) { |
| 339 | + scidd.scid = route->hops[i].scid; |
| 340 | + scidd.dir = route->hops[i].direction; |
| 341 | + channel_can_send(r, scidd, route->hops[i].amount); |
| 342 | + } |
| 343 | + if (failcode == WIRE_TEMPORARY_CHANNEL_FAILURE && |
| 344 | + (last_good_channel + 1) < path_len) { |
| 345 | + scidd.scid = route->hops[last_good_channel + 1].scid; |
| 346 | + scidd.dir = |
| 347 | + route->hops[last_good_channel + 1].direction; |
| 348 | + channel_cannot_send( |
| 349 | + r, scidd, |
| 350 | + route->hops[last_good_channel + 1].amount); |
| 351 | + } |
304 | 352 | } |
305 | 353 |
|
306 | 354 | switch (failcode) { |
|
0 commit comments