From 818a4d14cb3e0b879d97096d069a0f324e4eee5c Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 4 Oct 2021 14:28:11 +0200 Subject: [PATCH] paycore: Default `groupid` to increment from last one This re-establishes the prior behavior where a `sendpay` or `sendonion` that'd match a prior payment would cause the prior payment to be deleted. While we no longer delete prior attempts we now avoid a primary key collision by incrementing once. This helps us not having to touch all existing tests, and likely avoids breaking other users too. --- lightningd/pay.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lightningd/pay.c b/lightningd/pay.c index 5ae434018..35100e023 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -1284,10 +1284,18 @@ static struct command_result *json_sendonion(struct command *cmd, p_opt_def("msatoshi", param_msat, &msat, AMOUNT_MSAT(0)), p_opt("destination", param_node_id, &destination), p_opt("localofferid", param_sha256, &local_offer_id), - p_opt_def("groupid", param_u64, &group, 0), + p_opt("groupid", param_u64, &group), NULL)) return command_param_failed(); + /* If groupid was not provided default to incrementing from the previous one. */ + if (group == NULL) { + group = tal(tmpctx, u64); + *group = + wallet_payment_get_groupid(cmd->ld->wallet, payment_hash) + + 1; + } + packet = parse_onionpacket(cmd, onion, tal_bytelen(onion), &failcode); if (!packet) @@ -1437,7 +1445,7 @@ static struct command_result *json_sendpay(struct command *cmd, p_opt("payment_secret", param_secret, &payment_secret), p_opt_def("partid", param_u64, &partid, 0), p_opt("localofferid", param_sha256, &local_offer_id), - p_opt_def("groupid", param_u64, &group, 0), + p_opt("groupid", param_u64, &group), NULL)) return command_param_failed(); @@ -1447,6 +1455,12 @@ static struct command_result *json_sendpay(struct command *cmd, const struct amount_msat final_amount = route[tal_count(route)-1].amount; + /* If groupid was not provided default to incrementing from the previous one. */ + if (group == NULL) { + group = tal(tmpctx, u64); + *group = wallet_payment_get_groupid(cmd->ld->wallet, rhash) + 1; + } + if (msat && !*partid && !amount_msat_eq(*msat, final_amount)) return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Do not specify msatoshi (%s) without"