lnd: properly execute force closures kicked off via RPC

This commit includes some slight refactoring to properly execute force
closures which are initiated by RPC clients.

The CloseLink method within the htlcSwitch has been extended to take an
additional parameter which indicates if the link should be closed
forcefully. If so, then the channelManager which dispatches the request
executes a force closure using the target channel state machine. Once
the closing transaction has been broadcast, the summary is sent to the
utxoNursery so the outputs can be swept once they’re mature.
This commit is contained in:
Olaoluwa Osuntokun committed 2016-09-12 19:07:43 -07:00
1 parent bfa2a1d698
commit 80b09f7d6f
3 files changed
+122 -36

No files matched your search

+8 -7
View File
@@ -246,6 +246,7 @@ out:
func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
updateStream lnrpc.Lightning_CloseChannelServer) error {
force := in.Force
index := in.ChannelPoint.OutputIndex
txid, err := wire.NewShaHash(in.ChannelPoint.FundingTxid)
if err != nil {
@@ -257,7 +258,7 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
rpcsLog.Tracef("[closechannel] request for ChannelPoint(%v)",
targetChannelPoint)
updateChan, errChan := r.server.htlcSwitch.CloseLink(targetChannelPoint)
updateChan, errChan := r.server.htlcSwitch.CloseLink(targetChannelPoint, force)
out:
for {
@@ -279,7 +280,7 @@ out:
switch closeUpdate := closingUpdate.Update.(type) {
case *lnrpc.CloseStatusUpdate_ChanClose:
h, _ := wire.NewShaHash(closeUpdate.ChanClose.ClosingTxid)
rpcsLog.Errorf("[closechannel] close completed: "+
rpcsLog.Infof("[closechannel] close completed: "+
"txid(%v)", h)
break out
}
@@ -492,11 +493,11 @@ func (r *rpcServer) ShowRoutingTable(ctx context.Context,
for _, channel := range rtCopy.AllChannels() {
channels = append(channels,
&lnrpc.RoutingTableLink{
Id1: channel.Id1.String(),
Id2: channel.Id2.String(),
Outpoint: channel.EdgeID.String(),
Capacity: channel.Info.Capacity(),
Weight: channel.Info.Weight(),
Id1: channel.Id1.String(),
Id2: channel.Id2.String(),
Outpoint: channel.EdgeID.String(),
Capacity: channel.Info.Capacity(),
Weight: channel.Info.Weight(),
},
)
}