Show closed channels, fix policy order

pull/76/head
rkfg 2 years ago
parent eb662744e7
commit a2590193d0

@ -21,7 +21,7 @@ import (
const ( const (
lndDefaultInvoiceExpiry = 3600 lndDefaultInvoiceExpiry = 3600
lndMinPoolCapacity = 4 lndMinPoolCapacity = 5
) )
type Client struct { type Client struct {
@ -91,7 +91,7 @@ func (l Backend) SubscribeInvoice(ctx context.Context, channelInvoice chan *mode
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
break return nil
default: default:
invoice, err := cltInvoices.Recv() invoice, err := cltInvoices.Recv()
if err != nil { if err != nil {
@ -123,7 +123,7 @@ func (l Backend) SubscribeTransactions(ctx context.Context, channel chan *models
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
break return nil
default: default:
transaction, err := cltTransactions.Recv() transaction, err := cltTransactions.Recv()
if err != nil { if err != nil {
@ -141,24 +141,37 @@ func (l Backend) SubscribeTransactions(ctx context.Context, channel chan *models
} }
func (l Backend) SubscribeChannels(ctx context.Context, events chan *models.ChannelUpdate) error { func (l Backend) SubscribeChannels(ctx context.Context, events chan *models.ChannelUpdate) error {
_, err := l.Client(ctx) clt, err := l.Client(ctx)
if err != nil { if err != nil {
return err return err
} }
defer clt.Close()
// events, err := clt.SubscribeChannelEvents(ctx, &lnrpc.ChannelEventSubscription{}) channelEvents, err := clt.SubscribeChannelEvents(ctx, &lnrpc.ChannelEventSubscription{})
// if err != nil { if err != nil {
// return err return err
// } }
// for { for {
// event, err := events.Recv() select {
// if err != nil { case <-ctx.Done():
// return err return nil
// } default:
// events <- event, err := channelEvents.Recv()
//} if err != nil {
return nil st, ok := status.FromError(err)
if ok && st.Code() == codes.Canceled {
l.logger.Debug("stopping subscribe channels: context canceled")
return nil
}
return err
}
if event.Type == lnrpc.ChannelEventUpdate_FULLY_RESOLVED_CHANNEL {
events <- &models.ChannelUpdate{}
}
}
}
} }
func (l Backend) SubscribeRoutingEvents(ctx context.Context, channelEvents chan *models.RoutingEvent) error { func (l Backend) SubscribeRoutingEvents(ctx context.Context, channelEvents chan *models.RoutingEvent) error {
@ -176,7 +189,7 @@ func (l Backend) SubscribeRoutingEvents(ctx context.Context, channelEvents chan
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
break return nil
default: default:
event, err := cltRoutingEvents.Recv() event, err := cltRoutingEvents.Recv()
if err != nil { if err != nil {

@ -1,6 +1,7 @@
package models package models
import ( import (
"strings"
"time" "time"
"github.com/edouardparis/lntop/logging" "github.com/edouardparis/lntop/logging"
@ -13,6 +14,7 @@ const (
ChannelClosing ChannelClosing
ChannelForceClosing ChannelForceClosing
ChannelWaitingClose ChannelWaitingClose
ChannelClosed
) )
type ChannelsBalance struct { type ChannelsBalance struct {
@ -78,7 +80,7 @@ func (m Channel) ShortAlias() (alias string, forced bool) {
} else if m.Node == nil || m.Node.Alias == "" { } else if m.Node == nil || m.Node.Alias == "" {
alias = m.RemotePubKey[:24] alias = m.RemotePubKey[:24]
} else { } else {
alias = m.Node.Alias alias = strings.ReplaceAll(m.Node.Alias, "\ufe0f", "")
} }
if len(alias) > 25 { if len(alias) > 25 {
alias = alias[:24] alias = alias[:24]

@ -117,6 +117,35 @@ func (p *PubSub) routingUpdates(ctx context.Context, sub chan *events.Event) {
}() }()
} }
func (p *PubSub) channels(ctx context.Context, sub chan *events.Event) {
p.wg.Add(3)
channels := make(chan *models.ChannelUpdate)
ctx, cancel := context.WithCancel(ctx)
go func() {
for range channels {
p.logger.Debug("channels updated")
sub <- events.New(events.ChannelActive)
}
p.wg.Done()
}()
go func() {
err := p.network.SubscribeChannels(ctx, channels)
if err != nil {
p.logger.Error("SubscribeChannels returned an error", logging.Error(err))
}
p.wg.Done()
}()
go func() {
<-p.stop
cancel()
close(channels)
p.wg.Done()
}()
}
func (p *PubSub) Stop() { func (p *PubSub) Stop() {
p.stop <- true p.stop <- true
close(p.stop) close(p.stop)
@ -129,6 +158,7 @@ func (p *PubSub) Run(ctx context.Context, sub chan *events.Event) {
p.invoices(ctx, sub) p.invoices(ctx, sub)
p.transactions(ctx, sub) p.transactions(ctx, sub)
p.routingUpdates(ctx, sub) p.routingUpdates(ctx, sub)
p.channels(ctx, sub)
p.ticker(ctx, sub, p.ticker(ctx, sub,
withTickerInfo(), withTickerInfo(),
withTickerChannelsBalance(), withTickerChannelsBalance(),

@ -52,14 +52,16 @@ func (m *Models) RefreshChannels(ctx context.Context) error {
if err != nil { if err != nil {
return err return err
} }
index := map[string]*models.Channel{}
for i := range channels { for i := range channels {
index[channels[i].ChannelPoint] = channels[i]
if !m.Channels.Contains(channels[i]) { if !m.Channels.Contains(channels[i]) {
m.Channels.Add(channels[i]) m.Channels.Add(channels[i])
} }
channel := m.Channels.GetByChanPoint(channels[i].ChannelPoint) channel := m.Channels.GetByChanPoint(channels[i].ChannelPoint)
if channel != nil && if channel != nil &&
(channel.UpdatesCount < channels[i].UpdatesCount || (channel.UpdatesCount < channels[i].UpdatesCount ||
channel.LastUpdate == nil) { channel.LastUpdate == nil || channel.Policy1 == nil || channel.Policy2 == nil) {
err := m.network.GetChannelInfo(ctx, channels[i]) err := m.network.GetChannelInfo(ctx, channels[i])
if err != nil { if err != nil {
return err return err
@ -77,6 +79,11 @@ func (m *Models) RefreshChannels(ctx context.Context) error {
m.Channels.Update(channels[i]) m.Channels.Update(channels[i])
} }
for _, c := range m.Channels.List() {
if _, ok := index[c.ChannelPoint]; !ok {
c.Status = models.ChannelClosed
}
}
return nil return nil
} }

@ -666,6 +666,8 @@ func status(c *netmodels.Channel, opts ...color.Option) string {
return color.Yellow(opts...)(fmt.Sprintf("%-13s", "force closing")) return color.Yellow(opts...)(fmt.Sprintf("%-13s", "force closing"))
case netmodels.ChannelWaitingClose: case netmodels.ChannelWaitingClose:
return color.Yellow(opts...)(fmt.Sprintf("%-13s", "waiting close")) return color.Yellow(opts...)(fmt.Sprintf("%-13s", "waiting close"))
case netmodels.ChannelClosed:
return color.Red(opts...)(fmt.Sprintf("%-13s", "closed"))
} }
return "" return ""
} }

Loading…
Cancel
Save