| 1280 | } |
| 1281 | |
| 1282 | static void peer_got_shutdown(struct channel *channel, const u8 *msg) |
| 1283 | { |
| 1284 | u8 *scriptpubkey; |
| 1285 | struct lightningd *ld = channel->peer->ld; |
| 1286 | struct bitcoin_outpoint *wrong_funding; |
| 1287 | bool anysegwit = !chainparams->is_elements && feature_negotiated(ld->our_features, |
| 1288 | channel->peer->their_features, |
| 1289 | OPT_SHUTDOWN_ANYSEGWIT); |
| 1290 | bool anchors = feature_negotiated(ld->our_features, |
| 1291 | channel->peer->their_features, |
| 1292 | OPT_ANCHOR_OUTPUTS_DEPRECATED) |
| 1293 | || feature_negotiated(ld->our_features, |
| 1294 | channel->peer->their_features, |
| 1295 | OPT_ANCHORS_ZERO_FEE_HTLC_TX); |
| 1296 | |
| 1297 | if (!fromwire_channeld_got_shutdown(channel, msg, &scriptpubkey, |
| 1298 | &wrong_funding)) { |
| 1299 | channel_internal_error(channel, "bad channel_got_shutdown %s", |
| 1300 | tal_hex(msg, msg)); |
| 1301 | return; |
| 1302 | } |
| 1303 | |
| 1304 | /* BOLT #2: |
| 1305 | * A receiving node: |
| 1306 | *... |
| 1307 | * - if the `scriptpubkey` is not in one of the above forms: |
| 1308 | * - SHOULD send a `warning`. |
| 1309 | */ |
| 1310 | if (!valid_shutdown_scriptpubkey(scriptpubkey, anysegwit, !anchors, false)) { |
| 1311 | u8 *warning = towire_warningfmt(NULL, |
| 1312 | &channel->cid, |
| 1313 | "Bad shutdown scriptpubkey %s", |
| 1314 | tal_hex(tmpctx, scriptpubkey)); |
| 1315 | |
| 1316 | /* Get connectd to send warning, and then allow reconnect. */ |
| 1317 | subd_send_msg(ld->connectd, |
| 1318 | take(towire_connectd_peer_send_msg(NULL, |
| 1319 | &channel->peer->id, |
| 1320 | channel->peer->connectd_counter, |
| 1321 | warning))); |
| 1322 | subd_send_msg(ld->connectd, |
| 1323 | take(towire_connectd_disconnect_peer(NULL, |
| 1324 | &channel->peer->id, |
| 1325 | channel->peer->connectd_counter))); |
| 1326 | channel_fail_transient(channel, true, "Bad shutdown scriptpubkey %s", |
| 1327 | tal_hex(tmpctx, scriptpubkey)); |
| 1328 | return; |
| 1329 | } |
| 1330 | |
| 1331 | /* FIXME: Add to spec that we must allow repeated shutdown! */ |
| 1332 | tal_free(channel->shutdown_scriptpubkey[REMOTE]); |
| 1333 | channel->shutdown_scriptpubkey[REMOTE] = scriptpubkey; |
| 1334 | |
| 1335 | /* If we weren't already shutting down, we are now */ |
| 1336 | if (channel->state != CHANNELD_SHUTTING_DOWN) |
| 1337 | channel_set_state(channel, |
| 1338 | channel->state, |
| 1339 | CHANNELD_SHUTTING_DOWN, |
no test coverage detected