Merge pull request #5033 from robot-dreams/set-channel-status

Add lncli command / RPC for manually setting channel state
This commit is contained in:
Olaoluwa Osuntokun
2021-03-09 18:12:08 -08:00
committed by GitHub
25 changed files with 1230 additions and 330 deletions

View File

@@ -10,6 +10,7 @@ import (
"sync/atomic"
"time"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/lightningnetwork/lnd/channeldb"
@@ -116,6 +117,10 @@ var (
Entity: "offchain",
Action: "write",
}},
"/routerrpc.Router/UpdateChanStatus": {{
Entity: "offchain",
Action: "write",
}},
}
// DefaultRouterMacFilename is the default name of the router macaroon
@@ -698,3 +703,44 @@ func (s *Server) HtlcInterceptor(stream Router_HtlcInterceptorServer) error {
// run the forward interceptor.
return newForwardInterceptor(s, stream).run()
}
func extractOutPoint(req *UpdateChanStatusRequest) (*wire.OutPoint, error) {
chanPoint := req.GetChanPoint()
txid, err := lnrpc.GetChanPointFundingTxid(chanPoint)
if err != nil {
return nil, err
}
index := chanPoint.OutputIndex
return wire.NewOutPoint(txid, index), nil
}
// UpdateChanStatus allows channel state to be set manually.
func (s *Server) UpdateChanStatus(ctx context.Context,
req *UpdateChanStatusRequest) (*UpdateChanStatusResponse, error) {
outPoint, err := extractOutPoint(req)
if err != nil {
return nil, err
}
action := req.GetAction()
log.Debugf("UpdateChanStatus called for channel(%v) with "+
"action %v", outPoint, action)
switch action {
case ChanStatusAction_ENABLE:
err = s.cfg.RouterBackend.SetChannelEnabled(*outPoint)
case ChanStatusAction_DISABLE:
err = s.cfg.RouterBackend.SetChannelDisabled(*outPoint)
case ChanStatusAction_AUTO:
err = s.cfg.RouterBackend.SetChannelAuto(*outPoint)
default:
err = fmt.Errorf("unrecognized ChannelStatusAction %v", action)
}
if err != nil {
return nil, err
}
return &UpdateChanStatusResponse{}, nil
}