diff --git a/closingd/closing_wire.csv b/closingd/closing_wire.csv index 1dc45cb24..9f1e1861e 100644 --- a/closingd/closing_wire.csv +++ b/closingd/closing_wire.csv @@ -25,6 +25,8 @@ closing_init,,next_index_remote,u64 closing_init,,revocations_received,u64 closing_init,,channel_reestablish_len,u16 closing_init,,channel_reestablish,channel_reestablish_len*u8 +closing_init,,final_scriptpubkey_len,u16 +closing_init,,final_scriptpubkey,final_scriptpubkey_len*u8 # We received an offer, save signature. closing_received_signature,2002 diff --git a/closingd/closingd.c b/closingd/closingd.c index eb19badae..0dd9cac7b 100644 --- a/closingd/closingd.c +++ b/closingd/closingd.c @@ -103,7 +103,8 @@ static void do_reconnect(struct crypto_state *cs, const struct channel_id *channel_id, const u64 next_index[NUM_SIDES], u64 revocations_received, - const u8 *channel_reestablish) + const u8 *channel_reestablish, + const u8 *final_scriptpubkey) { u8 *msg; struct channel_id their_channel_id; @@ -147,6 +148,17 @@ static void do_reconnect(struct crypto_state *cs, next_local_commitment_number, next_remote_revocation_number); + /* BOLT #2: + * + * A node: + *... + * - upon reconnection: + * - if it has sent a previous `shutdown`: + * - MUST retransmit `shutdown`. + */ + msg = towire_shutdown(NULL, channel_id, final_scriptpubkey); + sync_crypto_write(cs, PEER_FD, take(msg)); + /* FIXME: Spec says to re-xmit funding_locked here if we haven't * done any updates. */ } @@ -429,7 +441,7 @@ int main(int argc, char *argv[]) u64 min_fee_to_accept, commitment_fee, offer[NUM_SIDES]; struct feerange feerange; enum side funder; - u8 *scriptpubkey[NUM_SIDES], *funding_wscript; + u8 *scriptpubkey[NUM_SIDES], *funding_wscript, *final_scriptpubkey; struct channel_id channel_id; bool reconnected; u64 next_index[NUM_SIDES], revocations_received; @@ -459,7 +471,8 @@ int main(int argc, char *argv[]) &next_index[LOCAL], &next_index[REMOTE], &revocations_received, - &channel_reestablish)) + &channel_reestablish, + &final_scriptpubkey)) master_badmsg(WIRE_CLOSING_INIT, msg); status_trace("satoshi_out = %"PRIu64"/%"PRIu64, @@ -475,7 +488,7 @@ int main(int argc, char *argv[]) if (reconnected) do_reconnect(&cs, &channel_id, next_index, revocations_received, - channel_reestablish); + channel_reestablish, final_scriptpubkey); peer_billboard(true, "Negotiating closing fee between %"PRIu64 " and %"PRIu64" satoshi (ideal %"PRIu64")", diff --git a/lightningd/closing_control.c b/lightningd/closing_control.c index b12448f2b..11a037dec 100644 --- a/lightningd/closing_control.c +++ b/lightningd/closing_control.c @@ -236,7 +236,9 @@ void peer_start_closingd(struct channel *channel, channel->next_index[LOCAL], channel->next_index[REMOTE], num_revocations, - channel_reestablish); + channel_reestablish, + p2wpkh_for_keyidx(tmpctx, ld, + channel->final_key_idx)); /* We don't expect a response: it will give us feedback on * signatures sent and received, then closing_complete. */