routing: remove the selfNode attribute from memory

In this commit, we’ve removed the selfNode attribute from memory, as
the set of new tests we’ll write, will depend on us being able to
switch the source node dynamically from the database itself.
This commit is contained in:
Olaoluwa Osuntokun 2017-10-18 21:41:56 -07:00
parent f5881ad3df
commit 65482faa79
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -162,11 +162,6 @@ type ChannelRouter struct {
// initialized with. // initialized with.
cfg *Config cfg *Config
// selfNode is the center of the star-graph centered around the
// ChannelRouter. The ChannelRouter uses this node as a starting point
// when doing any path finding.
selfNode *channeldb.LightningNode
// routeCache is a map that caches the k-shortest paths from ourselves // routeCache is a map that caches the k-shortest paths from ourselves
// to a given target destination for a particular payment amount. This // to a given target destination for a particular payment amount. This
// map is used as an optimization to speed up subsequent payments to a // map is used as an optimization to speed up subsequent payments to a
@ -223,14 +218,9 @@ var _ ChannelGraphSource = (*ChannelRouter)(nil)
// channel graph is a subset of the UTXO set) set, then the router will proceed // channel graph is a subset of the UTXO set) set, then the router will proceed
// to fully sync to the latest state of the UTXO set. // to fully sync to the latest state of the UTXO set.
func New(cfg Config) (*ChannelRouter, error) { func New(cfg Config) (*ChannelRouter, error) {
selfNode, err := cfg.Graph.SourceNode()
if err != nil {
return nil, err
}
return &ChannelRouter{ return &ChannelRouter{
cfg: &cfg, cfg: &cfg,
selfNode: selfNode,
networkUpdates: make(chan *routingMsg), networkUpdates: make(chan *routingMsg),
topologyClients: make(map[uint64]*topologyClient), topologyClients: make(map[uint64]*topologyClient),
ntfnClientUpdates: make(chan *topologyClientUpdate), ntfnClientUpdates: make(chan *topologyClientUpdate),
@ -1006,11 +996,15 @@ func (r *ChannelRouter) FindRoutes(target *btcec.PublicKey,
return nil, err return nil, err
} }
selfNode, err := r.cfg.Graph.SourceNode()
if err != nil {
return nil, err
}
// Now that we know the destination is reachable within the graph, // Now that we know the destination is reachable within the graph,
// we'll execute our KSP algorithm to find the k-shortest paths from // we'll execute our KSP algorithm to find the k-shortest paths from
// our source to the destination. // our source to the destination.
shortestPaths, err := findPaths(tx, r.cfg.Graph, r.selfNode, target, shortestPaths, err := findPaths(tx, r.cfg.Graph, selfNode, target, amt)
amt)
if err != nil { if err != nil {
tx.Rollback() tx.Rollback()
return nil, err return nil, err
@ -1024,7 +1018,7 @@ func (r *ChannelRouter) FindRoutes(target *btcec.PublicKey,
// aren't able to support the total satoshis flow once fees have been // aren't able to support the total satoshis flow once fees have been
// factored in. // factored in.
validRoutes := make([]*Route, 0, len(shortestPaths)) validRoutes := make([]*Route, 0, len(shortestPaths))
sourceVertex := newVertex(r.selfNode.PubKey) sourceVertex := newVertex(selfNode.PubKey)
for _, path := range shortestPaths { for _, path := range shortestPaths {
// Attempt to make the path into a route. We snip off the first // Attempt to make the path into a route. We snip off the first
// hop in the path as it contains a "self-hop" that is inserted // hop in the path as it contains a "self-hop" that is inserted
@ -1562,7 +1556,11 @@ func (r *ChannelRouter) ForEachNode(cb func(*channeldb.LightningNode) error) err
func (r *ChannelRouter) ForAllOutgoingChannels(cb func(*channeldb.ChannelEdgeInfo, func (r *ChannelRouter) ForAllOutgoingChannels(cb func(*channeldb.ChannelEdgeInfo,
*channeldb.ChannelEdgePolicy) error) error { *channeldb.ChannelEdgePolicy) error) error {
return r.selfNode.ForEachChannel(nil, func(_ *bolt.Tx, c *channeldb.ChannelEdgeInfo, selfNode, err := r.cfg.Graph.SourceNode()
if err != nil {
return err
}
return selfNode.ForEachChannel(nil, func(_ *bolt.Tx, c *channeldb.ChannelEdgeInfo,
e, _ *channeldb.ChannelEdgePolicy) error { e, _ *channeldb.ChannelEdgePolicy) error {
return cb(c, e) return cb(c, e)