diff --git a/htlcswitch/interfaces.go b/htlcswitch/interfaces.go index 51a5146e..a1b36ed7 100644 --- a/htlcswitch/interfaces.go +++ b/htlcswitch/interfaces.go @@ -30,7 +30,7 @@ type InvoiceDatabase interface { // | // | (Switch) (Switch) (Switch) // | Alice <-- channel link --> Bob <-- channel link --> Carol -// | +// | // | - - - - - - - - - - - - - TCP - - - - - - - - - - - - - - - // | // | (Peer) (Peer) (Peer) diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index b794d19b..377222ca 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -1284,8 +1284,8 @@ func (s *Switch) htlcForwarder() { chanID := lnwire.NewChanIDFromOutPoint(req.ChanPoint) link, ok := s.linkIndex[chanID] if !ok { - req.Err <- errors.Errorf("channel with "+ - "chan_id=%x not found", chanID[:]) + req.Err <- errors.Errorf("no peer for channel with "+ + "chan_id=%x", chanID[:]) continue } diff --git a/lnwire/channel_id.go b/lnwire/channel_id.go index 3033f401..1997ba51 100644 --- a/lnwire/channel_id.go +++ b/lnwire/channel_id.go @@ -22,6 +22,8 @@ const ( // within the network. The ChannelID is computed using the outpoint of the // funding transaction (the txid, and output index). Given a funding output the // ChannelID can be calculated by XOR'ing the big-endian serialization of the +// txid and the big-endian serialization of the output index, truncated to +// 2 bytes. type ChannelID [32]byte // ConnectionWideID is an all-zero ChannelID, which is used to represent a diff --git a/rpcserver.go b/rpcserver.go index cec89b6c..f93df730 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1071,6 +1071,16 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest, } }) } else { + // If the link is not known by the switch, we cannot gracefully close + // the channel. + channelID := lnwire.NewChanIDFromOutPoint(chanPoint) + if _, err := r.server.htlcSwitch.GetLink(channelID); err != nil { + rpcsLog.Debugf("Trying to non-force close offline channel with "+ + "chan_point=%v", chanPoint) + return fmt.Errorf("unable to gracefully close channel while peer "+ + "is offline (try force closing it instead): %v", err) + } + // Based on the passed fee related parameters, we'll determine // an appropriate fee rate for the cooperative closure // transaction.