From 057bed2b920776a81323ac249450f42ef7477c6b Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 10 Apr 2019 18:19:36 -0700 Subject: [PATCH] htlcswitch/link: delay restored channel reestablish This commit adds a brief delay when sending our channel reestablish message if the link contains a restored channel to ensure we first have a stable connection. Sending the message will cause the remote peer to force close the channel, which currently may not be resumed reliably if the connection is being torn town simultaneously. This delay can be removed after the force close is reliable, but in the meantime it improves the reliability of successfully closing out the channel and allows the `channel_backup_restore/restore_during_creation` to pass reliably. --- htlcswitch/link.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 8cde80ef..488ea74d 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -574,6 +574,22 @@ func (l *channelLink) syncChanStates() error { return fmt.Errorf("unable to generate chan sync message for "+ "ChannelPoint(%v)", l.channel.ChannelPoint()) } + + // If we have a restored channel, we'll delay sending our channel + // reestablish message briefly to ensure we first have a stable + // connection. Sending the message will cause the remote peer to force + // close the channel, which currently may not be resumed reliably if the + // connection is being torn down simultaneously. This delay can be + // removed after the force close is reliable, but in the meantime it + // improves the reliability of successfully closing out the channel. + if chanState.HasChanStatus(channeldb.ChanStatusRestored) { + select { + case <-time.After(5 * time.Second): + case <-l.quit: + return ErrLinkShuttingDown + } + } + if err := l.cfg.Peer.SendMessage(true, localChanSyncMsg); err != nil { return fmt.Errorf("Unable to send chan sync message for "+ "ChannelPoint(%v)", l.channel.ChannelPoint())