diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index 4ac8c947..9f35b9cd 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.go @@ -162,9 +162,11 @@ func initSwitchWithDB(startingHeight uint32, db *channeldb.DB) (*Switch, error) FetchLastChannelUpdate: func(lnwire.ShortChannelID) (*lnwire.ChannelUpdate, error) { return nil, nil }, - Notifier: &mockNotifier{}, - FwdEventTicker: ticker.MockNew(DefaultFwdEventInterval), - LogEventTicker: ticker.MockNew(DefaultLogInterval), + Notifier: &mockNotifier{}, + FwdEventTicker: ticker.MockNew(DefaultFwdEventInterval), + LogEventTicker: ticker.MockNew(DefaultLogInterval), + NotifyActiveChannel: func(wire.OutPoint) {}, + NotifyInactiveChannel: func(wire.OutPoint) {}, } return New(cfg, startingHeight) diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index 0968cba5..63e19f33 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -175,6 +175,11 @@ type Config struct { // LogEventTicker is a signal instructing the htlcswitch to log // aggregate stats about it's forwarding during the last interval. LogEventTicker ticker.Ticker + + // NotifyActiveChannel and NotifyInactiveChannel allow the link to tell + // the ChannelNotifier when channels become active and inactive. + NotifyActiveChannel func(wire.OutPoint) + NotifyInactiveChannel func(wire.OutPoint) } // Switch is the central messaging bus for all incoming/outgoing HTLCs. @@ -1956,6 +1961,11 @@ func (s *Switch) addLiveLink(link ChannelLink) { s.interfaceIndex[peerPub] = make(map[lnwire.ChannelID]ChannelLink) } s.interfaceIndex[peerPub][link.ChanID()] = link + + // Inform the channel notifier if the link has become active. + if link.EligibleToForward() { + s.cfg.NotifyActiveChannel(*link.ChannelPoint()) + } } // GetLink is used to initiate the handling of the get link command. The @@ -2031,6 +2041,9 @@ func (s *Switch) removeLink(chanID lnwire.ChannelID) ChannelLink { return nil } + // Inform the Channel Notifier about the link becoming inactive. + s.cfg.NotifyInactiveChannel(*link.ChannelPoint()) + // Remove the channel from live link indexes. delete(s.pendingLinkIndex, link.ChanID()) delete(s.linkIndex, link.ChanID()) diff --git a/server.go b/server.go index 2d32239c..3be02cdd 100644 --- a/server.go +++ b/server.go @@ -362,6 +362,8 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl, htlcswitch.DefaultFwdEventInterval), LogEventTicker: ticker.New( htlcswitch.DefaultLogInterval), + NotifyActiveChannel: s.channelNotifier.NotifyActiveChannelEvent, + NotifyInactiveChannel: s.channelNotifier.NotifyInactiveChannelEvent, }, uint32(currentHeight)) if err != nil { return nil, err