mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-12 02:08:15 +01:00
fetchinvoice: don't stash path in sent object, hand directly.
Simplification. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
a6cfdea71b
commit
ef641e81c6
1 changed files with 13 additions and 15 deletions
|
@ -36,8 +36,6 @@ struct sent {
|
||||||
struct command *cmd;
|
struct command *cmd;
|
||||||
/* The offer we are trying to get an invoice/payment for. */
|
/* The offer we are trying to get an invoice/payment for. */
|
||||||
struct tlv_offer *offer;
|
struct tlv_offer *offer;
|
||||||
/* Path to use (including self) */
|
|
||||||
const struct pubkey *path;
|
|
||||||
|
|
||||||
/* When creating blinded return path, use scid not pubkey for intro node. */
|
/* When creating blinded return path, use scid not pubkey for intro node. */
|
||||||
struct short_channel_id_dir *dev_path_use_scidd;
|
struct short_channel_id_dir *dev_path_use_scidd;
|
||||||
|
@ -408,25 +406,24 @@ static struct command_result *param_offer(struct command *cmd,
|
||||||
|
|
||||||
static struct blinded_path *make_reply_path(const tal_t *ctx,
|
static struct blinded_path *make_reply_path(const tal_t *ctx,
|
||||||
const struct sent *sent,
|
const struct sent *sent,
|
||||||
|
const struct pubkey *path,
|
||||||
struct secret *reply_secret)
|
struct secret *reply_secret)
|
||||||
{
|
{
|
||||||
struct pubkey *ids;
|
struct pubkey *ids;
|
||||||
|
|
||||||
/* FIXME: Maybe we should allow this? */
|
assert(tal_count(path) > 0);
|
||||||
if (tal_count(sent->path) == 1)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
randombytes_buf(reply_secret, sizeof(struct secret));
|
randombytes_buf(reply_secret, sizeof(struct secret));
|
||||||
|
|
||||||
if (sent->dev_reply_path) {
|
if (sent->dev_reply_path) {
|
||||||
ids = sent->dev_reply_path;
|
ids = sent->dev_reply_path;
|
||||||
} else {
|
} else {
|
||||||
size_t nhops = tal_count(sent->path);
|
size_t nhops = tal_count(path);
|
||||||
/* FIXME: Could create an independent reply path, not just
|
/* FIXME: Could create an independent reply path, not just
|
||||||
* reverse existing. */
|
* reverse existing. */
|
||||||
ids = tal_arr(tmpctx, struct pubkey, nhops - 1);
|
ids = tal_arr(tmpctx, struct pubkey, nhops - 1);
|
||||||
for (int i = nhops - 2; i >= 0; i--)
|
for (int i = nhops - 2; i >= 0; i--)
|
||||||
ids[nhops - 2 - i] = sent->path[i];
|
ids[nhops - 2 - i] = path[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -436,6 +433,7 @@ static struct blinded_path *make_reply_path(const tal_t *ctx,
|
||||||
|
|
||||||
static struct command_result *send_message(struct command *cmd,
|
static struct command_result *send_message(struct command *cmd,
|
||||||
struct sent *sent,
|
struct sent *sent,
|
||||||
|
const struct pubkey *path,
|
||||||
struct tlv_onionmsg_tlv *final_tlv,
|
struct tlv_onionmsg_tlv *final_tlv,
|
||||||
struct command_result *(*done)
|
struct command_result *(*done)
|
||||||
(struct command *cmd,
|
(struct command *cmd,
|
||||||
|
@ -448,19 +446,21 @@ static struct command_result *send_message(struct command *cmd,
|
||||||
/* Create transient secret so we can validate reply! */
|
/* Create transient secret so we can validate reply! */
|
||||||
sent->reply_secret = tal(sent, struct secret);
|
sent->reply_secret = tal(sent, struct secret);
|
||||||
|
|
||||||
/* Add reply path to final_tlv (it already contains invoice_request/invoice) */
|
/* FIXME: Maybe we should allow this? */
|
||||||
final_tlv->reply_path = make_reply_path(final_tlv, sent, sent->reply_secret);
|
if (tal_count(path) == 1)
|
||||||
if (!final_tlv->reply_path)
|
|
||||||
return command_fail(cmd, PAY_ROUTE_NOT_FOUND,
|
return command_fail(cmd, PAY_ROUTE_NOT_FOUND,
|
||||||
"Refusing to talk to ourselves");
|
"Refusing to talk to ourselves");
|
||||||
|
|
||||||
|
/* Add reply path to final_tlv (it already contains invoice_request/invoice) */
|
||||||
|
final_tlv->reply_path = make_reply_path(final_tlv, sent, path, sent->reply_secret);
|
||||||
|
|
||||||
/* Replace first hop with scidd if they said to */
|
/* Replace first hop with scidd if they said to */
|
||||||
if (sent->dev_path_use_scidd)
|
if (sent->dev_path_use_scidd)
|
||||||
sciddir_or_pubkey_from_scidd(&final_tlv->reply_path->first_node_id,
|
sciddir_or_pubkey_from_scidd(&final_tlv->reply_path->first_node_id,
|
||||||
sent->dev_path_use_scidd);
|
sent->dev_path_use_scidd);
|
||||||
|
|
||||||
/* FIXME: use their blinded path if they supplied one! */
|
/* FIXME: use their blinded path if they supplied one! */
|
||||||
omsg = outgoing_onion_message(tmpctx, sent->path, NULL, NULL, final_tlv);
|
omsg = outgoing_onion_message(tmpctx, path, NULL, NULL, final_tlv);
|
||||||
return inject_onionmessage(cmd, omsg, done, forward_error, sent);
|
return inject_onionmessage(cmd, omsg, done, forward_error, sent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,9 +498,8 @@ static struct command_result *fetchinvoice_path_done(struct command *cmd,
|
||||||
|
|
||||||
payload->invoice_request = tal_arr(payload, u8, 0);
|
payload->invoice_request = tal_arr(payload, u8, 0);
|
||||||
towire_tlv_invoice_request(&payload->invoice_request, sent->invreq);
|
towire_tlv_invoice_request(&payload->invoice_request, sent->invreq);
|
||||||
sent->path = tal_steal(sent, path);
|
|
||||||
|
|
||||||
return send_message(cmd, sent, payload, sendonionmsg_done);
|
return send_message(cmd, sent, path, payload, sendonionmsg_done);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct command_result *fetchinvoice_path_fail(struct command *cmd,
|
static struct command_result *fetchinvoice_path_fail(struct command *cmd,
|
||||||
|
@ -913,9 +912,8 @@ static struct command_result *sendinvoice_path_done(struct command *cmd,
|
||||||
|
|
||||||
payload->invoice = tal_arr(payload, u8, 0);
|
payload->invoice = tal_arr(payload, u8, 0);
|
||||||
towire_tlv_invoice(&payload->invoice, sent->inv);
|
towire_tlv_invoice(&payload->invoice, sent->inv);
|
||||||
sent->path = tal_steal(sent, path);
|
|
||||||
|
|
||||||
return send_message(cmd, sent, payload, prepare_inv_timeout);
|
return send_message(cmd, sent, path, payload, prepare_inv_timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct command_result *sendinvoice_path_fail(struct command *cmd,
|
static struct command_result *sendinvoice_path_fail(struct command *cmd,
|
||||||
|
|
Loading…
Add table
Reference in a new issue