rpcserver: don't allow closing restored channels

To avoid the scenario where the user tries to force close a channel too
early that was restored through SCB, we check the channel status in the
RPC server already. If a restored channel cannot connect to its peer and
mark it as local data loss the channel arbitrator would try to publish
the commitment TX it does not have and crash.
This commit is contained in:
Oliver Gugger 2020-08-12 16:03:35 +02:00
parent 37a29b4869
commit fe834bc0c0
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

View File

@ -2072,6 +2072,19 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
return err
}
// We can't coop or force close restored channels or channels that have
// experienced local data loss. Normally we would detect this in the
// channel arbitrator if the channel has the status
// ChanStatusLocalDataLoss after connecting to its peer. But if no
// connection can be established, the channel arbitrator doesn't know it
// can't be force closed yet.
if channel.HasChanStatus(channeldb.ChanStatusRestored) ||
channel.HasChanStatus(channeldb.ChanStatusLocalDataLoss) {
return fmt.Errorf("cannot close channel with state: %v",
channel.ChanStatus())
}
// Retrieve the best height of the chain, which we'll use to complete
// either closing flow.
_, bestHeight, err := r.server.cc.chainIO.GetBestBlock()