Skip to content

Commit fecfbf6

Browse files
committed
renepay: use askrene-inform-channel
Use askrene-inform-channel to update the knowledge of the liquidity when a payment attempt fails. Changelog-None Signed-off-by: Lagrang3 <[email protected]>
1 parent 132057a commit fecfbf6

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

plugins/renepay/routefail.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
#include <common/json_stream.h>
33
#include <common/jsonrpc_errors.h>
44
#include <plugins/renepay/renepay.h>
5+
#include <plugins/renepay/renepayconfig.h>
56
#include <plugins/renepay/routefail.h>
67
#include <plugins/renepay/routetracker.h>
78
#include <plugins/renepay/utils.h>
89
#include <wire/peer_wiregen.h>
910

11+
#define MIN(x, y) ((x) < (y) ? (x) : (y))
12+
1013
enum node_type {
1114
FINAL_NODE,
1215
INTERMEDIATE_NODE,
@@ -102,6 +105,32 @@ static void bias_channel(struct routefail *r, struct short_channel_id_dir scidd,
102105
send_outreq(req);
103106
}
104107

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+
105134
/*****************************************************************************
106135
* update_gossip
107136
*
@@ -301,6 +330,25 @@ static void handle_failure(struct routefail *r)
301330
node_type = ORIGIN_NODE;
302331
else
303332
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+
}
304352
}
305353

306354
switch (failcode) {

plugins/renepay/routetracker.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ struct command_result *notification_sendpay_success(struct command *cmd,
342342
json_tok_full_len(sub), json_tok_full(buf, sub));
343343

344344
assert(route->result->status == SENDPAY_COMPLETE);
345+
// FIXME: call askrene-inform-channel with inform=succeeded for this
346+
// route
345347
routetracker_add_to_final(payment, payment->routetracker, route);
346348
return notification_handled(cmd);
347349
}

0 commit comments

Comments
 (0)