routing: restore in memory selfNode within the ChannelRouter
In this commit we restore the in memory ChannelRouter as we’ll no dynamically set the ChannelRouter’s pointer within he spec path finding test example.
This commit is contained in:
parent
76ec41103e
commit
25614f67f8
@ -718,6 +718,7 @@ func TestPathFindSpecExample(t *testing.T) {
|
|||||||
if err := ctx.graph.SetSourceNode(aliceNode); err != nil {
|
if err := ctx.graph.SetSourceNode(aliceNode); err != nil {
|
||||||
t.Fatalf("unable to set source node: %v", err)
|
t.Fatalf("unable to set source node: %v", err)
|
||||||
}
|
}
|
||||||
|
ctx.router.selfNode = aliceNode
|
||||||
source, err := ctx.graph.SourceNode()
|
source, err := ctx.graph.SourceNode()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to retrieve source node: %v", err)
|
t.Fatalf("unable to retrieve source node: %v", err)
|
||||||
|
@ -168,6 +168,11 @@ 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
|
||||||
@ -225,12 +230,18 @@ var _ ChannelGraphSource = (*ChannelRouter)(nil)
|
|||||||
// 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,
|
||||||
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),
|
||||||
missionControl: newMissionControl(cfg.Graph, selfNode),
|
missionControl: newMissionControl(cfg.Graph, selfNode),
|
||||||
|
selfNode: selfNode,
|
||||||
routeCache: make(map[routeTuple][]*Route),
|
routeCache: make(map[routeTuple][]*Route),
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
}, nil
|
}, nil
|
||||||
@ -1009,15 +1020,11 @@ 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, selfNode, target, amt)
|
shortestPaths, err := findPaths(tx, r.cfg.Graph, r.selfNode, target,
|
||||||
|
amt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -1031,7 +1038,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(selfNode.PubKey)
|
sourceVertex := newVertex(r.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
|
||||||
@ -1583,11 +1590,7 @@ 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 {
|
||||||
|
|
||||||
selfNode, err := r.cfg.Graph.SourceNode()
|
return r.selfNode.ForEachChannel(nil, func(_ *bolt.Tx, c *channeldb.ChannelEdgeInfo,
|
||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user