MCPcopy Create free account
hub / github.com/ElementsProject/lightning / peer_got_shutdown

Function peer_got_shutdown

lightningd/channel_control.c:290–357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

288}
289
290static void peer_got_shutdown(struct channel *channel, const u8 *msg)
291{
292 u8 *scriptpubkey;
293 struct lightningd *ld = channel->peer->ld;
294 struct bitcoin_outpoint *wrong_funding;
295 bool anysegwit = feature_negotiated(ld->our_features,
296 channel->peer->their_features,
297 OPT_SHUTDOWN_ANYSEGWIT);
298 bool anchors = feature_negotiated(ld->our_features,
299 channel->peer->their_features,
300 OPT_ANCHOR_OUTPUTS)
301 || feature_negotiated(ld->our_features,
302 channel->peer->their_features,
303 OPT_ANCHORS_ZERO_FEE_HTLC_TX);
304
305 if (!fromwire_channeld_got_shutdown(channel, msg, &scriptpubkey,
306 &wrong_funding)) {
307 channel_internal_error(channel, "bad channel_got_shutdown %s",
308 tal_hex(msg, msg));
309 return;
310 }
311
312 /* BOLT #2:
313 * A receiving node:
314 *...
315 * - if the `scriptpubkey` is not in one of the above forms:
316 * - SHOULD send a `warning`.
317 */
318 if (!valid_shutdown_scriptpubkey(scriptpubkey, anysegwit, anchors)) {
319 u8 *warning = towire_warningfmt(NULL,
320 &channel->cid,
321 "Bad shutdown scriptpubkey %s",
322 tal_hex(tmpctx, scriptpubkey));
323
324 /* Get connectd to send warning, and then allow reconnect. */
325 subd_send_msg(ld->connectd,
326 take(towire_connectd_peer_final_msg(NULL,
327 &channel->peer->id,
328 channel->peer->connectd_counter,
329 warning)));
330 channel_fail_transient(channel, "Bad shutdown scriptpubkey %s",
331 tal_hex(tmpctx, scriptpubkey));
332 return;
333 }
334
335 /* FIXME: Add to spec that we must allow repeated shutdown! */
336 tal_free(channel->shutdown_scriptpubkey[REMOTE]);
337 channel->shutdown_scriptpubkey[REMOTE] = scriptpubkey;
338
339 /* If we weren't already shutting down, we are now */
340 if (channel->state != CHANNELD_SHUTTING_DOWN)
341 channel_set_state(channel,
342 channel->state,
343 CHANNELD_SHUTTING_DOWN,
344 REASON_REMOTE,
345 "Peer closes channel");
346
347 /* If we set it, that's what we want. Otherwise use their preference.

Callers 1

channel_msgFunction · 0.85

Calls 12

tal_hexFunction · 0.85
tal_freeFunction · 0.85
channel_set_stateFunction · 0.85
channel_internal_errorFunction · 0.70
subd_send_msgFunction · 0.70
channel_fail_transientFunction · 0.70
feature_negotiatedFunction · 0.50
towire_warningfmtFunction · 0.50
wallet_channel_saveFunction · 0.50

Tested by

no test coverage detected