| 1104 | } |
| 1105 | |
| 1106 | static void channel_fail_perm(struct channel *channel, |
| 1107 | enum state_change reason, |
| 1108 | const char *why, |
| 1109 | const struct bitcoin_tx *spent_by) |
| 1110 | { |
| 1111 | struct lightningd *ld = channel->peer->ld; |
| 1112 | |
| 1113 | /* Don't do anything if it's an stub channel because |
| 1114 | * peer has already closed it unilatelrally. */ |
| 1115 | if (channel->scid && is_stub_scid(*channel->scid)) |
| 1116 | return; |
| 1117 | |
| 1118 | log_unusual(channel->log, |
| 1119 | "Peer permanent failure in %s: %s (reason=%s)", |
| 1120 | channel_state_name(channel), why, |
| 1121 | channel_change_state_reason_str(reason)); |
| 1122 | |
| 1123 | /* We can have multiple errors, eg. onchaind failures. */ |
| 1124 | if (!channel->error) |
| 1125 | channel->error = towire_errorfmt(channel, |
| 1126 | &channel->cid, "%s", why); |
| 1127 | |
| 1128 | channel_set_owner(channel, NULL); |
| 1129 | |
| 1130 | if (channel_state_wants_onchain_fail(channel->state) && !channel->withheld) { |
| 1131 | channel_set_state(channel, |
| 1132 | channel->state, |
| 1133 | AWAITING_UNILATERAL, |
| 1134 | reason, |
| 1135 | why); |
| 1136 | } |
| 1137 | |
| 1138 | /* BOLT #5: |
| 1139 | * A node: |
| 1140 | * - if a *local commitment transaction* has NOT ever contained a `to_local` |
| 1141 | * or HTLC output: |
| 1142 | * - MAY simply forget the channel. |
| 1143 | */ |
| 1144 | /* FIXME: We only implement a subset of this; we keep waiting |
| 1145 | * as long as it was finished opening. */ |
| 1146 | if (channel_state_open_uncommitted(channel->state)) { |
| 1147 | /* If we already sent tx_signatures we must not forget the |
| 1148 | * channel until an input of the negotiated tx is spent (the |
| 1149 | * BOLT #2 tx_abort receiver rule). */ |
| 1150 | if (channel_funding_sigs_sent(channel)) { |
| 1151 | log_unusual(channel->log, |
| 1152 | "Already sent tx_signatures, remembering" |
| 1153 | " channel after permanent failure"); |
| 1154 | return; |
| 1155 | } |
| 1156 | delete_channel(channel, false); |
| 1157 | return; |
| 1158 | } |
| 1159 | |
| 1160 | /* Drop non-cooperatively (unilateral) to chain. If we detect |
| 1161 | * the close from the blockchain, then we can observe |
| 1162 | * passively, and not broadcast our own unilateral close, as |
| 1163 | * it doesn't stand a chance anyway. */ |
no test coverage detected