From e7116284f05b65f3b2496fd3254616e6f5e289f2 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 17 Aug 2018 14:36:36 +0930 Subject: [PATCH] channeld: move reestablish retransmission below checks. This makes it a bit clearer, but also means we do all checks before sending any packets. Signed-off-by: Rusty Russell --- channeld/channel.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/channeld/channel.c b/channeld/channel.c index 75452bd99..7e635db51 100644 --- a/channeld/channel.c +++ b/channeld/channel.c @@ -1836,7 +1836,7 @@ static void peer_reconnect(struct peer *peer, struct channel_id channel_id; /* Note: BOLT #2 uses these names, which are sender-relative! */ u64 next_local_commitment_number, next_remote_revocation_number; - bool retransmit_revoke_and_ack; + bool retransmit_revoke_and_ack, retransmit_commitment_signed; struct htlc_map_iter it; const struct htlc *htlc; u8 *msg; @@ -1960,11 +1960,6 @@ static void peer_reconnect(struct peer *peer, } else retransmit_revoke_and_ack = false; - /* We have to re-send in the same order we sent originally: - * revoke_and_ack (usually) alters our next commitment. */ - if (retransmit_revoke_and_ack && !peer->last_was_revoke) - resend_revoke(peer); - /* BOLT #2: * * - if `next_local_commitment_number` is equal to the commitment @@ -1982,7 +1977,7 @@ static void peer_reconnect(struct peer *peer, PRIu64, next_local_commitment_number); - resend_commitment(peer, peer->last_sent_commit); + retransmit_commitment_signed = true; /* BOLT #2: * @@ -1999,6 +1994,16 @@ static void peer_reconnect(struct peer *peer, " vs %"PRIu64, next_local_commitment_number, peer->next_index[REMOTE]); + else + retransmit_commitment_signed = false; + + /* We have to re-send in the same order we sent originally: + * revoke_and_ack (usually) alters our next commitment. */ + if (retransmit_revoke_and_ack && !peer->last_was_revoke) + resend_revoke(peer); + + if (retransmit_commitment_signed) + resend_commitment(peer, peer->last_sent_commit); /* This covers the case where we sent revoke after commit. */ if (retransmit_revoke_and_ack && peer->last_was_revoke)