peer: ensure no messages are sent/processed _before_ all channels loaded

This commit fixes a bug which could at times cause channels to be
unusable upon connection. The bug would manifest like the following:
two peers would connect, one loads their channels faster than the
other, this would result in the winning peer attempting to extend their
revocation window. However, if the other peer hadn’t yet loaded the
channel, then this would appear to them to be an unknown channel.

We properly fix this issue by ensure all channels are loaded _before_
any of the goroutines needed for the operation of the peer are
launched.
This commit is contained in:
Olaoluwa Osuntokun 2017-05-10 17:37:59 -07:00
parent a75439f56b
commit e05ec619ca
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

16
peer.go
View File

@ -237,6 +237,8 @@ func (p *peer) Start() error {
}
}
// Once the init message arrives, we can parse it so we can figure out
// the negotiation of features for this session.
msg := <-msgChan
if msg, ok := msg.(*lnwire.Init); ok {
if err := p.handleInitMsg(msg); err != nil {
@ -247,13 +249,6 @@ func (p *peer) Start() error {
"must be init message")
}
p.wg.Add(5)
go p.queueHandler()
go p.writeHandler()
go p.readHandler()
go p.channelManager()
go p.pingHandler()
// Fetch and then load all the active channels we have with this remote
// peer from the database.
activeChans, err := p.server.chanDB.FetchOpenChannels(p.addr.IdentityKey)
@ -272,6 +267,13 @@ func (p *peer) Start() error {
return fmt.Errorf("unable to load channels: %v", err)
}
p.wg.Add(5)
go p.queueHandler()
go p.writeHandler()
go p.readHandler()
go p.channelManager()
go p.pingHandler()
return nil
}