Skip to content

Commit 1ecdf9f

Browse files
committed
renepay: refactor and bugfixes
We remove the auxiliary RPC renesenday (only used internally) in favor of a function that builds the onion, stores the shared secrets needed to recover the onion reply, and calls sendonion/injectpaymentonion. This solves a concurrency race ``` **BROKEN** plugin-cln-renepay: Unable to parse sendpay_failure ``` in which we are waiting for renesenday to return in order to record the shared secrets but we get the a sendpay_failure notification with an onionreply before we have secrets to decode it. It also solves a missing JSON id seen in the logs ``` DEBUG plugin-cln-renepay: JSON reply with unknown id ``` because renesendpay was using his command variable to issue an RPC to sendonion/injecpaymentonion and would fail or succeed the command before those RPCs were done. This also meant that the callback functions were silently being ignored. Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
1 parent f0e9547 commit 1ecdf9f

File tree

8 files changed

+269
-742
lines changed

8 files changed

+269
-742
lines changed

plugins/renepay/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ PLUGIN_RENEPAY_SRC := \
1010
plugins/renepay/routebuilder.c \
1111
plugins/renepay/routetracker.c \
1212
plugins/renepay/routefail.c \
13-
plugins/renepay/sendpay.c \
1413
plugins/renepay/uncertainty.c \
1514
plugins/renepay/mods.c \
1615
plugins/renepay/errorcodes.c \
@@ -30,7 +29,6 @@ PLUGIN_RENEPAY_HDRS := \
3029
plugins/renepay/routebuilder.h \
3130
plugins/renepay/routetracker.h \
3231
plugins/renepay/routefail.h \
33-
plugins/renepay/sendpay.h \
3432
plugins/renepay/uncertainty.h \
3533
plugins/renepay/mods.h \
3634
plugins/renepay/errorcodes.h \

plugins/renepay/main.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <plugins/renepay/mods.h>
2020
#include <plugins/renepay/payplugin.h>
2121
#include <plugins/renepay/routetracker.h>
22-
#include <plugins/renepay/sendpay.h>
2322
#include <stdio.h>
2423

2524
// TODO(eduardo): notice that pending attempts performed with another
@@ -460,10 +459,6 @@ static const struct plugin_command commands[] = {
460459
"renepay",
461460
json_renepay
462461
},
463-
{
464-
"renesendpay",
465-
json_renesendpay
466-
},
467462
};
468463

469464
static const struct plugin_notification notifications[] = {

plugins/renepay/mods.c

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -753,10 +753,30 @@ REGISTER_PAYMENT_MODIFIER(compute_routes, compute_routes_cb);
753753
* request calling sendpay.
754754
*/
755755

756-
static struct command_result *send_routes_cb(struct payment *payment)
756+
static struct command_result *waitblockheight_done(struct command *cmd,
757+
const char *method UNUSED,
758+
const char *buf,
759+
const jsmntok_t *result,
760+
struct payment *payment)
757761
{
758-
assert(payment);
759-
struct routetracker *routetracker = payment->routetracker;
762+
const char *err;
763+
struct command *aux_cmd;
764+
struct route *route;
765+
struct routetracker *routetracker;
766+
767+
err = json_scan(tmpctx, buf, result, "{blockheight:%}",
768+
JSON_SCAN(json_to_u32, &payment->blockheight));
769+
payment->blockheight += 1;
770+
771+
if (err) {
772+
plugin_err(pay_plugin->plugin,
773+
"Failed to read blockheight from waitblockheight "
774+
"response: %s",
775+
err);
776+
return payment_continue(payment);
777+
}
778+
779+
routetracker = payment->routetracker;
760780
assert(routetracker);
761781
if (!routetracker->computed_routes ||
762782
tal_count(routetracker->computed_routes) == 0) {
@@ -765,12 +785,11 @@ static struct command_result *send_routes_cb(struct payment *payment)
765785
__func__);
766786
return payment_continue(payment);
767787
}
768-
struct command *cmd = payment_command(payment);
769-
assert(cmd);
770788
for (size_t i = 0; i < tal_count(routetracker->computed_routes); i++) {
771-
struct route *route = routetracker->computed_routes[i];
789+
aux_cmd = aux_command(cmd);
790+
route = routetracker->computed_routes[i];
772791

773-
route_sendpay_request(cmd, take(route), payment);
792+
route_sendpay_request(aux_cmd, take(route), payment);
774793

775794
payment_note(payment, LOG_INFORM,
776795
"Sent route request: partid=%" PRIu64
@@ -785,6 +804,22 @@ static struct command_result *send_routes_cb(struct payment *payment)
785804
return payment_continue(payment);
786805
}
787806

807+
static struct command_result *send_routes_cb(struct payment *payment)
808+
{
809+
struct command *cmd;
810+
struct out_req *req;
811+
assert(payment);
812+
cmd = payment_command(payment);
813+
if (!cmd)
814+
plugin_err(pay_plugin->plugin,
815+
"send_routes_pay_mod: cannot get a valid cmd.");
816+
req =
817+
jsonrpc_request_start(cmd, "waitblockheight", waitblockheight_done,
818+
payment_rpc_failure, payment);
819+
json_add_num(req->js, "blockheight", 0);
820+
return send_outreq(req);
821+
}
822+
788823
REGISTER_PAYMENT_MODIFIER(send_routes, send_routes_cb);
789824

790825
/*****************************************************************************

plugins/renepay/payment.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ struct payment {
7373
struct plugin_timer *waitresult_timer;
7474

7575
struct routetracker *routetracker;
76+
77+
/* use this to build the onions */
78+
u32 blockheight;
7679
};
7780

7881
static inline const struct sha256 payment_hash(const struct payment *p)

0 commit comments

Comments
 (0)