Fills in *pay_errcode with PAY_TRY_OTHER_ROUTE or PAY_DESTINATION_PERM_FAIL */
| 438 | |
| 439 | /* Fills in *pay_errcode with PAY_TRY_OTHER_ROUTE or PAY_DESTINATION_PERM_FAIL */ |
| 440 | static struct routing_failure* |
| 441 | remote_routing_failure(const tal_t *ctx, |
| 442 | struct lightningd *ld, |
| 443 | const struct wallet_payment *payment, |
| 444 | const u8 *failuremsg, |
| 445 | int origin_index, |
| 446 | struct logger *log, |
| 447 | enum jsonrpc_errcode *pay_errcode) |
| 448 | { |
| 449 | enum onion_wire failcode = fromwire_peektype(failuremsg); |
| 450 | struct routing_failure *routing_failure; |
| 451 | const struct node_id *route_nodes; |
| 452 | const struct node_id *erring_node; |
| 453 | const struct short_channel_id *route_channels; |
| 454 | const struct short_channel_id *erring_channel; |
| 455 | int dir; |
| 456 | |
| 457 | routing_failure = tal(ctx, struct routing_failure); |
| 458 | route_nodes = payment->route_nodes; |
| 459 | route_channels = payment->route_channels; |
| 460 | |
| 461 | assert(route_nodes == NULL || origin_index < tal_count(route_nodes)); |
| 462 | |
| 463 | /* Either we have both channels and nodes, or neither */ |
| 464 | assert((route_nodes == NULL) == (route_channels == NULL)); |
| 465 | |
| 466 | if (route_nodes == NULL) { |
| 467 | /* This means we have the `shared_secrets`, but cannot infer |
| 468 | * the erring channel and node since we don't have them. This |
| 469 | * can happen if the payment was initialized using `sendonion` |
| 470 | * and the `shared_secrets` where specified. */ |
| 471 | dir = 0; |
| 472 | erring_channel = NULL; |
| 473 | erring_node = NULL; |
| 474 | |
| 475 | /* We don't know if there's another route, that'd depend on |
| 476 | * where the failure occured and whether it was a node |
| 477 | * failure. Let's assume it wasn't a terminal one, and have |
| 478 | * the sendonion caller deal with the actual decision. */ |
| 479 | *pay_errcode = PAY_TRY_OTHER_ROUTE; |
| 480 | } else if (origin_index == tal_count(route_nodes) - 1) { |
| 481 | /* If any channel is to blame, it's the last one. */ |
| 482 | erring_channel = &route_channels[origin_index]; |
| 483 | /* Single hop? */ |
| 484 | if (origin_index == 0) |
| 485 | dir = node_id_idx(&ld->our_nodeid, |
| 486 | &route_nodes[origin_index]); |
| 487 | else |
| 488 | dir = node_id_idx(&route_nodes[origin_index - 1], |
| 489 | &route_nodes[origin_index]); |
| 490 | |
| 491 | /* BOLT #4: |
| 492 | * |
| 493 | * - if the _final node_ is returning the error: |
| 494 | * - if the PERM bit is set: |
| 495 | * - SHOULD fail the payment. |
| 496 | * - otherwise: |
| 497 | * - if the error code is understood and valid: |
no test coverage detected