From 7e8c840f29afb247cb70d7bb9b8e52b84521f905 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 4 May 2017 16:04:41 -0700 Subject: [PATCH] rpc: when force closing ensure switch+peer indexes are wiped --- rpcserver.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 0453c1607..f8e26ae15 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -452,12 +452,24 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest, // As the first part of the force closure, we first fetch the // channel from the database, then execute a direct force // closure broadcasting our current commitment transaction. - // TODO(roasbeef): d/c peer if connected? - // * otherwise safety no guaranteed channel, err := r.fetchActiveChannel(*chanPoint) if err != nil { return err } + + // As we're force closing this channel, as a precaution, we'll + // ensure that the switch doesn't continue to see this channel + // as eligible for forwarding HTLC's. If the peer is online, + // then we'll also purge all of its indexes. + remotePub := &channel.StateSnapshot().RemoteIdentity + if peer, err := r.server.findPeer(remotePub); err == nil { + wipeChannel(peer, channel) + } else { + chanID := lnwire.NewChanIDFromOutPoint(channel.ChannelPoint()) + r.server.htlcSwitch.UnregisterLink(remotePub, &chanID) + } + + r.server.breachArbiter.settledContracts <- chanPoint closingTxid, err := r.forceCloseChan(channel) if err != nil { rpcsLog.Errorf("unable to force close transaction: %v", err)