mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 05:45:21 +01:00
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:
parent
8c0df98439
commit
cf3de72503
@ -2227,18 +2227,13 @@ func TestPathFindSpecExample(t *testing.T) {
|
||||
// Carol, so we set "B" as the source node so path finding starts from
|
||||
// Bob.
|
||||
bob := ctx.aliases["B"]
|
||||
bobNode, err := ctx.graph.FetchLightningNode(nil, bob)
|
||||
require.NoError(t, err, "unable to find bob")
|
||||
if err := ctx.graph.SetSourceNode(bobNode); err != nil {
|
||||
t.Fatalf("unable to set source node: %v", err)
|
||||
}
|
||||
|
||||
// Query for a route of 4,999,999 mSAT to carol.
|
||||
carol := ctx.aliases["C"]
|
||||
const amt lnwire.MilliSatoshi = 4999999
|
||||
req, err := NewRouteRequest(
|
||||
bobNode.PubKeyBytes, &carol, amt, 0, noRestrictions, nil, nil,
|
||||
nil, MinCLTVDelta,
|
||||
bob, &carol, amt, 0, noRestrictions, nil, nil, nil,
|
||||
MinCLTVDelta,
|
||||
)
|
||||
require.NoError(t, err, "invalid route request")
|
||||
|
||||
@ -2276,22 +2271,11 @@ func TestPathFindSpecExample(t *testing.T) {
|
||||
// Next, we'll set A as the source node so we can assert that we create
|
||||
// the proper route for any queries starting with Alice.
|
||||
alice := ctx.aliases["A"]
|
||||
aliceNode, err := ctx.graph.FetchLightningNode(nil, alice)
|
||||
require.NoError(t, err, "unable to find alice")
|
||||
if err := ctx.graph.SetSourceNode(aliceNode); err != nil {
|
||||
t.Fatalf("unable to set source node: %v", err)
|
||||
}
|
||||
ctx.router.selfNode = aliceNode
|
||||
source, err := ctx.graph.SourceNode()
|
||||
require.NoError(t, err, "unable to retrieve source node")
|
||||
if source.PubKeyBytes != alice {
|
||||
t.Fatalf("source node not set")
|
||||
}
|
||||
|
||||
// We'll now request a route from A -> B -> C.
|
||||
req, err = NewRouteRequest(
|
||||
source.PubKeyBytes, &carol, amt, 0, noRestrictions, nil, nil,
|
||||
nil, MinCLTVDelta,
|
||||
alice, &carol, amt, 0, noRestrictions, nil, nil, nil,
|
||||
MinCLTVDelta,
|
||||
)
|
||||
require.NoError(t, err, "invalid route request")
|
||||
|
||||
|
@ -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,
|
||||
|
@ -74,9 +74,13 @@ func (c *testCtx) RestartRouter(t *testing.T) {
|
||||
// filter between restarts.
|
||||
c.chainView.Reset()
|
||||
|
||||
source, err := c.graph.SourceNode()
|
||||
require.NoError(t, err)
|
||||
|
||||
// With the chainView reset, we'll now re-create the router itself, and
|
||||
// start it.
|
||||
router, err := New(Config{
|
||||
SelfNode: source.PubKeyBytes,
|
||||
RoutingGraph: newMockGraphSessionChanDB(c.graph),
|
||||
Graph: c.graph,
|
||||
Chain: c.chain,
|
||||
@ -157,6 +161,7 @@ func createTestCtxFromGraphInstanceAssumeValid(t *testing.T,
|
||||
}
|
||||
|
||||
router, err := New(Config{
|
||||
SelfNode: sourceNode.PubKeyBytes,
|
||||
RoutingGraph: newMockGraphSessionChanDB(graphInstance.graph),
|
||||
Graph: graphInstance.graph,
|
||||
Chain: chain,
|
||||
@ -278,7 +283,7 @@ func TestFindRoutesWithFeeLimit(t *testing.T) {
|
||||
}
|
||||
|
||||
req, err := NewRouteRequest(
|
||||
ctx.router.selfNode.PubKeyBytes, &target, paymentAmt, 0,
|
||||
ctx.router.cfg.SelfNode, &target, paymentAmt, 0,
|
||||
restrictions, nil, nil, nil, MinCLTVDelta,
|
||||
)
|
||||
require.NoError(t, err, "invalid route request")
|
||||
@ -1541,7 +1546,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
|
||||
copy(targetPubKeyBytes[:], targetNode.SerializeCompressed())
|
||||
|
||||
req, err := NewRouteRequest(
|
||||
ctx.router.selfNode.PubKeyBytes, &targetPubKeyBytes,
|
||||
ctx.router.cfg.SelfNode, &targetPubKeyBytes,
|
||||
paymentAmt, 0, noRestrictions, nil, nil, nil, MinCLTVDelta,
|
||||
)
|
||||
require.NoError(t, err, "invalid route request")
|
||||
@ -1583,7 +1588,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
|
||||
// Should still be able to find the route, and the info should be
|
||||
// updated.
|
||||
req, err = NewRouteRequest(
|
||||
ctx.router.selfNode.PubKeyBytes, &targetPubKeyBytes,
|
||||
ctx.router.cfg.SelfNode, &targetPubKeyBytes,
|
||||
paymentAmt, 0, noRestrictions, nil, nil, nil, MinCLTVDelta,
|
||||
)
|
||||
require.NoError(t, err, "invalid route request")
|
||||
@ -1765,8 +1770,12 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
|
||||
// Give time to process new blocks.
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
|
||||
source, err := ctx.graph.SourceNode()
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create new router with same graph database.
|
||||
router, err := New(Config{
|
||||
SelfNode: source.PubKeyBytes,
|
||||
RoutingGraph: newMockGraphSessionChanDB(ctx.graph),
|
||||
Graph: ctx.graph,
|
||||
Chain: ctx.chain,
|
||||
|
Loading…
Reference in New Issue
Block a user