switch: notify the ChannelNotifier on newly active/inactive channels.
This commit is contained in:
parent
f6cffa8f4b
commit
bdd8ce14c9
@ -162,9 +162,11 @@ func initSwitchWithDB(startingHeight uint32, db *channeldb.DB) (*Switch, error)
|
|||||||
FetchLastChannelUpdate: func(lnwire.ShortChannelID) (*lnwire.ChannelUpdate, error) {
|
FetchLastChannelUpdate: func(lnwire.ShortChannelID) (*lnwire.ChannelUpdate, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
},
|
},
|
||||||
Notifier: &mockNotifier{},
|
Notifier: &mockNotifier{},
|
||||||
FwdEventTicker: ticker.MockNew(DefaultFwdEventInterval),
|
FwdEventTicker: ticker.MockNew(DefaultFwdEventInterval),
|
||||||
LogEventTicker: ticker.MockNew(DefaultLogInterval),
|
LogEventTicker: ticker.MockNew(DefaultLogInterval),
|
||||||
|
NotifyActiveChannel: func(wire.OutPoint) {},
|
||||||
|
NotifyInactiveChannel: func(wire.OutPoint) {},
|
||||||
}
|
}
|
||||||
|
|
||||||
return New(cfg, startingHeight)
|
return New(cfg, startingHeight)
|
||||||
|
@ -175,6 +175,11 @@ type Config struct {
|
|||||||
// LogEventTicker is a signal instructing the htlcswitch to log
|
// LogEventTicker is a signal instructing the htlcswitch to log
|
||||||
// aggregate stats about it's forwarding during the last interval.
|
// aggregate stats about it's forwarding during the last interval.
|
||||||
LogEventTicker ticker.Ticker
|
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.
|
// 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] = make(map[lnwire.ChannelID]ChannelLink)
|
||||||
}
|
}
|
||||||
s.interfaceIndex[peerPub][link.ChanID()] = link
|
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
|
// 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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inform the Channel Notifier about the link becoming inactive.
|
||||||
|
s.cfg.NotifyInactiveChannel(*link.ChannelPoint())
|
||||||
|
|
||||||
// Remove the channel from live link indexes.
|
// Remove the channel from live link indexes.
|
||||||
delete(s.pendingLinkIndex, link.ChanID())
|
delete(s.pendingLinkIndex, link.ChanID())
|
||||||
delete(s.linkIndex, link.ChanID())
|
delete(s.linkIndex, link.ChanID())
|
||||||
|
@ -362,6 +362,8 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl,
|
|||||||
htlcswitch.DefaultFwdEventInterval),
|
htlcswitch.DefaultFwdEventInterval),
|
||||||
LogEventTicker: ticker.New(
|
LogEventTicker: ticker.New(
|
||||||
htlcswitch.DefaultLogInterval),
|
htlcswitch.DefaultLogInterval),
|
||||||
|
NotifyActiveChannel: s.channelNotifier.NotifyActiveChannelEvent,
|
||||||
|
NotifyInactiveChannel: s.channelNotifier.NotifyInactiveChannelEvent,
|
||||||
}, uint32(currentHeight))
|
}, uint32(currentHeight))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user