cmd/lncli: avoid unnecessarily re-encoding graph vertexes in routing table
This commit is contained in:
parent
071a6a54de
commit
9bd5105ae5
@ -811,10 +811,7 @@ func showRoutingTableAsImage(ctx *cli.Context) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
selfLightningId, err := hex.DecodeString(respGetInfo.LightningId)
|
selfLightningId := respGetInfo.IdentityPubkey
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
imgType := ctx.String("type")
|
imgType := ctx.String("type")
|
||||||
imgDest := ctx.String("dest")
|
imgDest := ctx.String("dest")
|
||||||
@ -847,15 +844,15 @@ func showRoutingTableAsImage(ctx *cli.Context) error {
|
|||||||
fmt.Printf("Format: '%v' not recognized. Use one of: %v\n", imgType, visualizer.SupportedFormats())
|
fmt.Printf("Format: '%v' not recognized. Use one of: %v\n", imgType, visualizer.SupportedFormats())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate description graph by dot language
|
// generate description graph by dot language
|
||||||
err = writeToTempFile(r, tempFile, selfLightningId)
|
if err := writeToTempFile(r, tempFile, selfLightningId); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = writeToImageFile(tempFile, imageFile)
|
if err := writeToImageFile(tempFile, imageFile); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Bool("open") {
|
if ctx.Bool("open") {
|
||||||
if err := visualizer.Open(imageFile); err != nil {
|
if err := visualizer.Open(imageFile); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -864,10 +861,10 @@ func showRoutingTableAsImage(ctx *cli.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeToTempFile(r *rt.RoutingTable, file *os.File, self []byte) error {
|
func writeToTempFile(r *rt.RoutingTable, file *os.File, self string) error {
|
||||||
slc := []graph.ID{graph.NewID(string(self))}
|
slc := []graph.ID{graph.NewID(self)}
|
||||||
viz := visualizer.New(r.G, slc, nil, nil)
|
viz := visualizer.New(r.G, slc, nil, nil)
|
||||||
viz.ApplyToNode = func(s string) string { return hex.EncodeToString([]byte(s)) }
|
viz.ApplyToNode = func(s string) string { return s }
|
||||||
viz.ApplyToEdge = func(info interface{}) string {
|
viz.ApplyToEdge = func(info interface{}) string {
|
||||||
if info, ok := info.(*rt.ChannelInfo); ok {
|
if info, ok := info.(*rt.ChannelInfo); ok {
|
||||||
return fmt.Sprintf(`"%v"`, info.Capacity())
|
return fmt.Sprintf(`"%v"`, info.Capacity())
|
||||||
@ -939,7 +936,7 @@ func printRTAsTable(r *rt.RoutingTable, humanForm bool) {
|
|||||||
// Generate prefix tree for shortcuts
|
// Generate prefix tree for shortcuts
|
||||||
lightningIdTree = prefix_tree.NewPrefixTree()
|
lightningIdTree = prefix_tree.NewPrefixTree()
|
||||||
for _, node := range r.Nodes() {
|
for _, node := range r.Nodes() {
|
||||||
lightningIdTree.Add(hex.EncodeToString([]byte(node.String())))
|
lightningIdTree.Add(node.String())
|
||||||
}
|
}
|
||||||
edgeIdTree = prefix_tree.NewPrefixTree()
|
edgeIdTree = prefix_tree.NewPrefixTree()
|
||||||
for _, channel := range channels {
|
for _, channel := range channels {
|
||||||
@ -948,8 +945,8 @@ func printRTAsTable(r *rt.RoutingTable, humanForm bool) {
|
|||||||
}
|
}
|
||||||
for _, channel := range channels {
|
for _, channel := range channels {
|
||||||
var source, target, edgeId string
|
var source, target, edgeId string
|
||||||
sourceHex := hex.EncodeToString([]byte(channel.Id1.String()))
|
sourceHex := channel.Id1.String()
|
||||||
targetHex := hex.EncodeToString([]byte(channel.Id2.String()))
|
targetHex := channel.Id2.String()
|
||||||
edgeIdRaw := channel.EdgeID.String()
|
edgeIdRaw := channel.EdgeID.String()
|
||||||
if humanForm {
|
if humanForm {
|
||||||
source = getShortcut(lightningIdTree, sourceHex, minLen)
|
source = getShortcut(lightningIdTree, sourceHex, minLen)
|
||||||
@ -993,8 +990,8 @@ func printRTAsJSON(r *rt.RoutingTable) {
|
|||||||
channelsRaw := r.AllChannels()
|
channelsRaw := r.AllChannels()
|
||||||
channels.Channels = make([]ChannelDesc, 0, len(channelsRaw))
|
channels.Channels = make([]ChannelDesc, 0, len(channelsRaw))
|
||||||
for _, channelRaw := range channelsRaw {
|
for _, channelRaw := range channelsRaw {
|
||||||
sourceHex := hex.EncodeToString([]byte(channelRaw.Id1.String()))
|
sourceHex := channelRaw.Id1.String()
|
||||||
targetHex := hex.EncodeToString([]byte(channelRaw.Id2.String()))
|
targetHex := channelRaw.Id2.String()
|
||||||
channels.Channels = append(channels.Channels,
|
channels.Channels = append(channels.Channels,
|
||||||
ChannelDesc{
|
ChannelDesc{
|
||||||
ID1: sourceHex,
|
ID1: sourceHex,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user