| 641 | } |
| 642 | |
| 643 | void channel_errmsg(struct channel *channel, |
| 644 | struct peer_fd *peer_fd, |
| 645 | const char *desc, |
| 646 | const u8 *err_for_them, |
| 647 | bool disconnect, |
| 648 | bool warning) |
| 649 | { |
| 650 | /* Clean up any in-progress open attempts */ |
| 651 | channel_cleanup_commands(channel, desc); |
| 652 | |
| 653 | if (channel_state_uncommitted(channel->state)) { |
| 654 | log_info(channel->log, "%s", "Unsaved peer failed." |
| 655 | " Deleting channel."); |
| 656 | delete_channel(channel, false); |
| 657 | return; |
| 658 | } |
| 659 | |
| 660 | /* No peer_fd means a subd crash or disconnection. */ |
| 661 | if (!peer_fd) { |
| 662 | /* If the channel is unsaved, we forget it */ |
| 663 | channel_fail_transient(channel, disconnect, "%s: %s", |
| 664 | channel->owner->name, desc); |
| 665 | return; |
| 666 | } |
| 667 | |
| 668 | /* Do we have an error to send? */ |
| 669 | if (err_for_them && !channel->error && !warning) |
| 670 | channel->error = tal_dup_talarr(channel, u8, err_for_them); |
| 671 | |
| 672 | /* LND sends "internal error" and we close the channel. But |
| 673 | * prior to 0.11 we would turn this into a warning, and they |
| 674 | * would recover after a reconnect. So we downgrade, but snark |
| 675 | * about it in the logs. */ |
| 676 | if (!err_for_them && strends(desc, "internal error")) { |
| 677 | channel_fail_transient(channel, disconnect, "%s: %s", |
| 678 | channel->owner->name, |
| 679 | "lnd sent 'internal error':" |
| 680 | " let's give it some space"); |
| 681 | return; |
| 682 | } |
| 683 | |
| 684 | /* This is us, sending a warning. */ |
| 685 | if (warning) { |
| 686 | channel_fail_transient(channel, disconnect, "%s sent %s", |
| 687 | channel->owner->name, |
| 688 | desc); |
| 689 | return; |
| 690 | } |
| 691 | |
| 692 | /* BOLT #1: |
| 693 | * |
| 694 | * A sending node: |
| 695 | *... |
| 696 | * - when sending `error`: |
| 697 | * - MUST fail the channel(s) referred to by the error message. |
| 698 | * - MAY set `channel_id` to all zero to indicate all channels. |
| 699 | */ |
| 700 | /* FIXME: Close if it's an all-channels error sent or rcvd */ |
no test coverage detected