closingd: retransmit shutdown on reconnect.

The spec says so, and it's right: with the right pattern of packet loss
(thanks Travis!) the other end can still be in channeld, waiting for our
`shutdown` message.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-10-29 14:07:11 +10:30
committed by Christian Decker
parent d4f164eb39
commit 1935614979
3 changed files with 22 additions and 5 deletions

View File

@@ -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
1 #include <common/cryptomsg.h>
25 closing_init,,revocations_received,u64
26 closing_init,,channel_reestablish_len,u16
27 closing_init,,channel_reestablish,channel_reestablish_len*u8
28 closing_init,,final_scriptpubkey_len,u16
29 closing_init,,final_scriptpubkey,final_scriptpubkey_len*u8
30 # We received an offer, save signature.
31 closing_received_signature,2002
32 closing_received_signature,,signature,secp256k1_ecdsa_signature

View File

@@ -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")",

View File

@@ -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. */