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.
This commit is contained in:
Christian Decker 2021-10-04 14:28:11 +02:00 committed by Rusty Russell
parent ec9040577e
commit 818a4d14cb
1 changed files with 16 additions and 2 deletions

View File

@ -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_def("msatoshi", param_msat, &msat, AMOUNT_MSAT(0)),
p_opt("destination", param_node_id, &destination), p_opt("destination", param_node_id, &destination),
p_opt("localofferid", param_sha256, &local_offer_id), p_opt("localofferid", param_sha256, &local_offer_id),
p_opt_def("groupid", param_u64, &group, 0), p_opt("groupid", param_u64, &group),
NULL)) NULL))
return command_param_failed(); 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); packet = parse_onionpacket(cmd, onion, tal_bytelen(onion), &failcode);
if (!packet) 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("payment_secret", param_secret, &payment_secret),
p_opt_def("partid", param_u64, &partid, 0), p_opt_def("partid", param_u64, &partid, 0),
p_opt("localofferid", param_sha256, &local_offer_id), p_opt("localofferid", param_sha256, &local_offer_id),
p_opt_def("groupid", param_u64, &group, 0), p_opt("groupid", param_u64, &group),
NULL)) NULL))
return command_param_failed(); 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; 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)) if (msat && !*partid && !amount_msat_eq(*msat, final_amount))
return command_fail(cmd, JSONRPC2_INVALID_PARAMS, return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Do not specify msatoshi (%s) without" "Do not specify msatoshi (%s) without"