pay: Fail a sendpay or sendonion that'd produce a DB collision

This commit is contained in:
Christian Decker
2021-10-04 19:27:30 +02:00
committed by Rusty Russell
parent bc089d3350
commit 6196d2f559

View File

@@ -985,6 +985,22 @@ send_payment_core(struct lightningd *ld,
if (payments[i]->partid == partid)
old_payment = payments[i];
}
/* There is no way for us to add a payment with the
* same (payment_hash, partid, groupid) tuple since
* it'd collide with the database primary key. So
* report this as soon as possible. */
if (payments[i]->partid == partid && payments[i]->groupid == group) {
return command_fail(
cmd, PAY_RHASH_ALREADY_USED,
"There already is a payment with payment_hash=%s, "
"groupid=%" PRIu64 ", partid=%" PRIu64
". Either change the partid, or wait for the "
"payment to complete and start a new group.",
type_to_string(tmpctx, struct sha256, rhash), group,
partid);
}
}
/* If any part has succeeded, you can't start a new one! */