MCPcopy Create free account
hub / github.com/ElementsProject/lightning / check_progress

Function check_progress

lightningd/pay.c:900–1069  ·  view source on GitHub ↗

Check if payment already in progress. Returns NULL if all good. * Sets *succeeded_payment if we had a previous successful payment for this hash. */

Source from the content-addressed store, hash-verified

898/* Check if payment already in progress. Returns NULL if all good.
899 * Sets *succeeded_payment if we had a previous successful payment for this hash. */
900static struct command_result *check_progress(struct lightningd *ld,
901 struct command *cmd,
902 const struct sha256 *rhash,
903 struct amount_msat msat,
904 struct amount_msat total_msat,
905 u64 partid,
906 u64 group,
907 const struct node_id *destination,
908 const struct wallet_payment **succeeded_payment)
909{
910 bool have_complete = false;
911 struct amount_msat msat_already_pending = AMOUNT_MSAT(0);
912
913 *succeeded_payment = NULL;
914
915 /* Now, do we already have one or more payments? */
916 for (struct db_stmt *stmt = payments_by_hash(cmd->ld->wallet, rhash);
917 stmt;
918 stmt = payments_next(cmd->ld->wallet, stmt)) {
919 const struct wallet_payment *payment;
920
921 payment = payment_get_details(tmpctx, stmt);
922 log_debug(ld->log, "Payment: %s %s",
923 fmt_amount_msat(tmpctx, payment->msatoshi),
924 payment->status == PAYMENT_COMPLETE ? "COMPLETE"
925 : payment->status == PAYMENT_PENDING ? "PENDING"
926 : "FAILED");
927
928 switch (payment->status) {
929 case PAYMENT_COMPLETE:
930 have_complete = true;
931 if (payment->partid != partid)
932 continue;
933
934 tal_free(stmt);
935
936 /* Must match successful payment parameters. */
937 if (!amount_msat_eq(payment->msatoshi, msat)) {
938 return command_fail(cmd, PAY_RHASH_ALREADY_USED,
939 "Already succeeded "
940 "with amount %s (not %s)",
941 fmt_amount_msat(tmpctx,
942 payment->msatoshi),
943 fmt_amount_msat(tmpctx,
944 msat));
945 }
946 if (payment->destination && destination
947 && !node_id_eq(payment->destination,
948 destination)) {
949 return command_fail(cmd, PAY_RHASH_ALREADY_USED,
950 "Already succeeded to %s",
951 fmt_node_id(tmpctx,
952 payment->destination));
953 }
954 *succeeded_payment = payment;
955 return NULL;
956
957 case PAYMENT_PENDING:

Callers 2

send_payment_coreFunction · 0.85
json_injectpaymentonionFunction · 0.85

Calls 14

payments_by_hashFunction · 0.85
payments_nextFunction · 0.85
payment_get_detailsFunction · 0.85
tal_freeFunction · 0.85
node_id_eqFunction · 0.85
fmt_node_idFunction · 0.85
json_sendpay_in_progressFunction · 0.85
amount_msat_accumulateFunction · 0.85
fmt_sha256Function · 0.85
amount_msat_is_zeroFunction · 0.85
amount_msat_greater_eqFunction · 0.85
command_failFunction · 0.70

Tested by

no test coverage detected