peer: ensure when closing the channel actually exists

This commit is contained in:
Olaoluwa Osuntokun 2017-05-23 15:21:35 -07:00
parent 408be356fb
commit 588a606a56
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
1 changed files with 22 additions and 4 deletions

26
peer.go
View File

@ -857,8 +857,15 @@ func (p *peer) handleLocalClose(req *closeLinkReq) {
chanID := lnwire.NewChanIDFromOutPoint(req.chanPoint)
p.activeChanMtx.RLock()
channel := p.activeChannels[chanID]
channel, ok := p.activeChannels[chanID]
p.activeChanMtx.RUnlock()
if !ok {
err := fmt.Errorf("unable to close channel, ChannelID(%v) is "+
"unknown", chanID)
peerLog.Errorf(err.Error())
req.err <- err
return
}
switch req.CloseType {
// A type of CloseRegular indicates that the user has opted to close
@ -929,10 +936,16 @@ func (p *peer) handleShutdownResponse(msg *lnwire.Shutdown) []byte {
// closure.
func (p *peer) handleInitClosingSigned(req *closeLinkReq, msg *lnwire.ClosingSigned) {
chanID := lnwire.NewChanIDFromOutPoint(req.chanPoint)
p.activeChanMtx.RLock()
channel := p.activeChannels[chanID]
channel, ok := p.activeChannels[chanID]
p.activeChanMtx.RUnlock()
if !ok {
err := fmt.Errorf("unable to close channel, ChannelID(%v) is "+
"unknown", chanID)
peerLog.Errorf(err.Error())
req.err <- err
return
}
// Calculate a fee rate that we believe to be fair.
// TODO(bvu): with a dynamic fee implementation, we will compare this to
@ -1057,8 +1070,13 @@ func (p *peer) handleInitClosingSigned(req *closeLinkReq, msg *lnwire.ClosingSig
func (p *peer) handleResponseClosingSigned(msg *lnwire.ClosingSigned,
respSig []byte) {
p.activeChanMtx.RLock()
channel := p.activeChannels[msg.ChannelID]
channel, ok := p.activeChannels[msg.ChannelID]
p.activeChanMtx.RUnlock()
if !ok {
peerLog.Errorf("unable to close channel, ChannelID(%v) is "+
"unknown", msg.ChannelID)
return
}
// Now that we have the initiator's signature for the closure
// transaction, we can assemble the final closure transaction, complete