| 537 | } |
| 538 | |
| 539 | void 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 { |
no test coverage detected