rpcserver: only block co-op close for frozen chans

This commit fixes a recent issue from #4081 that would prevent a frozen
channel from being force closed via the rpc. We correct this, so that
only the co-op path is inhibited.
This commit is contained in:
Conner Fromknecht 2020-04-02 17:40:08 -07:00
parent 3c371dd633
commit d1fa33c8eb
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

View File

@ -1990,19 +1990,12 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
return err
}
// If this is a frozen channel, then we only allow the close to proceed
// if we were the responder to this channel.
// Retrieve the best height of the chain, which we'll use to complete
// either closing flow.
_, bestHeight, err := r.server.cc.chainIO.GetBestBlock()
if err != nil {
return err
}
if channel.ChanType.IsFrozen() && channel.IsInitiator &&
uint32(bestHeight) < channel.ThawHeight {
return fmt.Errorf("cannot co-op close frozen channel as "+
"initiator until height=%v, (current_height=%v)",
channel.ThawHeight, bestHeight)
}
// If a force closure was requested, then we'll handle all the details
// around the creation and broadcast of the unilateral closure
@ -2057,6 +2050,17 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
}
})
} else {
// If this is a frozen channel, then we only allow the co-op
// close to proceed if we were the responder to this channel.
if channel.ChanType.IsFrozen() && channel.IsInitiator &&
uint32(bestHeight) < channel.ThawHeight {
return fmt.Errorf("cannot co-op close frozen channel "+
"as initiator until height=%v, "+
"(current_height=%v)", channel.ThawHeight,
bestHeight)
}
// If the link is not known by the switch, we cannot gracefully close
// the channel.
channelID := lnwire.NewChanIDFromOutPoint(chanPoint)