refactor: move various duties from ChannelRouter to graph.Builder
This commit is a large refactor that moves over various responsibilities from the ChannelRouter to the graph.Builder. These include all graph related tasks such as: - graph pruning - validation of new network updates & persisting new updates - notifying topology update clients of any changes. This is a large commit but: - many of the files are purely moved from `routing` to `graph` - the business logic put in the graph Builder is copied exactly as is from the ChannelRouter with one exception: - The ChannelRouter just needs to be able to call the Builder's `ApplyChannelUpdate` method. So this is now exported and provided to the ChannelRouter as a config option. - The trickiest part was just moving over the test code since quite a bit had to be duplicated.
This commit is contained in:
26 files changed
+5121
-3862
No files matched your search
@@ -342,7 +342,7 @@ type server struct {
|
||||
// updatePersistentPeerAddrs subscribes to topology changes and stores
|
||||
// advertised addresses for any NodeAnnouncements from our persisted peers.
|
||||
func (s *server) updatePersistentPeerAddrs() error {
|
||||
graphSub, err := s.chanRouter.SubscribeTopology()
|
||||
graphSub, err := s.graphBuilder.SubscribeTopology()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -976,32 +976,36 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
||||
strictPruning := cfg.Bitcoin.Node == "neutrino" ||
|
||||
cfg.Routing.StrictZombiePruning
|
||||
|
||||
s.graphBuilder, err = graph.NewBuilder(&graph.Config{})
|
||||
s.graphBuilder, err = graph.NewBuilder(&graph.Config{
|
||||
SelfNode: selfNode.PubKeyBytes,
|
||||
Graph: chanGraph,
|
||||
Chain: cc.ChainIO,
|
||||
ChainView: cc.ChainView,
|
||||
Notifier: cc.ChainNotifier,
|
||||
ChannelPruneExpiry: graph.DefaultChannelPruneExpiry,
|
||||
GraphPruneInterval: time.Hour,
|
||||
FirstTimePruneDelay: graph.DefaultFirstTimePruneDelay,
|
||||
AssumeChannelValid: cfg.Routing.AssumeChannelValid,
|
||||
StrictZombiePruning: strictPruning,
|
||||
IsAlias: aliasmgr.IsAlias,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't create graph builder: %w", err)
|
||||
}
|
||||
|
||||
s.chanRouter, err = routing.New(routing.Config{
|
||||
SelfNode: selfNode.PubKeyBytes,
|
||||
RoutingGraph: graphsession.NewRoutingGraph(chanGraph),
|
||||
Graph: chanGraph,
|
||||
Chain: cc.ChainIO,
|
||||
ChainView: cc.ChainView,
|
||||
Notifier: cc.ChainNotifier,
|
||||
Payer: s.htlcSwitch,
|
||||
Control: s.controlTower,
|
||||
MissionControl: s.missionControl,
|
||||
SessionSource: paymentSessionSource,
|
||||
ChannelPruneExpiry: routing.DefaultChannelPruneExpiry,
|
||||
GraphPruneInterval: time.Hour,
|
||||
FirstTimePruneDelay: routing.DefaultFirstTimePruneDelay,
|
||||
GetLink: s.htlcSwitch.GetLinkByShortID,
|
||||
AssumeChannelValid: cfg.Routing.AssumeChannelValid,
|
||||
NextPaymentID: sequencer.NextID,
|
||||
PathFindingConfig: pathFindingConfig,
|
||||
Clock: clock.NewDefaultClock(),
|
||||
StrictZombiePruning: strictPruning,
|
||||
IsAlias: aliasmgr.IsAlias,
|
||||
SelfNode: selfNode.PubKeyBytes,
|
||||
RoutingGraph: graphsession.NewRoutingGraph(chanGraph),
|
||||
Chain: cc.ChainIO,
|
||||
Payer: s.htlcSwitch,
|
||||
Control: s.controlTower,
|
||||
MissionControl: s.missionControl,
|
||||
SessionSource: paymentSessionSource,
|
||||
GetLink: s.htlcSwitch.GetLinkByShortID,
|
||||
NextPaymentID: sequencer.NextID,
|
||||
PathFindingConfig: pathFindingConfig,
|
||||
Clock: clock.NewDefaultClock(),
|
||||
ApplyChannelUpdate: s.graphBuilder.ApplyChannelUpdate,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't create router: %w", err)
|
||||
@@ -1018,7 +1022,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
||||
}
|
||||
|
||||
s.authGossiper = discovery.New(discovery.Config{
|
||||
Router: s.chanRouter,
|
||||
Router: s.graphBuilder,
|
||||
Notifier: s.cc.ChainNotifier,
|
||||
ChainHash: *s.cfg.ActiveNetParams.GenesisHash,
|
||||
Broadcast: s.BroadcastMessage,
|
||||
@@ -1053,11 +1057,11 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
||||
FindBaseByAlias: s.aliasMgr.FindBaseSCID,
|
||||
GetAlias: s.aliasMgr.GetPeerAlias,
|
||||
FindChannel: s.findChannel,
|
||||
IsStillZombieChannel: s.chanRouter.IsZombieChannel,
|
||||
IsStillZombieChannel: s.graphBuilder.IsZombieChannel,
|
||||
}, nodeKeyDesc)
|
||||
|
||||
s.localChanMgr = &localchans.Manager{
|
||||
ForAllOutgoingChannels: s.chanRouter.ForAllOutgoingChannels,
|
||||
ForAllOutgoingChannels: s.graphBuilder.ForAllOutgoingChannels,
|
||||
PropagateChanPolicyUpdate: s.authGossiper.PropagateChanPolicyUpdate,
|
||||
UpdateForwardingPolicies: s.htlcSwitch.UpdateForwardingPolicies,
|
||||
FetchChannel: s.chanStateDB.FetchChannel,
|
||||
@@ -4667,7 +4671,7 @@ func (s *server) fetchLastChanUpdate() func(lnwire.ShortChannelID) (
|
||||
|
||||
ourPubKey := s.identityECDH.PubKey().SerializeCompressed()
|
||||
return func(cid lnwire.ShortChannelID) (*lnwire.ChannelUpdate, error) {
|
||||
info, edge1, edge2, err := s.chanRouter.GetChannelByID(cid)
|
||||
info, edge1, edge2, err := s.graphBuilder.GetChannelByID(cid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user