Skip to content

Commit ea9ecba

Browse files
committed
renepay: collect shared secrets
Collect the shared secrets when making a payment request. We would need this if we use injectpaymentonion instead of sendonion. Changelog-None. Signed-off-by: Lagrang3 <[email protected]>
1 parent 7cbd763 commit ea9ecba

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

plugins/renepay/json.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct route *tal_route_from_json(const tal_t *ctx, const char *buf,
6464
route->hops = NULL;
6565
route->final_msg = NULL;
6666
route->final_error = LIGHTNINGD;
67+
route->shared_secrets = NULL;
6768

6869
return route;
6970
fail:

plugins/renepay/route.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct route *new_route(const tal_t *ctx, u32 groupid,
2020
route->amount_deliver = amount_deliver;
2121
route->amount_sent = amount_sent;
2222
route->path_num = -1;
23+
route->shared_secrets = NULL;
2324
return route;
2425
}
2526

plugins/renepay/route.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ struct route {
5959
/* The series of channels and nodes to traverse. */
6060
struct route_hop *hops;
6161

62+
/* shared secrets to unwrap the onions */
63+
struct secret *shared_secrets;
64+
6265
/* amounts are redundant here if we know the hops, however sometimes we
6366
* don't know the hops, eg. by calling listsendpays, or if we have
6467
* blinded paths */

plugins/renepay/routetracker.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,28 @@ static void route_pending_register(struct routetracker *routetracker,
195195
/* Callback function for sendpay request success. */
196196
static struct command_result *sendpay_done(struct command *cmd,
197197
const char *method UNUSED,
198-
const char *buf UNUSED,
199-
const jsmntok_t *result UNUSED,
198+
const char *buf,
199+
const jsmntok_t *result,
200200
struct route *route)
201201
{
202202
assert(route);
203203
struct payment *payment = route_get_payment_verify(route);
204204
route_pending_register(payment->routetracker, route);
205+
206+
const jsmntok_t *t;
207+
size_t i;
208+
bool ret;
209+
210+
const jsmntok_t *secretstok =
211+
json_get_member(buf, result, "shared_secrets");
212+
assert(secretstok->type == JSMN_ARRAY);
213+
214+
route->shared_secrets = tal_arr(route, struct secret, secretstok->size);
215+
json_for_each_arr(i, t, secretstok)
216+
{
217+
ret = json_to_secret(buf, t, &route->shared_secrets[i]);
218+
assert(ret);
219+
}
205220
return command_still_pending(cmd);
206221
}
207222

plugins/renepay/sendpay.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,16 @@ static struct command_result *sendonion_done(struct command *cmd,
306306
json_add_hex_talarr(response, "payment_metadata",
307307
renesendpay->metadata);
308308

309+
if (renesendpay->shared_secrets) {
310+
json_array_start(response, "shared_secrets");
311+
for (size_t i = 0; i < tal_count(renesendpay->shared_secrets);
312+
i++) {
313+
json_add_secret(response, NULL,
314+
&renesendpay->shared_secrets[i]);
315+
}
316+
json_array_end(response);
317+
}
318+
309319
/* FIXME: shall we report the blinded path, secret and route used? */
310320
return command_finished(cmd, response);
311321
}
@@ -435,6 +445,7 @@ struct command_result *json_renesendpay(struct command *cmd,
435445
renesendpay->label = tal_steal(renesendpay, label);
436446
renesendpay->description = tal_steal(renesendpay, description);
437447
renesendpay->metadata = tal_steal(renesendpay, metadata);
448+
renesendpay->shared_secrets = NULL;
438449

439450
struct out_req *req =
440451
jsonrpc_request_start(cmd, "waitblockheight", waitblockheight_done,

0 commit comments

Comments
 (0)