Merge pull request #6149 from bhandras/graph_import_rpc

lnd: add `devrpc` sub server and `devrpc.ImportGraph` to import graph dumps
This commit is contained in:
Oliver Gugger
2022-01-28 10:24:59 +01:00
committed by GitHub
28 changed files with 1403 additions and 70 deletions

View File

@@ -0,0 +1,64 @@
//go:build dev
// +build dev
package main
import (
"bytes"
"fmt"
"io/ioutil"
"github.com/lightninglabs/protobuf-hex-display/jsonpb"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/devrpc"
"github.com/urfave/cli"
)
// devCommands will return the set of commands to enable for devrpc builds.
func devCommands() []cli.Command {
return []cli.Command{
{
Name: "importgraph",
Category: "Development",
Description: "Imports graph from describegraph JSON",
Usage: "Import the network graph.",
ArgsUsage: "graph-json-file",
Action: actionDecorator(importGraph),
},
}
}
func getDevClient(ctx *cli.Context) (devrpc.DevClient, func()) {
conn := getClientConn(ctx, false)
cleanUp := func() {
conn.Close()
}
return devrpc.NewDevClient(conn), cleanUp
}
func importGraph(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getDevClient(ctx)
defer cleanUp()
jsonFile := lncfg.CleanAndExpandPath(ctx.Args().First())
jsonBytes, err := ioutil.ReadFile(jsonFile)
if err != nil {
return fmt.Errorf("error reading JSON from file %v: %v",
jsonFile, err)
}
jsonGraph := &lnrpc.ChannelGraph{}
err = jsonpb.Unmarshal(bytes.NewReader(jsonBytes), jsonGraph)
if err != nil {
return fmt.Errorf("error parsing JSON: %v", err)
}
res, err := client.ImportGraph(ctxc, jsonGraph)
if err != nil {
return err
}
printRespJSON(res)
return nil
}

View File

@@ -0,0 +1,11 @@
//go:build !dev
// +build !dev
package main
import "github.com/urfave/cli"
// devCommands will return nil for non-devrpc builds.
func devCommands() []cli.Command {
return nil
}

View File

@@ -39,7 +39,7 @@ var (
// maxMsgRecvSize is the largest message our client will receive. We
// set this to 200MiB atm.
maxMsgRecvSize = grpc.MaxCallRecvMsgSize(1 * 1024 * 1024 * 200)
maxMsgRecvSize = grpc.MaxCallRecvMsgSize(lnrpc.MaxGrpcMsgSize)
)
func fatal(err error) {
@@ -400,6 +400,7 @@ func main() {
app.Commands = append(app.Commands, walletCommands()...)
app.Commands = append(app.Commands, watchtowerCommands()...)
app.Commands = append(app.Commands, wtclientCommands()...)
app.Commands = append(app.Commands, devCommands()...)
if err := app.Run(os.Args); err != nil {
fatal(err)