#84: Fix fee order, intorduce channel initiator field

pull/86/head
Slyghtning 2 years ago
parent 95c7b3d13e
commit 79558d06a9

@ -70,11 +70,11 @@ columns = [
"ALIAS", # alias of the channel node "ALIAS", # alias of the channel node
"GAUGE", # ascii bar with percent local/capacity "GAUGE", # ascii bar with percent local/capacity
"LOCAL", # the local amount of the channel "LOCAL", # the local amount of the channel
"REMOTE", # the remote amount of the channel
#"BASE_OUT" # the outgoing base fee of the channel #"BASE_OUT" # the outgoing base fee of the channel
#"RATE_OUT" # the outgoing fee rate in ppm of the channel #"RATE_OUT" # the outgoing fee rate in ppm of the channel
# "REMOTE", # the remote amount of the channel #"BASE_IN" # the incoming base fee of the channel
#"BASE_IN" # the incoming base fee of the channel #"RATE_IN" # the incoming fee rate in ppm of the channel
#"RATE_IN" # the incoming fee rate in ppm of the channel
"CAP", # the total capacity of the channel "CAP", # the total capacity of the channel
"SENT", # the total amount sent "SENT", # the total amount sent
"RECEIVED", # the total amount received "RECEIVED", # the total amount received

@ -351,8 +351,6 @@ func (l Backend) GetChannelInfo(ctx context.Context, channel *models.Channel) er
t := time.Unix(int64(uint64(resp.LastUpdate)), 0) t := time.Unix(int64(uint64(resp.LastUpdate)), 0)
channel.LastUpdate = &t channel.LastUpdate = &t
channel.Policy1 = protoToRoutingPolicy(resp.Node1Policy)
channel.Policy2 = protoToRoutingPolicy(resp.Node2Policy)
info, err := clt.GetInfo(ctx, &lnrpc.GetInfoRequest{}) info, err := clt.GetInfo(ctx, &lnrpc.GetInfoRequest{})
if err != nil { if err != nil {
@ -361,6 +359,13 @@ func (l Backend) GetChannelInfo(ctx context.Context, channel *models.Channel) er
if info != nil { if info != nil {
channel.WeFirst = resp.Node1Pub == info.IdentityPubkey channel.WeFirst = resp.Node1Pub == info.IdentityPubkey
} }
if channel.WeFirst {
channel.LocalPolicy = protoToRoutingPolicy(resp.Node1Policy)
channel.RemotePolicy = protoToRoutingPolicy(resp.Node2Policy)
} else {
channel.LocalPolicy = protoToRoutingPolicy(resp.Node2Policy)
channel.RemotePolicy = protoToRoutingPolicy(resp.Node1Policy)
}
return nil return nil
} }

@ -48,8 +48,8 @@ type Channel struct {
LastUpdate *time.Time LastUpdate *time.Time
Node *Node Node *Node
WeFirst bool WeFirst bool
Policy1 *RoutingPolicy LocalPolicy *RoutingPolicy
Policy2 *RoutingPolicy RemotePolicy *RoutingPolicy
} }
func (m Channel) MarshalLogObject(enc logging.ObjectEncoder) error { func (m Channel) MarshalLogObject(enc logging.ObjectEncoder) error {

@ -108,12 +108,12 @@ func (c *Channels) Update(newChannel *models.Channel) {
oldChannel.LastUpdate = newChannel.LastUpdate oldChannel.LastUpdate = newChannel.LastUpdate
} }
if newChannel.Policy1 != nil { if newChannel.LocalPolicy != nil {
oldChannel.Policy1 = newChannel.Policy1 oldChannel.LocalPolicy = newChannel.LocalPolicy
} }
if newChannel.Policy2 != nil { if newChannel.RemotePolicy != nil {
oldChannel.Policy2 = newChannel.Policy2 oldChannel.RemotePolicy = newChannel.RemotePolicy
} }
} }

