channelnotifier: let notifier take channel updates
What changed, and why it matters
This commit adds a new internal notification type so that parts of the LND program can be told when a Lightning channel's state changes. It is purely an infrastructure/observability change: it adds a new event struct, a function to send the event, and a unit test. There is no change to network-facing behavior, authentication, cryptography, or money-handling logic.
No security action required; review as normal feature/infrastructure code.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch extends channelnotifier.go with a ChannelUpdateEvent type and a NotifyChannelUpdateEvent method that publishes an OpenChannel reference to existing subscribers. A new test verifies the event is delivered. The change is additive only and does not modify existing event handling, state machines, or RPC interfaces.
Changed components
channelnotifier/channelnotifier.gochannelnotifier/channelnotifier_test.goInspect captured patch +60 / −0
diff --git a/channelnotifier/channelnotifier.go b/channelnotifier/channelnotifier.go
index f13ca6d..e7b815b 100644
--- a/channelnotifier/channelnotifier.go
+++ b/channelnotifier/channelnotifier.go
@@ -72,6 +72,12 @@ type ClosedChannelEvent struct {
CloseSummary *channeldb.ChannelCloseSummary
}
+// ChannelUpdateEvent represents a new event where a channel's state is updated.
+type ChannelUpdateEvent struct {
+ // Channel is the channel that has been updated.
+ Channel *channeldb.OpenChannel
+}
+
// FullyResolvedChannelEvent represents a new event where a channel becomes
// fully resolved.
type FullyResolvedChannelEvent struct {
@@ -238,3 +244,14 @@ func (c *ChannelNotifier) NotifyInactiveChannelEvent(chanPoint wire.OutPoint) {
log.Warnf("Unable to send inactive channel update: %v", err)
}
}
+
+// NotifyChannelUpdateEvent notifies subscribers that a channel's state has been
+// updated.
+func (c *ChannelNotifier) NotifyChannelUpdateEvent(
+ channel *channeldb.OpenChannel) {
+
+ event := ChannelUpdateEvent{Channel: channel}
+ if err := c.ntfnServer.SendUpdate(event); err != nil {
+ log.Warnf("Unable to send channel update: %v", err)
+ }
+}
diff --git a/channelnotifier/channelnotifier_test.go b/channelnotifier/channelnotifier_test.go
new file mode 100644
index 0000000..5dbdb4a
--- /dev/null
+++ b/channelnotifier/channelnotifier_test.go
@@ -0,0 +1,43 @@
+package channelnotifier
+
+import (
+ "testing"
+ "time"
+
+ "github.com/lightningnetwork/lnd/channeldb"
+ "github.com/stretchr/testify/require"
+)
+
+// TestChannelUpdateEvent tests that channel update events are properly
+// notified to subscribers.
+func TestChannelUpdateEvent(t *testing.T) {
+ // Initialize the notification server.
+ ntfnServer := New(nil)
+ require.NoError(t, ntfnServer.Start())
+
+ defer func() {
+ require.NoError(t, ntfnServer.Stop())
+ }()
+
+ // Subscribe to channel events.
+ sub, err := ntfnServer.SubscribeChannelEvents()
+ require.NoError(t, err)
+ defer sub.Cancel()
+
+ // Create a mock channel state.
+ channel := &channeldb.OpenChannel{}
+
+ // Notify the server of a channel update event.
+ ntfnServer.NotifyChannelUpdateEvent(channel)
+
+ // Consume the event.
+ select {
+ case event := <-sub.Updates():
+ updateEvent, ok := event.(ChannelUpdateEvent)
+ require.True(t, ok)
+ require.Equal(t, channel, updateEvent.Channel)
+
+ case <-time.After(time.Second):
+ t.Fatalf("expected to receive channel update event")
+ }
+}
Why this scored 13/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.