chancloser: unregister channel before db modification

This fixes a race during channel closing, where the last channel state
update was still not finished when we set the channel close bit in the
database. This lead to a flake during integration tests, where the last
state update would not finish, and the channel wasn't closes
successfully.

We fix it by first unregistering the channel, making sure it is removed
fully from the link before doing the db modification.
This commit is contained in:
Johan T. Halseth 2020-02-25 12:20:17 -03:00
parent 1467cd4dd3
commit 03a0706593
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

View File

@ -223,6 +223,10 @@ func (c *channelCloser) initChanShutdown() (*lnwire.Shutdown, error) {
"close: %v", c.chanPoint, err)
}
// Before returning the shutdown message, we'll unregister the channel
// to ensure that it isn't seen as usable within the system.
c.cfg.unregisterChannel(c.cid)
// Before continuing, mark the channel as cooperatively closed with a
// nil txn. Even though we haven't negotiated the final txn, this
// guarantees that our listchannels rpc will be externally consistent,
@ -233,12 +237,6 @@ func (c *channelCloser) initChanShutdown() (*lnwire.Shutdown, error) {
return nil, err
}
// Before returning the shutdown message, we'll unregister the channel
// to ensure that it isn't seen as usable within the system.
//
// TODO(roasbeef): fail if err?
c.cfg.unregisterChannel(c.cid)
peerLog.Infof("ChannelPoint(%v): sending shutdown message", c.chanPoint)
return shutdown, nil