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

Function payment_failed

lightningd/pay.c:539–653  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 3

fail_out_htlcFunction · 0.70
rcvd_htlc_replyFunction · 0.70
onchain_failed_our_htlcFunction · 0.70

Calls 13

wallet_payment_by_hashFunction · 0.85
local_routing_failureFunction · 0.85
unwrap_onionreplyFunction · 0.85
log_infoClass · 0.85
tal_hexFunction · 0.85
onion_wire_nameFunction · 0.85
remote_routing_failureFunction · 0.85
tell_waiters_failedFunction · 0.85
payment_storeFunction · 0.70
type_to_stringClass · 0.50

Tested by

no test coverage detected