From dcff9e5e2693bd61bd320e99897197c60cf41905 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Mon, 9 Aug 2021 13:55:30 +0200 Subject: [PATCH] channelnotifier: add event for fully resolved channel We'll want to be informed about a channel that's been fully resolved on chain in case it was involved in a force close. We add a new event type and emit method for it. --- channelnotifier/channelnotifier.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/channelnotifier/channelnotifier.go b/channelnotifier/channelnotifier.go index f5aa29617..df062c437 100644 --- a/channelnotifier/channelnotifier.go +++ b/channelnotifier/channelnotifier.go @@ -65,6 +65,14 @@ type ClosedChannelEvent struct { CloseSummary *channeldb.ChannelCloseSummary } +// FullyResolvedChannelEvent represents a new event where a channel becomes +// fully resolved. +type FullyResolvedChannelEvent struct { + // ChannelPoint is the channelpoint for the newly fully resolved + // channel. + ChannelPoint *wire.OutPoint +} + // New creates a new channel notifier. The ChannelNotifier gets channel // events from peers and from the chain arbitrator, and dispatches them to // its clients. @@ -125,7 +133,6 @@ func (c *ChannelNotifier) NotifyPendingOpenChannelEvent(chanPoint wire.OutPoint, // NotifyOpenChannelEvent notifies the channelEventNotifier goroutine that a // channel has gone from pending open to open. func (c *ChannelNotifier) NotifyOpenChannelEvent(chanPoint wire.OutPoint) { - // Fetch the relevant channel from the database. channel, err := c.chanDB.FetchChannel(chanPoint) if err != nil { @@ -155,6 +162,18 @@ func (c *ChannelNotifier) NotifyClosedChannelEvent(chanPoint wire.OutPoint) { } } +// NotifyFullyResolvedChannelEvent notifies the channelEventNotifier goroutine +// that a channel was fully resolved on chain. +func (c *ChannelNotifier) NotifyFullyResolvedChannelEvent( + chanPoint wire.OutPoint) { + + // Send the resolved event to all channel event subscribers. + event := FullyResolvedChannelEvent{ChannelPoint: &chanPoint} + if err := c.ntfnServer.SendUpdate(event); err != nil { + log.Warnf("Unable to send resolved channel update: %v", err) + } +} + // NotifyActiveLinkEvent notifies the channelEventNotifier goroutine that a // link has been added to the switch. func (c *ChannelNotifier) NotifyActiveLinkEvent(chanPoint wire.OutPoint) {