multi: surface closedchannels on lndclient

This commit is contained in:
Carla Kirk-Cohen 2023-10-11 12:53:37 -04:00
parent 85a1d48bf4
commit 50b32abce1
No known key found for this signature in database
GPG key ID: 4CA7FE54A6213C91
4 changed files with 53 additions and 0 deletions

View file

@ -255,6 +255,49 @@ func (l *lndclientGrpc) listChannels() (map[uint64]*channel, error) {
return chans, nil
}
func (l *lndclientGrpc) listClosedChannels() (map[uint64]*channel, error) {
ctx, cancel := context.WithTimeout(ctxb, rpcTimeout)
defer cancel()
resp, err := l.main.ClosedChannels(ctx, &lnrpc.ClosedChannelsRequest{})
if err != nil {
return nil, err
}
chans := make(map[uint64]*channel)
for _, rpcChan := range resp.Channels {
peer, err := route.NewVertexFromStr(rpcChan.RemotePubkey)
if err != nil {
return nil, err
}
channel := &channel{
peer: peer,
}
// LND didn't always store who initiated the channel, so in some cases
// we don't know who initiated the channel (for very old channels). We're
// unlikely to hit this case since we're dealing with channels related
// to current forwards, so we just log that we don't know this value and
// allow initiator to be true.
switch rpcChan.OpenInitiator {
case lnrpc.Initiator_INITIATOR_LOCAL:
channel.initiator = true
case lnrpc.Initiator_INITIATOR_REMOTE:
default:
channel.initiator = true
log.Debugf("Channel initiator for %v with %v unknown",
rpcChan.ChanId, peer)
}
chans[rpcChan.ChanId] = channel
}
return chans, nil
}
func (l *lndclientGrpc) subscribeHtlcEvents(ctx context.Context) (
htlcEventsClient, error) {

View file

@ -50,6 +50,10 @@ func (l *lndclientMock) listChannels() (map[uint64]*channel, error) {
return l.channels, nil
}
func (l *lndclientMock) listClosedChannels() (map[uint64]*channel, error) {
return make(map[uint64]*channel), nil
}
func (l *lndclientMock) subscribeHtlcEvents(ctx context.Context) (
htlcEventsClient, error) {

View file

@ -26,6 +26,8 @@ type lndclient interface {
listChannels() (map[uint64]*channel, error)
listClosedChannels() (map[uint64]*channel, error)
getNodeAlias(key route.Vertex) (string, error)
subscribeHtlcEvents(ctx context.Context) (htlcEventsClient, error)

View file

@ -335,6 +335,10 @@ func (s *stubLndClient) listChannels() (map[uint64]*channel, error) {
return allChannels, nil
}
func (s *stubLndClient) listClosedChannels() (map[uint64]*channel, error) {
return make(map[uint64]*channel), nil
}
func (s *stubLndClient) getNodeAlias(key route.Vertex) (string, error) {
peer, ok := s.peers[key]
if !ok {