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

Function payment_failed

lightningd/pay.c:546–659  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

544}
545
546void payment_failed(struct lightningd *ld,
547 struct logger *log,
548 const struct sha256 *payment_hash,
549 u64 partid, u64 groupid,
550 const struct onionreply *failonion,
551 const u8 *failmsg,
552 const char *localfail)
553{
554 struct wallet_payment *payment;
555 struct routing_failure* fail = NULL;
556 const char *failstr;
557 enum jsonrpc_errcode pay_errcode;
558 int origin_index;
559
560 payment = wallet_payment_by_hash(tmpctx, ld->wallet,
561 payment_hash,
562 partid, groupid);
563
564#ifdef COMPAT_V052
565 /* Prior to "pay: delete HTLC when we delete payment." we would
566 * delete a payment on retry, but leave the HTLC. */
567 if (!payment) {
568 log_unusual(log,
569 "No payment for %s:"
570 " was this an old database?",
571 fmt_sha256(tmpctx, payment_hash));
572 return;
573 }
574#else
575 assert(payment);
576#endif
577 assert((payment->route_channels == NULL) == (payment->route_nodes == NULL));
578
579 /* This gives more details than a generic failure message */
580 if (localfail) {
581 /* Use temporary_channel_failure if failmsg has it */
582 enum onion_wire failcode;
583 failcode = fromwire_peektype(failmsg);
584
585 fail = local_routing_failure(tmpctx, ld, failcode, payment);
586 log_debug(log, "local_routing_failure: %u (%s)",
587 fail->failcode,
588 onion_wire_name(fail->failcode));
589 failstr = localfail;
590 pay_errcode = PAY_TRY_OTHER_ROUTE;
591 } else if (failmsg) {
592 /* This can happen when a direct peer told channeld it's a
593 * malformed onion using update_fail_malformed_htlc. */
594 failstr = "local failure";
595 origin_index = 0;
596 pay_errcode = PAY_TRY_OTHER_ROUTE;
597 goto use_failmsg;
598 } else if (payment->path_secrets == NULL) {
599 /* This was a payment initiated with `sendonion`/`injectonionmessage`, we therefore
600 * don't have the path secrets and cannot decode the error
601 * onion. We hand it to the user. */
602 assert(failonion != NULL);
603 pay_errcode = PAY_UNPARSEABLE_ONION;

Callers 4

selfpay_mpp_failFunction · 0.85
fail_out_htlcFunction · 0.85
rcvd_htlc_replyFunction · 0.85
onchain_failed_our_htlcFunction · 0.85

Calls 11

wallet_payment_by_hashFunction · 0.85
fmt_sha256Function · 0.85
fromwire_peektypeFunction · 0.85
local_routing_failureFunction · 0.85
unwrap_onionreplyFunction · 0.85
log_infoClass · 0.85
tal_hexFunction · 0.85
remote_routing_failureFunction · 0.85
tell_waiters_failedFunction · 0.85

Tested by

no test coverage detected