From 9b71d90a6e1800266cf34dcdda993ff4ce78f15c Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Fri, 10 May 2019 10:39:16 +0200 Subject: [PATCH] lncli: add querymc command Adds querymc command to lncli to dump mission control state. --- cmd/lncli/cmd_query_mission_control.go | 59 ++++++++++++++++++++++++++ cmd/lncli/main.go | 1 + cmd/lncli/routerrpc_active.go | 10 +++++ cmd/lncli/routerrpc_default.go | 10 +++++ 4 files changed, 80 insertions(+) create mode 100644 cmd/lncli/cmd_query_mission_control.go create mode 100644 cmd/lncli/routerrpc_active.go create mode 100644 cmd/lncli/routerrpc_default.go diff --git a/cmd/lncli/cmd_query_mission_control.go b/cmd/lncli/cmd_query_mission_control.go new file mode 100644 index 00000000..b8764d37 --- /dev/null +++ b/cmd/lncli/cmd_query_mission_control.go @@ -0,0 +1,59 @@ +// +build routerrpc + +package main + +import ( + "context" + "encoding/hex" + + "github.com/lightningnetwork/lnd/lnrpc/routerrpc" + + "github.com/urfave/cli" +) + +var queryMissionControlCommand = cli.Command{ + Name: "querymc", + Category: "Payments", + Action: actionDecorator(queryMissionControl), +} + +func queryMissionControl(ctx *cli.Context) error { + conn := getClientConn(ctx, false) + defer conn.Close() + + client := routerrpc.NewRouterClient(conn) + + req := &routerrpc.QueryMissionControlRequest{} + rpcCtx := context.Background() + snapshot, err := client.QueryMissionControl(rpcCtx, req) + if err != nil { + return err + } + + type displayNodeHistory struct { + Pubkey string + LastFailTime int64 + OtherChanSuccessProb float32 + Channels []*routerrpc.ChannelHistory + } + + displayResp := struct { + Nodes []displayNodeHistory + }{} + + for _, n := range snapshot.Nodes { + displayResp.Nodes = append( + displayResp.Nodes, + displayNodeHistory{ + Pubkey: hex.EncodeToString(n.Pubkey), + LastFailTime: n.LastFailTime, + OtherChanSuccessProb: n.OtherChanSuccessProb, + Channels: n.Channels, + }, + ) + } + + printJSON(displayResp) + + return nil +} diff --git a/cmd/lncli/main.go b/cmd/lncli/main.go index f04d4568..73a6ce75 100644 --- a/cmd/lncli/main.go +++ b/cmd/lncli/main.go @@ -303,6 +303,7 @@ func main() { // Add any extra autopilot commands determined by build flags. app.Commands = append(app.Commands, autopilotCommands()...) app.Commands = append(app.Commands, invoicesCommands()...) + app.Commands = append(app.Commands, routerCommands()...) if err := app.Run(os.Args); err != nil { fatal(err) diff --git a/cmd/lncli/routerrpc_active.go b/cmd/lncli/routerrpc_active.go new file mode 100644 index 00000000..4a34d6b1 --- /dev/null +++ b/cmd/lncli/routerrpc_active.go @@ -0,0 +1,10 @@ +// +build routerrpc + +package main + +import "github.com/urfave/cli" + +// routerCommands will return nil for non-routerrpc builds. +func routerCommands() []cli.Command { + return []cli.Command{queryMissionControlCommand} +} diff --git a/cmd/lncli/routerrpc_default.go b/cmd/lncli/routerrpc_default.go new file mode 100644 index 00000000..c2a5fe7b --- /dev/null +++ b/cmd/lncli/routerrpc_default.go @@ -0,0 +1,10 @@ +// +build !routerrpc + +package main + +import "github.com/urfave/cli" + +// routerCommands will return nil for non-routerrpc builds. +func routerCommands() []cli.Command { + return nil +}