| 544 | } |
| 545 | |
| 546 | void 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; |
no test coverage detected