From 966cd2112cfe9481714133be49afe6b5e4c67f98 Mon Sep 17 00:00:00 2001 From: nsa Date: Fri, 6 Mar 2020 22:42:58 -0500 Subject: [PATCH] multi: link notifies subscribers of ActiveLinkEvent, rpc ignores --- htlcswitch/link.go | 8 ++++++++ htlcswitch/link_test.go | 2 ++ htlcswitch/test_utils.go | 1 + peer.go | 2 ++ rpcserver.go | 7 +++++++ 5 files changed, 20 insertions(+) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index ff631a59..d91bc856 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -265,6 +265,10 @@ type ChannelLinkConfig struct { // initiator of the channel. MaxFeeAllocation float64 + // NotifyActiveLink allows the link to tell the ChannelNotifier when a + // link is first started. + NotifyActiveLink func(wire.OutPoint) + // NotifyActiveChannel allows the link to tell the ChannelNotifier when // channels becomes active. NotifyActiveChannel func(wire.OutPoint) @@ -870,6 +874,10 @@ func (l *channelLink) htlcManager() { l.log.Infof("HTLC manager started, bandwidth=%v", l.Bandwidth()) + // Notify any clients that the link is now in the switch via an + // ActiveLinkEvent. + l.cfg.NotifyActiveLink(*l.ChannelPoint()) + // TODO(roasbeef): need to call wipe chan whenever D/C? // If this isn't the first time that this channel link has been diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index d7f95df1..d150ddc5 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -1748,6 +1748,7 @@ func newSingleLinkTestHarness(chanAmt, chanReserve btcutil.Amount) ( MaxFeeUpdateTimeout: 40 * time.Minute, MaxOutgoingCltvExpiry: DefaultMaxOutgoingCltvExpiry, MaxFeeAllocation: DefaultMaxLinkFeeAllocation, + NotifyActiveLink: func(wire.OutPoint) {}, NotifyActiveChannel: func(wire.OutPoint) {}, NotifyInactiveChannel: func(wire.OutPoint) {}, HtlcNotifier: aliceSwitch.cfg.HtlcNotifier, @@ -4474,6 +4475,7 @@ func (h *persistentLinkHarness) restartLink( HodlMask: hodl.MaskFromFlags(hodlFlags...), MaxOutgoingCltvExpiry: DefaultMaxOutgoingCltvExpiry, MaxFeeAllocation: DefaultMaxLinkFeeAllocation, + NotifyActiveLink: func(wire.OutPoint) {}, NotifyActiveChannel: func(wire.OutPoint) {}, NotifyInactiveChannel: func(wire.OutPoint) {}, HtlcNotifier: aliceSwitch.cfg.HtlcNotifier, diff --git a/htlcswitch/test_utils.go b/htlcswitch/test_utils.go index f628f280..f302ff01 100644 --- a/htlcswitch/test_utils.go +++ b/htlcswitch/test_utils.go @@ -1173,6 +1173,7 @@ func (h *hopNetwork) createChannelLink(server, peer *mockServer, OutgoingCltvRejectDelta: 3, MaxOutgoingCltvExpiry: DefaultMaxOutgoingCltvExpiry, MaxFeeAllocation: DefaultMaxLinkFeeAllocation, + NotifyActiveLink: func(wire.OutPoint) {}, NotifyActiveChannel: func(wire.OutPoint) {}, NotifyInactiveChannel: func(wire.OutPoint) {}, HtlcNotifier: server.htlcSwitch.cfg.HtlcNotifier, diff --git a/peer.go b/peer.go index 2236e66c..4368f71b 100644 --- a/peer.go +++ b/peer.go @@ -21,6 +21,7 @@ import ( "github.com/lightningnetwork/lnd/buffer" "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/channelnotifier" "github.com/lightningnetwork/lnd/contractcourt" "github.com/lightningnetwork/lnd/feature" "github.com/lightningnetwork/lnd/htlcswitch" @@ -649,6 +650,7 @@ func (p *peer) addLink(chanPoint *wire.OutPoint, TowerClient: p.server.towerClient, MaxOutgoingCltvExpiry: cfg.MaxOutgoingCltvExpiry, MaxFeeAllocation: cfg.MaxChannelFeeAllocation, + NotifyActiveLink: p.server.channelNotifier.NotifyActiveLinkEvent, NotifyActiveChannel: p.server.channelNotifier.NotifyActiveChannelEvent, NotifyInactiveChannel: p.server.channelNotifier.NotifyInactiveChannelEvent, HtlcNotifier: p.server.htlcNotifier, diff --git a/rpcserver.go b/rpcserver.go index 721b4fad..947d462c 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -3522,6 +3522,11 @@ func (r *rpcServer) SubscribeChannelEvents(req *lnrpc.ChannelEventSubscription, }, } + // Completely ignore ActiveLinkEvent as this is explicitly not + // exposed to the RPC. + case channelnotifier.ActiveLinkEvent: + continue + default: return fmt.Errorf("unexpected channel event update: %v", event) } @@ -5896,6 +5901,8 @@ func (r *rpcServer) SubscribeChannelBackups(req *lnrpc.ChannelBackupSubscription continue case channelnotifier.InactiveChannelEvent: continue + case channelnotifier.ActiveLinkEvent: + continue } // Now that we know the channel state has changed,