mirror of
https://github.com/lightningequipment/circuitbreaker.git
synced 2026-08-13 12:33:02 +02:00
multi: surface closedchannels on lndclient
This commit is contained in:
parent
85a1d48bf4
commit
50b32abce1
4 changed files with 53 additions and 0 deletions
43
lndclient.go
43
lndclient.go
|
|
@ -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) {
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
4
stub.go
4
stub.go
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue