| 616 | } |
| 617 | |
| 618 | void channel_errmsg(struct channel *channel, |
| 619 | struct peer_fd *peer_fd, |
| 620 | const char *desc, |
| 621 | const u8 *err_for_them, |
| 622 | bool disconnect, |
| 623 | bool warning) |
| 624 | { |
| 625 | /* Clean up any in-progress open attempts */ |
| 626 | channel_cleanup_commands(channel, desc); |
| 627 | |
| 628 | if (channel_state_uncommitted(channel->state)) { |
| 629 | log_info(channel->log, "%s", "Unsaved peer failed." |
| 630 | " Deleting channel."); |
| 631 | delete_channel(channel, false); |
| 632 | return; |
| 633 | } |
| 634 | |
| 635 | /* No peer_fd means a subd crash or disconnection. */ |
| 636 | if (!peer_fd) { |
| 637 | /* If the channel is unsaved, we forget it */ |
| 638 | channel_fail_transient(channel, disconnect, "%s: %s", |
| 639 | channel->owner->name, desc); |
| 640 | return; |
| 641 | } |
| 642 | |
| 643 | /* Do we have an error to send? */ |
| 644 | if (err_for_them && !channel->error && !warning) |
| 645 | channel->error = tal_dup_talarr(channel, u8, err_for_them); |
| 646 | |
| 647 | /* LND sends "internal error" and we close the channel. But |
| 648 | * prior to 0.11 we would turn this into a warning, and they |
| 649 | * would recover after a reconnect. So we downgrade, but snark |
| 650 | * about it in the logs. */ |
| 651 | if (!err_for_them && strends(desc, "internal error")) { |
| 652 | channel_fail_transient(channel, disconnect, "%s: %s", |
| 653 | channel->owner->name, |
| 654 | "lnd sent 'internal error':" |
| 655 | " let's give it some space"); |
| 656 | return; |
| 657 | } |
| 658 | |
| 659 | /* This is us, sending a warning. */ |
| 660 | if (warning) { |
| 661 | channel_fail_transient(channel, disconnect, "%s sent %s", |
| 662 | channel->owner->name, |
| 663 | desc); |
| 664 | return; |
| 665 | } |
| 666 | |
| 667 | /* BOLT #1: |
| 668 | * |
| 669 | * A sending node: |
| 670 | *... |
| 671 | * - when sending `error`: |
| 672 | * - MUST fail the channel(s) referred to by the error message. |
| 673 | * - MAY set `channel_id` to all zero to indicate all channels. |
| 674 | */ |
| 675 | /* FIXME: Close if it's an all-channels error sent or rcvd */ |
no test coverage detected