@ -148,6 +148,7 @@ func (c *Channel) display() {
channel := c.channels.Current() channel := c.channels.Current()
green := color.Green() green := color.Green()
cyan := color.Cyan() cyan := color.Cyan()
fmt.Fprintln(v, green(" [ Channel ]")) fmt.Fprintln(v, green(" [ Channel ]"))
fmt.Fprintf(v, "%s %s\n", fmt.Fprintf(v, "%s %s\n",
cyan(" Status:"), status(channel)) cyan(" Status:"), status(channel))
@ -161,7 +162,9 @@ func (c *Channel) display() {
cyan(" Remote Balance:"), channel.RemoteBalance) cyan(" Remote Balance:"), channel.RemoteBalance)
fmt.Fprintf(v, "%s %s\n", fmt.Fprintf(v, "%s %s\n",
cyan(" Channel Point:"), channel.ChannelPoint) cyan(" Channel Point:"), channel.ChannelPoint)
fmt.Fprintln(v, "") fmt.Fprintln(v, "")
fmt.Fprintln(v, green(" [ Node ]")) fmt.Fprintln(v, green(" [ Node ]"))
fmt.Fprintf(v, "%s %s\n", fmt.Fprintf(v, "%s %s\n",
cyan(" PubKey:"), channel.RemotePubKey) cyan(" PubKey:"), channel.RemotePubKey)
@ -178,17 +181,11 @@ func (c *Channel) display() {
fmt.Fprintf(v, "%s %d\n", fmt.Fprintf(v, "%s %d\n",
cyan(" Total Channels:"), channel.Node.NumChannels) cyan(" Total Channels:"), channel.Node.NumChannels)
} }
if channel.LocalPolicy != nil {
if channel.Policy1 != nil && channel.WeFirst { printPolicy(v, p, channel.LocalPolicy, true)
printPolicy(v, p, channel.Policy1, true)
} }
if channel.RemotePolicy != nil {
if channel.Policy2 != nil { printPolicy(v, p, channel.RemotePolicy, false)
printPolicy(v, p, channel.Policy2, !channel.WeFirst)
}
if channel.Policy1 != nil && !channel.WeFirst {
printPolicy(v, p, channel.Policy1, false)
} }
if len(channel.PendingHTLC) > 0 { if len(channel.PendingHTLC) > 0 {
fmt.Fprintln(v) fmt.Fprintln(v)

@ -546,19 +546,19 @@ func NewChannels(cfg *config.View, chans *models.Channels) *Channels {
return func(c1, c2 *netmodels.Channel) bool { return func(c1, c2 *netmodels.Channel) bool {
var c1f uint64 var c1f uint64
var c2f uint64 var c2f uint64
if c1.Policy1 != nil { if c1.LocalPolicy != nil {
c1f = uint64(c1.Policy1.FeeBaseMsat) c1f = uint64(c1.LocalPolicy.FeeBaseMsat)
} }
if c2.Policy1 != nil { if c2.LocalPolicy != nil {
c2f = uint64(c2.Policy1.FeeBaseMsat) c2f = uint64(c2.LocalPolicy.FeeBaseMsat)
} }
return models.UInt64Sort(c1f, c2f, order) return models.UInt64Sort(c1f, c2f, order)
} }
}, },
display: func(c *netmodels.Channel, opts ...color.Option) string { display: func(c *netmodels.Channel, opts ...color.Option) string {
var val int64 var val int64
if c.Policy1 != nil { if c.LocalPolicy != nil {
val = c.Policy1.FeeBaseMsat val = c.LocalPolicy.FeeBaseMsat
} }
return color.White(opts...)(printer.Sprintf("%8d", val)) return color.White(opts...)(printer.Sprintf("%8d", val))
}, },
@ -571,19 +571,19 @@ func NewChannels(cfg *config.View, chans *models.Channels) *Channels {
return func(c1, c2 *netmodels.Channel) bool { return func(c1, c2 *netmodels.Channel) bool {
var c1f uint64 var c1f uint64
var c2f uint64 var c2f uint64
if c1.Policy1 != nil { if c1.LocalPolicy != nil {
c1f = uint64(c1.Policy1.FeeRateMilliMsat) c1f = uint64(c1.LocalPolicy.FeeRateMilliMsat)
} }
if c2.Policy1 != nil { if c2.LocalPolicy != nil {
c2f = uint64(c2.Policy1.FeeRateMilliMsat) c2f = uint64(c2.LocalPolicy.FeeRateMilliMsat)
} }
return models.UInt64Sort(c1f, c2f, order) return models.UInt64Sort(c1f, c2f, order)
} }
}, },
display: func(c *netmodels.Channel, opts ...color.Option) string { display: func(c *netmodels.Channel, opts ...color.Option) string {
var val int64 var val int64
if c.Policy1 != nil { if c.LocalPolicy != nil {
val = c.Policy1.FeeRateMilliMsat val = c.LocalPolicy.FeeRateMilliMsat
} }
return color.White(opts...)(printer.Sprintf("%8d", val)) return color.White(opts...)(printer.Sprintf("%8d", val))
}, },
@ -596,19 +596,19 @@ func NewChannels(cfg *config.View, chans *models.Channels) *Channels {
return func(c1, c2 *netmodels.Channel) bool { return func(c1, c2 *netmodels.Channel) bool {
var c1f uint64 var c1f uint64
var c2f uint64 var c2f uint64
if c1.Policy2 != nil { if c1.RemotePolicy != nil {
c1f = uint64(c1.Policy2.FeeBaseMsat) c1f = uint64(c1.RemotePolicy.FeeBaseMsat)
} }
if c2.Policy2 != nil { if c2.RemotePolicy != nil {
c2f = uint64(c2.Policy2.FeeBaseMsat) c2f = uint64(c2.RemotePolicy.FeeBaseMsat)
} }
return models.UInt64Sort(c1f, c2f, order) return models.UInt64Sort(c1f, c2f, order)
} }
}, },
display: func(c *netmodels.Channel, opts ...color.Option) string { display: func(c *netmodels.Channel, opts ...color.Option) string {
var val int64 var val int64
if c.Policy2 != nil { if c.RemotePolicy != nil {
val = c.Policy2.FeeBaseMsat val = c.RemotePolicy.FeeBaseMsat
} }
return color.White(opts...)(printer.Sprintf("%7d", val)) return color.White(opts...)(printer.Sprintf("%7d", val))
}, },
@ -621,19 +621,19 @@ func NewChannels(cfg *config.View, chans *models.Channels) *Channels {
return func(c1, c2 *netmodels.Channel) bool { return func(c1, c2 *netmodels.Channel) bool {
var c1f uint64 var c1f uint64
var c2f uint64 var c2f uint64
if c1.Policy2 != nil { if c1.RemotePolicy != nil {
c1f = uint64(c1.Policy2.FeeRateMilliMsat) c1f = uint64(c1.RemotePolicy.FeeRateMilliMsat)
} }
if c2.Policy2 != nil { if c2.RemotePolicy != nil {
c2f = uint64(c2.Policy2.FeeRateMilliMsat) c2f = uint64(c2.RemotePolicy.FeeRateMilliMsat)
} }
return models.UInt64Sort(c1f, c2f, order) return models.UInt64Sort(c1f, c2f, order)
} }
}, },
display: func(c *netmodels.Channel, opts ...color.Option) string { display: func(c *netmodels.Channel, opts ...color.Option) string {
var val int64 var val int64
if c.Policy2 != nil { if c.RemotePolicy != nil {
val = c.Policy2.FeeRateMilliMsat val = c.RemotePolicy.FeeRateMilliMsat
} }
return color.White(opts...)(printer.Sprintf("%7d", val)) return color.White(opts...)(printer.Sprintf("%7d", val))
}, },

Loading…
Cancel
Save