From ced883389508b7601c37e5957f546dfb59e8bfbf Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 24 Nov 2022 06:57:53 +0800 Subject: [PATCH] channelnotifier: add `InactiveLinkEvent` This commit adds a new event `InactiveLinkEvent` to be used when a link becomes inactive. --- channelnotifier/channelnotifier.go | 16 ++++++++++++++++ rpcserver.go | 11 ++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/channelnotifier/channelnotifier.go b/channelnotifier/channelnotifier.go index 7c6cc3095..78e1a8033 100644 --- a/channelnotifier/channelnotifier.go +++ b/channelnotifier/channelnotifier.go @@ -47,6 +47,13 @@ type ActiveLinkEvent struct { ChannelPoint *wire.OutPoint } +// InactiveLinkEvent represents a new event where the link becomes inactive in +// the switch. +type InactiveLinkEvent struct { + // ChannelPoint is the channel point for the inactive channel. + ChannelPoint *wire.OutPoint +} + // ActiveChannelEvent represents a new event where a channel becomes active. type ActiveChannelEvent struct { // ChannelPoint is the channelpoint for the newly active channel. @@ -193,6 +200,15 @@ func (c *ChannelNotifier) NotifyActiveChannelEvent(chanPoint wire.OutPoint) { } } +// NotifyInactiveLinkEvent notifies the channelEventNotifier goroutine that a +// link has been removed from the switch. +func (c *ChannelNotifier) NotifyInactiveLinkEvent(chanPoint wire.OutPoint) { + event := InactiveLinkEvent{ChannelPoint: &chanPoint} + if err := c.ntfnServer.SendUpdate(event); err != nil { + log.Warnf("Unable to send inactive link update: %v", err) + } +} + // NotifyInactiveChannelEvent notifies the channelEventNotifier goroutine that a // channel is inactive. func (c *ChannelNotifier) NotifyInactiveChannelEvent(chanPoint wire.OutPoint) { diff --git a/rpcserver.go b/rpcserver.go index a5bd31686..7e4ded225 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -4624,9 +4624,12 @@ func (r *rpcServer) SubscribeChannelEvents(req *lnrpc.ChannelEventSubscription, }, } - // Completely ignore ActiveLinkEvent as this is explicitly not - // exposed to the RPC. - case channelnotifier.ActiveLinkEvent: + // Completely ignore ActiveLinkEvent and + // InactiveLinkEvent as this is explicitly not exposed + // to the RPC. + case channelnotifier.ActiveLinkEvent, + channelnotifier.InactiveLinkEvent: + continue case channelnotifier.FullyResolvedChannelEvent: @@ -7323,6 +7326,8 @@ func (r *rpcServer) SubscribeChannelBackups(req *lnrpc.ChannelBackupSubscription continue case channelnotifier.ActiveLinkEvent: continue + case channelnotifier.InactiveLinkEvent: + continue } // Now that we know the channel state has changed,