routing: let SelfNode be passed via config
Instead of querying it from the graph since this will be removed in a future commit.
This commit is contained in:
4 files changed
+28
-41
No files matched your search
+11
-18
@@ -319,6 +319,10 @@ type ChannelPolicy struct {
|
||||
// the configuration MUST be non-nil for the ChannelRouter to carry out its
|
||||
// duties.
|
||||
type Config struct {
|
||||
// SelfNode is the public key of the node that this channel router
|
||||
// belongs to.
|
||||
SelfNode route.Vertex
|
||||
|
||||
// RoutingGraph is a graph source that will be used for pathfinding.
|
||||
RoutingGraph Graph
|
||||
|
||||
@@ -451,11 +455,6 @@ type ChannelRouter struct {
|
||||
// initialized with.
|
||||
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
|
||||
|
||||
// newBlocks is a channel in which new blocks connected to the end of
|
||||
// the main chain are sent over, and blocks updated after a call to
|
||||
// UpdateFilter.
|
||||
@@ -508,18 +507,12 @@ var _ ChannelGraphSource = (*ChannelRouter)(nil)
|
||||
// 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.
|
||||
func New(cfg Config) (*ChannelRouter, error) {
|
||||
selfNode, err := cfg.Graph.SourceNode()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r := &ChannelRouter{
|
||||
cfg: &cfg,
|
||||
networkUpdates: make(chan *routingMsg),
|
||||
topologyClients: &lnutils.SyncMap[uint64, *topologyClient]{},
|
||||
ntfnClientUpdates: make(chan *topologyClientUpdate),
|
||||
channelEdgeMtx: multimutex.NewMutex[uint64](),
|
||||
selfNode: selfNode,
|
||||
statTicker: ticker.New(defaultStatInterval),
|
||||
stats: new(routerStats),
|
||||
quit: make(chan struct{}),
|
||||
@@ -968,8 +961,8 @@ func (r *ChannelRouter) pruneZombieChans() error {
|
||||
|
||||
// A helper method to detect if the channel belongs to this node
|
||||
isSelfChannelEdge := func(info *models.ChannelEdgeInfo) bool {
|
||||
return info.NodeKey1Bytes == r.selfNode.PubKeyBytes ||
|
||||
info.NodeKey2Bytes == r.selfNode.PubKeyBytes
|
||||
return info.NodeKey1Bytes == r.cfg.SelfNode ||
|
||||
info.NodeKey2Bytes == r.cfg.SelfNode
|
||||
}
|
||||
|
||||
// First, we'll collect all the channels which are eligible for garbage
|
||||
@@ -2114,7 +2107,7 @@ func (r *ChannelRouter) FindRoute(req *RouteRequest) (*route.Route, float64,
|
||||
// We'll attempt to obtain a set of bandwidth hints that can help us
|
||||
// eliminate certain routes early on in the path finding process.
|
||||
bandwidthHints, err := newBandwidthManager(
|
||||
r.cfg.RoutingGraph, r.selfNode.PubKeyBytes, r.cfg.GetLink,
|
||||
r.cfg.RoutingGraph, r.cfg.SelfNode, r.cfg.GetLink,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
@@ -2144,7 +2137,7 @@ func (r *ChannelRouter) FindRoute(req *RouteRequest) (*route.Route, float64,
|
||||
graph: r.cfg.RoutingGraph,
|
||||
},
|
||||
req.Restrictions, &r.cfg.PathFindingConfig,
|
||||
r.selfNode.PubKeyBytes, req.Source, req.Target, req.Amount,
|
||||
r.cfg.SelfNode, req.Source, req.Target, req.Amount,
|
||||
req.TimePreference, finalHtlcExpiry,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -2944,7 +2937,7 @@ func (r *ChannelRouter) ForEachNode(
|
||||
func (r *ChannelRouter) ForAllOutgoingChannels(cb func(kvdb.RTx,
|
||||
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy) error) error {
|
||||
|
||||
return r.cfg.Graph.ForEachNodeChannel(nil, r.selfNode.PubKeyBytes,
|
||||
return r.cfg.Graph.ForEachNodeChannel(nil, r.cfg.SelfNode,
|
||||
func(tx kvdb.RTx, c *models.ChannelEdgeInfo,
|
||||
e *models.ChannelEdgePolicy,
|
||||
_ *models.ChannelEdgePolicy) error {
|
||||
@@ -3127,7 +3120,7 @@ func (r *ChannelRouter) BuildRoute(amt *lnwire.MilliSatoshi,
|
||||
// We'll attempt to obtain a set of bandwidth hints that helps us select
|
||||
// the best outgoing channel to use in case no outgoing channel is set.
|
||||
bandwidthHints, err := newBandwidthManager(
|
||||
r.cfg.RoutingGraph, r.selfNode.PubKeyBytes, r.cfg.GetLink,
|
||||
r.cfg.RoutingGraph, r.cfg.SelfNode, r.cfg.GetLink,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -3140,7 +3133,7 @@ func (r *ChannelRouter) BuildRoute(amt *lnwire.MilliSatoshi,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sourceNode := r.selfNode.PubKeyBytes
|
||||
sourceNode := r.cfg.SelfNode
|
||||
unifiers, senderAmt, err := getRouteUnifiers(
|
||||
sourceNode, hops, useMinAmt, runningAmt, outgoingChans,
|
||||
r.cfg.RoutingGraph, bandwidthHints,
|
||||
|
||||
Reference in new issue
Block a user