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

Function on_payment_failure

plugins/pay.c:694–805  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

692}
693
694static void on_payment_failure(struct payment *payment)
695{
696 struct payment *p, *nxt;
697 struct payment_tree_result result = payment_collect_result(payment);
698 list_for_each_safe(&payments, p, nxt, list)
699 {
700 struct json_stream *ret;
701 struct command *cmd;
702 const char *msg;
703 /* The result for the active payment is returned in
704 * `payment_finished`. */
705 if (payment == p)
706 continue;
707
708 /* When we suspended we've set the groupid to match so
709 * we'd know which calls were duplicates. */
710 if (!sha256_eq(payment->payment_hash, p->payment_hash) ||
711 payment->groupid != p->groupid)
712 continue;
713 if (p->cmd == NULL)
714 continue;
715
716 cmd = p->cmd;
717 p->cmd = NULL;
718 if (p->aborterror != NULL) {
719 /* We set an explicit toplevel error message,
720 * so let's report that. */
721 ret = jsonrpc_stream_fail(cmd, PAY_STOPPED_RETRYING,
722 p->aborterror);
723 payment_json_add_attempts(ret, "attempts", p);
724
725 if (command_finished(cmd, ret)) {/* Ignore result. */}
726 } else if (result.failure == NULL || result.failure->failcode < NODE) {
727 /* This is failing because we have no more routes to try */
728 msg = tal_fmt(cmd,
729 "Ran out of routes to try after "
730 "%d attempt%s: see `paystatus`",
731 result.attempts,
732 result.attempts == 1 ? "" : "s");
733 ret = jsonrpc_stream_fail(cmd, PAY_STOPPED_RETRYING,
734 msg);
735 payment_json_add_attempts(ret, "attempts", p);
736
737 if (command_finished(cmd, ret)) {/* Ignore result. */}
738
739 } else {
740 struct payment_result *failure = result.failure;
741 assert(failure!= NULL);
742
743 ret = jsonrpc_stream_fail(cmd, failure->code,
744 failure->message);
745
746 json_add_u64(ret, "id", failure->id);
747
748 json_add_u32(ret, "failcode", failure->failcode);
749 json_add_string(ret, "failcodename",
750 failure->failcodename);
751

Callers

nothing calls this directly

Calls 14

payment_collect_resultFunction · 0.85
jsonrpc_stream_failFunction · 0.70
command_finishedFunction · 0.70
json_add_u64Function · 0.50
json_add_u32Function · 0.50
json_add_stringFunction · 0.50
json_add_invstringFunction · 0.50
json_add_hex_talarrFunction · 0.50
json_add_numFunction · 0.50
json_add_node_idFunction · 0.50
json_add_sha256Function · 0.50

Tested by

no test coverage detected