Implement lightweight method to check is peer has update channel (#1351)

Instead of GetAllConnectedPeers that need to traverse the whole
connections map in order to find one channel there.
This commit is contained in:
Yury Gargay
2023-12-05 14:17:56 +01:00
committed by GitHub
parent 45fc89b2c9
commit 27ed88f918
6 changed files with 49 additions and 49 deletions

View File

@@ -151,3 +151,21 @@ func (p *PeersUpdateManager) GetAllConnectedPeers() map[string]struct{} {
return m
}
// HasChannel returns true if peers has channel in update manager, otherwise false
func (p *PeersUpdateManager) HasChannel(peerID string) bool {
start := time.Now()
p.channelsMux.Lock()
defer func() {
p.channelsMux.Unlock()
if p.metrics != nil {
p.metrics.UpdateChannelMetrics().CountHasChannelDuration(time.Since(start))
}
}()
_, ok := p.peerChannels[peerID]
return ok
}