| 585 | } |
| 586 | |
| 587 | void channel_errmsg(struct channel *channel, |
| 588 | struct peer_fd *peer_fd, |
| 589 | const char *desc, |
| 590 | const u8 *err_for_them, |
| 591 | bool disconnect, |
| 592 | bool warning) |
| 593 | { |
| 594 | /* Clean up any in-progress open attempts */ |
| 595 | channel_cleanup_commands(channel, desc); |
| 596 | |
| 597 | if (channel_state_uncommitted(channel->state)) { |
| 598 | log_info(channel->log, "%s", "Unsaved peer failed." |
| 599 | " Deleting channel."); |
| 600 | delete_channel(channel, false); |
| 601 | return; |
| 602 | } |
| 603 | |
| 604 | /* No peer_fd means a subd crash or disconnection. */ |
| 605 | if (!peer_fd) { |
| 606 | /* If the channel is unsaved, we forget it */ |
| 607 | channel_fail_transient(channel, disconnect, "%s: %s", |
| 608 | channel->owner->name, desc); |
| 609 | return; |
| 610 | } |
| 611 | |
| 612 | /* Do we have an error to send? */ |
| 613 | if (err_for_them && !channel->error && !warning) |
| 614 | channel->error = tal_dup_talarr(channel, u8, err_for_them); |
| 615 | |
| 616 | /* LND sends "internal error" and we close the channel. But |
| 617 | * prior to 0.11 we would turn this into a warning, and they |
| 618 | * would recover after a reconnect. So we downgrade, but snark |
| 619 | * about it in the logs. */ |
| 620 | if (!err_for_them && strends(desc, "internal error")) { |
| 621 | channel_fail_transient(channel, disconnect, "%s: %s", |
| 622 | channel->owner->name, |
| 623 | "lnd sent 'internal error':" |
| 624 | " let's give it some space"); |
| 625 | return; |
| 626 | } |
| 627 | |
| 628 | /* This is us, sending a warning. */ |
| 629 | if (warning) { |
| 630 | channel_fail_transient(channel, disconnect, "%s sent %s", |
| 631 | channel->owner->name, |
| 632 | desc); |
| 633 | return; |
| 634 | } |
| 635 | |
| 636 | /* BOLT #1: |
| 637 | * |
| 638 | * A sending node: |
| 639 | *... |
| 640 | * - when sending `error`: |
| 641 | * - MUST fail the channel(s) referred to by the error message. |
| 642 | * - MAY set `channel_id` to all zero to indicate all channels. |
| 643 | */ |
| 644 | /* FIXME: Close if it's an all-channels error sent or rcvd */ |
no test coverage detected