Fills in *pay_errcode with PAY_TRY_OTHER_ROUTE or PAY_DESTINATION_PERM_FAIL */
| 412 | |
| 413 | /* Fills in *pay_errcode with PAY_TRY_OTHER_ROUTE or PAY_DESTINATION_PERM_FAIL */ |
| 414 | static struct routing_failure* |
| 415 | remote_routing_failure(const tal_t *ctx, |
| 416 | struct lightningd *ld, |
| 417 | const struct wallet_payment *payment, |
| 418 | const u8 *failuremsg, |
| 419 | int origin_index, |
| 420 | struct log *log, |
| 421 | enum jsonrpc_errcode *pay_errcode) |
| 422 | { |
| 423 | enum onion_wire failcode = fromwire_peektype(failuremsg); |
| 424 | struct routing_failure *routing_failure; |
| 425 | const struct node_id *route_nodes; |
| 426 | const struct node_id *erring_node; |
| 427 | const struct short_channel_id *route_channels; |
| 428 | const struct short_channel_id *erring_channel; |
| 429 | int dir; |
| 430 | |
| 431 | routing_failure = tal(ctx, struct routing_failure); |
| 432 | route_nodes = payment->route_nodes; |
| 433 | route_channels = payment->route_channels; |
| 434 | |
| 435 | assert(route_nodes == NULL || origin_index < tal_count(route_nodes)); |
| 436 | |
| 437 | /* Either we have both channels and nodes, or neither */ |
| 438 | assert((route_nodes == NULL) == (route_channels == NULL)); |
| 439 | |
| 440 | if (route_nodes == NULL) { |
| 441 | /* This means we have the `shared_secrets`, but cannot infer |
| 442 | * the erring channel and node since we don't have them. This |
| 443 | * can happen if the payment was initialized using `sendonion` |
| 444 | * and the `shared_secrets` where specified. */ |
| 445 | dir = 0; |
| 446 | erring_channel = NULL; |
| 447 | erring_node = NULL; |
| 448 | |
| 449 | /* We don't know if there's another route, that'd depend on |
| 450 | * where the failure occured and whether it was a node |
| 451 | * failure. Let's assume it wasn't a terminal one, and have |
| 452 | * the sendonion caller deal with the actual decision. */ |
| 453 | *pay_errcode = PAY_TRY_OTHER_ROUTE; |
| 454 | } else if (origin_index == tal_count(route_nodes) - 1) { |
| 455 | /* If any channel is to blame, it's the last one. */ |
| 456 | erring_channel = &route_channels[origin_index]; |
| 457 | /* Single hop? */ |
| 458 | if (origin_index == 0) |
| 459 | dir = node_id_idx(&ld->id, |
| 460 | &route_nodes[origin_index]); |
| 461 | else |
| 462 | dir = node_id_idx(&route_nodes[origin_index - 1], |
| 463 | &route_nodes[origin_index]); |
| 464 | |
| 465 | /* BOLT #4: |
| 466 | * |
| 467 | * - if the _final node_ is returning the error: |
| 468 | * - if the PERM bit is set: |
| 469 | * - SHOULD fail the payment. |
| 470 | * */ |
| 471 | if (failcode & BADONION) |
no test coverage detected