Browse Source

paymod: Wrap the getroute request in a struct

Keeping the arguments in their non-serialized form allows us to amend them as
we apply modifiers and learn new information.
keysend
Christian Decker 5 years ago
parent
commit
e71bdf9ed8
  1. 23
      plugins/libplugin-pay.c
  2. 12
      plugins/libplugin-pay.h
  3. 2
      plugins/pay.c

23
plugins/libplugin-pay.c

@ -20,15 +20,14 @@ struct payment *payment_new(tal_t *ctx, struct command *cmd,
p->cmd = cmd; p->cmd = cmd;
p->start_time = time_now(); p->start_time = time_now();
p->result = NULL; p->result = NULL;
p->getroute_cltv = DEFAULT_FINAL_CLTV_DELTA;
p->why = NULL; p->why = NULL;
p->getroute = tal(p, struct getroute_request);
/* Copy over the relevant pieces of information. */ /* Copy over the relevant pieces of information. */
if (parent != NULL) { if (parent != NULL) {
assert(cmd == NULL); assert(cmd == NULL);
tal_arr_expand(&parent->children, p); tal_arr_expand(&parent->children, p);
p->destination = p->getroute_destination = parent->destination; p->destination = parent->destination;
p->getroute_cltv = parent->getroute_cltv;
p->amount = parent->amount; p->amount = parent->amount;
p->payment_hash = parent->payment_hash; p->payment_hash = parent->payment_hash;
p->partid = payment_root(p->parent)->next_partid++; p->partid = payment_root(p->parent)->next_partid++;
@ -151,9 +150,20 @@ static struct command_result *payment_getinfo_success(struct command *cmd,
void payment_start(struct payment *p) void payment_start(struct payment *p)
{ {
struct payment *root = payment_root(p);
p->step = PAYMENT_STEP_INITIALIZED; p->step = PAYMENT_STEP_INITIALIZED;
p->current_modifier = -1; p->current_modifier = -1;
/* Pre-generate the getroute request, so modifiers can have their say,
* before we actually call `getroute` */
p->getroute->destination = p->destination;
p->getroute->max_hops = ROUTING_MAX_HOPS;
if (root->invoice != NULL && root->invoice->min_final_cltv_expiry != 0)
p->getroute->cltv = root->invoice->min_final_cltv_expiry;
else
p->getroute->cltv = DEFAULT_FINAL_CLTV_DELTA;
p->getroute->amount = p->amount;
/* TODO If this is not the root, we can actually skip the getinfo call /* TODO If this is not the root, we can actually skip the getinfo call
* and just reuse the parent's value. */ * and just reuse the parent's value. */
send_outreq(p->plugin, send_outreq(p->plugin,
@ -290,10 +300,11 @@ static void payment_getroute(struct payment *p)
req = jsonrpc_request_start(p->plugin, NULL, "getroute", req = jsonrpc_request_start(p->plugin, NULL, "getroute",
payment_getroute_result, payment_getroute_result,
payment_getroute_error, p); payment_getroute_error, p);
json_add_node_id(req->js, "id", p->getroute_destination); json_add_node_id(req->js, "id", p->getroute->destination);
json_add_amount_msat_only(req->js, "msatoshi", p->amount); json_add_amount_msat_only(req->js, "msatoshi", p->getroute->amount);
json_add_num(req->js, "riskfactor", 1); json_add_num(req->js, "riskfactor", 1);
json_add_num(req->js, "cltv", p->getroute_cltv); json_add_num(req->js, "cltv", p->getroute->cltv);
json_add_num(req->js, "maxhops", p->getroute->max_hops);
payment_getroute_add_excludes(p, req->js); payment_getroute_add_excludes(p, req->js);
send_outreq(p->plugin, req); send_outreq(p->plugin, req);
} }

12
plugins/libplugin-pay.h

@ -144,6 +144,13 @@ struct payment_tree_result {
struct payment_result *failure; struct payment_result *failure;
}; };
struct getroute_request {
struct node_id *destination;
struct amount_msat amount;
u32 cltv;
u32 max_hops;
};
struct payment { struct payment {
/* The command that triggered this payment. Only set for the root /* The command that triggered this payment. Only set for the root
* payment. */ * payment. */
@ -172,9 +179,8 @@ struct payment {
/* Destination we should ask `getroute` for. This might differ from /* Destination we should ask `getroute` for. This might differ from
* the above destination if we use rendez-vous routing of blinded * the above destination if we use rendez-vous routing of blinded
* paths to amend the route later in a mixin. */ * paths amend the route later in a mixin. */
struct node_id *getroute_destination; struct getroute_request *getroute;
u32 getroute_cltv;
struct createonion_request *createonion_request; struct createonion_request *createonion_request;
struct createonion_response *createonion_response; struct createonion_response *createonion_response;

2
plugins/pay.c

@ -1890,7 +1890,7 @@ static struct command_result *json_paymod(struct command *cmd,
p->local_id = &my_id; p->local_id = &my_id;
p->json_buffer = tal_steal(p, buf); p->json_buffer = tal_steal(p, buf);
p->json_toks = params; p->json_toks = params;
p->destination = p->getroute_destination = &b11->receiver_id; p->destination = &b11->receiver_id;
p->payment_hash = tal_dup(p, struct sha256, &b11->payment_hash); p->payment_hash = tal_dup(p, struct sha256, &b11->payment_hash);
p->payment_secret = b11->payment_secret p->payment_secret = b11->payment_secret
? tal_dup(p, struct secret, b11->payment_secret) ? tal_dup(p, struct secret, b11->payment_secret)

Loading…
Cancel
Save