From 172b30c557ce14157d1491652c3cb328286dd2a7 Mon Sep 17 00:00:00 2001 From: rkfg Date: Sat, 27 Nov 2021 16:30:21 +0300 Subject: [PATCH] Add forced aliases --- README.md | 6 ++++++ config/config.go | 23 +++++++++++++---------- network/backend/lnd/lnd.go | 7 +++++-- network/models/channel.go | 15 +++++++++++++++ network/models/node.go | 1 + ui/views/channel.go | 6 +++++- ui/views/channels.go | 13 +++++-------- ui/views/routing.go | 13 ++++++------- 8 files changed, 56 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index bfa2a41..25eff44 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,12 @@ max_msg_recv_size = 52428800 conn_timeout = 1000000 pool_capacity = 4 +[network.aliases] +# Not all peers have aliases set up. In order to remember who is whom, pubkeys can be annotated. +# "Forced" aliases will be printed in a different color to be distinguished from network advertised aliases. +035e4ff418fc8b5554c5d9eea66396c227bd429a3251c8cbc711002ba215bfc226 = "Wallet of Satoshi" +03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370e2c366597a3f8f = "-=[ACINQ]=-" + [views] # views.channels is the view displaying channel list. [views.channels] diff --git a/config/config.go b/config/config.go index a918d05..f87deec 100644 --- a/config/config.go +++ b/config/config.go @@ -23,16 +23,17 @@ type Logger struct { } type Network struct { - Name string `toml:"name"` - Type string `toml:"type"` - Address string `toml:"address"` - Cert string `toml:"cert"` - Macaroon string `toml:"macaroon"` - MacaroonTimeOut int64 `toml:"macaroon_timeout"` - MacaroonIP string `toml:"macaroon_ip"` - MaxMsgRecvSize int `toml:"max_msg_recv_size"` - ConnTimeout int `toml:"conn_timeout"` - PoolCapacity int `toml:"pool_capacity"` + Name string `toml:"name"` + Type string `toml:"type"` + Address string `toml:"address"` + Cert string `toml:"cert"` + Macaroon string `toml:"macaroon"` + MacaroonTimeOut int64 `toml:"macaroon_timeout"` + MacaroonIP string `toml:"macaroon_ip"` + MaxMsgRecvSize int `toml:"max_msg_recv_size"` + ConnTimeout int `toml:"conn_timeout"` + PoolCapacity int `toml:"pool_capacity"` + Aliases Aliases `toml:"aliases"` } type Views struct { @@ -45,6 +46,8 @@ type View struct { Columns []string `toml:"columns"` } +type Aliases map[string]string + func Load(path string) (*Config, error) { c := &Config{} diff --git a/network/backend/lnd/lnd.go b/network/backend/lnd/lnd.go index f78c8c8..11536c7 100644 --- a/network/backend/lnd/lnd.go +++ b/network/backend/lnd/lnd.go @@ -379,8 +379,11 @@ func (l Backend) GetNode(ctx context.Context, pubkey string) (*models.Node, erro if err != nil { return nil, errors.WithStack(err) } - - return nodeProtoToNode(resp), nil + result := nodeProtoToNode(resp) + if forcedAlias, ok := l.cfg.Aliases[result.PubKey]; ok { + result.ForcedAlias = forcedAlias + } + return result, nil } func (l Backend) CreateInvoice(ctx context.Context, amount int64, desc string) (*models.Invoice, error) { diff --git a/network/models/channel.go b/network/models/channel.go index ff7aaed..db1ad2a 100644 --- a/network/models/channel.go +++ b/network/models/channel.go @@ -72,6 +72,21 @@ func (m Channel) MarshalLogObject(enc logging.ObjectEncoder) error { return nil } +func (m Channel) ShortAlias() (alias string, forced bool) { + if m.Node != nil && m.Node.ForcedAlias != "" { + alias = m.Node.ForcedAlias + forced = true + } else if m.Node == nil || m.Node.Alias == "" { + alias = m.RemotePubKey[:24] + } else { + alias = m.Node.Alias + } + if len(alias) > 25 { + alias = alias[:24] + } + return +} + type ChannelUpdate struct { } diff --git a/network/models/node.go b/network/models/node.go index c67199d..6ac0741 100644 --- a/network/models/node.go +++ b/network/models/node.go @@ -8,6 +8,7 @@ type Node struct { LastUpdate time.Time PubKey string Alias string + ForcedAlias string Addresses []*NodeAddress } diff --git a/ui/views/channel.go b/ui/views/channel.go index 0bd1965..fc87e23 100644 --- a/ui/views/channel.go +++ b/ui/views/channel.go @@ -167,8 +167,12 @@ func (c *Channel) display() { cyan(" PubKey:"), channel.RemotePubKey) if channel.Node != nil { + alias, forced := channel.ShortAlias() + if forced { + alias = cyan(alias) + } fmt.Fprintf(v, "%s %s\n", - cyan(" Alias:"), channel.Node.Alias) + cyan(" Alias:"), alias) fmt.Fprintf(v, "%s %d\n", cyan(" Total Capacity:"), channel.Node.TotalCapacity) fmt.Fprintf(v, "%s %d\n", diff --git a/ui/views/channels.go b/ui/views/channels.go index 32534de..93dc7bf 100644 --- a/ui/views/channels.go +++ b/ui/views/channels.go @@ -316,15 +316,12 @@ func NewChannels(cfg *config.View, chans *models.Channels) *Channels { } }, display: func(c *netmodels.Channel, opts ...color.Option) string { - var alias string - if c.Node == nil || c.Node.Alias == "" { - alias = c.RemotePubKey[:24] - } else if len(c.Node.Alias) > 25 { - alias = c.Node.Alias[:24] - } else { - alias = c.Node.Alias + aliasColor := color.White(opts...) + alias, forced := c.ShortAlias() + if forced { + aliasColor = color.Cyan(opts...) } - return color.White(opts...)(fmt.Sprintf("%-25s", alias)) + return aliasColor(fmt.Sprintf("%-25s", alias)) }, } case "GAUGE": diff --git a/ui/views/routing.go b/ui/views/routing.go index 518674f..357200f 100644 --- a/ui/views/routing.go +++ b/ui/views/routing.go @@ -477,18 +477,17 @@ func ralias(channels *models.Channels, out bool) func(*netmodels.RoutingEvent, . } var alias string + var forced bool + aliasColor := color.White(opts...) for _, ch := range channels.List() { if ch.ID == id { - if ch.Node == nil || ch.Node.Alias == "" { - alias = ch.RemotePubKey[:24] - } else if len(ch.Node.Alias) > 25 { - alias = ch.Node.Alias[:24] - } else { - alias = ch.Node.Alias + alias, forced = ch.ShortAlias() + if forced { + aliasColor = color.Cyan(opts...) } break } } - return color.White(opts...)(fmt.Sprintf("%-25s", alias)) + return aliasColor(fmt.Sprintf("%-25s", alias)) } }