lncli: add querymc command

Adds querymc command to lncli to dump mission control state.
This commit is contained in:
Joost Jager 2019-05-10 10:39:16 +02:00
parent f7982f0f4c
commit 9b71d90a6e
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
4 changed files with 80 additions and 0 deletions

@ -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
}

@ -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)

@ -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}
}

@ -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
}