Browse Source

paymod: Use reasonable partids

We were just handwaving the partid generation, which broke some tests that
expected the first payment attempt to always have partid=0, so here we just
track the partids assigned in the payment tree, starting at 0.
paymod-02
Christian Decker 5 years ago
parent
commit
8207b4eac8
  1. 21
      plugins/libplugin-pay.c
  2. 2
      plugins/libplugin-pay.h

21
plugins/libplugin-pay.c

@ -42,6 +42,10 @@ struct payment *payment_new(tal_t *ctx, struct command *cmd,
p->destination = p->getroute_destination = parent->destination; p->destination = p->getroute_destination = parent->destination;
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++;
} else {
p->partid = 0;
p->next_partid = 1;
} }
/* Initialize all modifier data so we can point to the fields when /* Initialize all modifier data so we can point to the fields when
@ -60,6 +64,14 @@ struct payment *payment_new(tal_t *ctx, struct command *cmd,
return p; return p;
} }
struct payment *payment_root(struct payment *p)
{
if (p->parent == NULL)
return p;
else
return payment_root(p->parent);
}
/* Generic handler for RPC failures that should end up failing the payment. */ /* Generic handler for RPC failures that should end up failing the payment. */
static struct command_result *payment_rpc_failure(struct command *cmd, static struct command_result *payment_rpc_failure(struct command *cmd,
const char *buffer, const char *buffer,
@ -307,11 +319,14 @@ static struct payment_result *tal_sendpay_result_from_json(const tal_t *ctx,
result = tal(ctx, struct payment_result); result = tal(ctx, struct payment_result);
json_to_u64(buffer, idtok, &result->id); /* If the partid is 0 it'd be omitted in waitsendpay, fix this here. */
if (partidtok != NULL)
json_to_u32(buffer, partidtok, &result->partid); json_to_u32(buffer, partidtok, &result->partid);
/* TODO Fetch the payment_hash here */ else
json_to_msat(buffer, senttok, &result->amount_sent); result->partid = 0;
json_to_u64(buffer, idtok, &result->id);
json_to_msat(buffer, senttok, &result->amount_sent);
if (json_tok_streq(buffer, statustok, "pending")) { if (json_tok_streq(buffer, statustok, "pending")) {
result->state = PAYMENT_PENDING; result->state = PAYMENT_PENDING;
} else if (json_tok_streq(buffer, statustok, "complete")) { } else if (json_tok_streq(buffer, statustok, "complete")) {

2
plugins/libplugin-pay.h

@ -117,6 +117,7 @@ struct payment {
struct sha256 *payment_hash; struct sha256 *payment_hash;
u32 partid; u32 partid;
u32 next_partid;
/* 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
@ -205,5 +206,6 @@ struct payment *payment_new(tal_t *ctx, struct command *cmd,
void payment_start(struct payment *p); void payment_start(struct payment *p);
void payment_continue(struct payment *p); void payment_continue(struct payment *p);
struct payment *payment_root(struct payment *p);
#endif /* LIGHTNING_PLUGINS_LIBPLUGIN_PAY_H */ #endif /* LIGHTNING_PLUGINS_LIBPLUGIN_PAY_H */

Loading…
Cancel
Save