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
@@ -2227,18 +2227,13 @@ func TestPathFindSpecExample(t *testing.T) {
|
|||||||
// Carol, so we set "B" as the source node so path finding starts from
|
// Carol, so we set "B" as the source node so path finding starts from
|
||||||
// Bob.
|
// Bob.
|
||||||
bob := ctx.aliases["B"]
|
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.
|
// Query for a route of 4,999,999 mSAT to carol.
|
||||||
carol := ctx.aliases["C"]
|
carol := ctx.aliases["C"]
|
||||||
const amt lnwire.MilliSatoshi = 4999999
|
const amt lnwire.MilliSatoshi = 4999999
|
||||||
req, err := NewRouteRequest(
|
req, err := NewRouteRequest(
|
||||||
bobNode.PubKeyBytes, &carol, amt, 0, noRestrictions, nil, nil,
|
bob, &carol, amt, 0, noRestrictions, nil, nil, nil,
|
||||||
nil, MinCLTVDelta,
|
MinCLTVDelta,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "invalid route request")
|
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
|
// 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.
|
// the proper route for any queries starting with Alice.
|
||||||
alice := ctx.aliases["A"]
|
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.
|
// We'll now request a route from A -> B -> C.
|
||||||
req, err = NewRouteRequest(
|
req, err = NewRouteRequest(
|
||||||
source.PubKeyBytes, &carol, amt, 0, noRestrictions, nil, nil,
|
alice, &carol, amt, 0, noRestrictions, nil, nil, nil,
|
||||||
nil, MinCLTVDelta,
|
MinCLTVDelta,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "invalid route request")
|
require.NoError(t, err, "invalid route request")
|
||||||
|
|
||||||
|
|||||||
+11
-18
@@ -319,6 +319,10 @@ type ChannelPolicy struct {
|
|||||||
// the configuration MUST be non-nil for the ChannelRouter to carry out its
|
// the configuration MUST be non-nil for the ChannelRouter to carry out its
|
||||||
// duties.
|
// duties.
|
||||||
type Config struct {
|
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 is a graph source that will be used for pathfinding.
|
||||||
RoutingGraph Graph
|
RoutingGraph Graph
|
||||||
|
|
||||||
@@ -451,11 +455,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
|
|
||||||
|
|
||||||
// newBlocks is a channel in which new blocks connected to the end of
|
// 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
|
// the main chain are sent over, and blocks updated after a call to
|
||||||
// UpdateFilter.
|
// UpdateFilter.
|
||||||
@@ -508,18 +507,12 @@ 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
|
|
||||||
}
|
|
||||||
|
|
||||||
r := &ChannelRouter{
|
r := &ChannelRouter{
|
||||||
cfg: &cfg,
|
cfg: &cfg,
|
||||||
networkUpdates: make(chan *routingMsg),
|
networkUpdates: make(chan *routingMsg),
|
||||||
topologyClients: &lnutils.SyncMap[uint64, *topologyClient]{},
|
topologyClients: &lnutils.SyncMap[uint64, *topologyClient]{},
|
||||||
ntfnClientUpdates: make(chan *topologyClientUpdate),
|
ntfnClientUpdates: make(chan *topologyClientUpdate),
|
||||||
channelEdgeMtx: multimutex.NewMutex[uint64](),
|
channelEdgeMtx: multimutex.NewMutex[uint64](),
|
||||||
selfNode: selfNode,
|
|
||||||
statTicker: ticker.New(defaultStatInterval),
|
statTicker: ticker.New(defaultStatInterval),
|
||||||
stats: new(routerStats),
|
stats: new(routerStats),
|
||||||
quit: make(chan struct{}),
|
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
|
// A helper method to detect if the channel belongs to this node
|
||||||
isSelfChannelEdge := func(info *models.ChannelEdgeInfo) bool {
|
isSelfChannelEdge := func(info *models.ChannelEdgeInfo) bool {
|
||||||
return info.NodeKey1Bytes == r.selfNode.PubKeyBytes ||
|
return info.NodeKey1Bytes == r.cfg.SelfNode ||
|
||||||
info.NodeKey2Bytes == r.selfNode.PubKeyBytes
|
info.NodeKey2Bytes == r.cfg.SelfNode
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, we'll collect all the channels which are eligible for garbage
|
// 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
|
// We'll attempt to obtain a set of bandwidth hints that can help us
|
||||||
// eliminate certain routes early on in the path finding process.
|
// eliminate certain routes early on in the path finding process.
|
||||||
bandwidthHints, err := newBandwidthManager(
|
bandwidthHints, err := newBandwidthManager(
|
||||||
r.cfg.RoutingGraph, r.selfNode.PubKeyBytes, r.cfg.GetLink,
|
r.cfg.RoutingGraph, r.cfg.SelfNode, r.cfg.GetLink,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
@@ -2144,7 +2137,7 @@ func (r *ChannelRouter) FindRoute(req *RouteRequest) (*route.Route, float64,
|
|||||||
graph: r.cfg.RoutingGraph,
|
graph: r.cfg.RoutingGraph,
|
||||||
},
|
},
|
||||||
req.Restrictions, &r.cfg.PathFindingConfig,
|
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,
|
req.TimePreference, finalHtlcExpiry,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -2944,7 +2937,7 @@ func (r *ChannelRouter) ForEachNode(
|
|||||||
func (r *ChannelRouter) ForAllOutgoingChannels(cb func(kvdb.RTx,
|
func (r *ChannelRouter) ForAllOutgoingChannels(cb func(kvdb.RTx,
|
||||||
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy) error) error {
|
*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,
|
func(tx kvdb.RTx, c *models.ChannelEdgeInfo,
|
||||||
e *models.ChannelEdgePolicy,
|
e *models.ChannelEdgePolicy,
|
||||||
_ *models.ChannelEdgePolicy) error {
|
_ *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
|
// 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.
|
// the best outgoing channel to use in case no outgoing channel is set.
|
||||||
bandwidthHints, err := newBandwidthManager(
|
bandwidthHints, err := newBandwidthManager(
|
||||||
r.cfg.RoutingGraph, r.selfNode.PubKeyBytes, r.cfg.GetLink,
|
r.cfg.RoutingGraph, r.cfg.SelfNode, r.cfg.GetLink,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -3140,7 +3133,7 @@ func (r *ChannelRouter) BuildRoute(amt *lnwire.MilliSatoshi,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceNode := r.selfNode.PubKeyBytes
|
sourceNode := r.cfg.SelfNode
|
||||||
unifiers, senderAmt, err := getRouteUnifiers(
|
unifiers, senderAmt, err := getRouteUnifiers(
|
||||||
sourceNode, hops, useMinAmt, runningAmt, outgoingChans,
|
sourceNode, hops, useMinAmt, runningAmt, outgoingChans,
|
||||||
r.cfg.RoutingGraph, bandwidthHints,
|
r.cfg.RoutingGraph, bandwidthHints,
|
||||||
|
|||||||
+12
-3
@@ -74,9 +74,13 @@ func (c *testCtx) RestartRouter(t *testing.T) {
|
|||||||
// filter between restarts.
|
// filter between restarts.
|
||||||
c.chainView.Reset()
|
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
|
// With the chainView reset, we'll now re-create the router itself, and
|
||||||
// start it.
|
// start it.
|
||||||
router, err := New(Config{
|
router, err := New(Config{
|
||||||
|
SelfNode: source.PubKeyBytes,
|
||||||
RoutingGraph: newMockGraphSessionChanDB(c.graph),
|
RoutingGraph: newMockGraphSessionChanDB(c.graph),
|
||||||
Graph: c.graph,
|
Graph: c.graph,
|
||||||
Chain: c.chain,
|
Chain: c.chain,
|
||||||
@@ -157,6 +161,7 @@ func createTestCtxFromGraphInstanceAssumeValid(t *testing.T,
|
|||||||
}
|
}
|
||||||
|
|
||||||
router, err := New(Config{
|
router, err := New(Config{
|
||||||
|
SelfNode: sourceNode.PubKeyBytes,
|
||||||
RoutingGraph: newMockGraphSessionChanDB(graphInstance.graph),
|
RoutingGraph: newMockGraphSessionChanDB(graphInstance.graph),
|
||||||
Graph: graphInstance.graph,
|
Graph: graphInstance.graph,
|
||||||
Chain: chain,
|
Chain: chain,
|
||||||
@@ -278,7 +283,7 @@ func TestFindRoutesWithFeeLimit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
req, err := NewRouteRequest(
|
req, err := NewRouteRequest(
|
||||||
ctx.router.selfNode.PubKeyBytes, &target, paymentAmt, 0,
|
ctx.router.cfg.SelfNode, &target, paymentAmt, 0,
|
||||||
restrictions, nil, nil, nil, MinCLTVDelta,
|
restrictions, nil, nil, nil, MinCLTVDelta,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "invalid route request")
|
require.NoError(t, err, "invalid route request")
|
||||||
@@ -1541,7 +1546,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
|
|||||||
copy(targetPubKeyBytes[:], targetNode.SerializeCompressed())
|
copy(targetPubKeyBytes[:], targetNode.SerializeCompressed())
|
||||||
|
|
||||||
req, err := NewRouteRequest(
|
req, err := NewRouteRequest(
|
||||||
ctx.router.selfNode.PubKeyBytes, &targetPubKeyBytes,
|
ctx.router.cfg.SelfNode, &targetPubKeyBytes,
|
||||||
paymentAmt, 0, noRestrictions, nil, nil, nil, MinCLTVDelta,
|
paymentAmt, 0, noRestrictions, nil, nil, nil, MinCLTVDelta,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "invalid route request")
|
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
|
// Should still be able to find the route, and the info should be
|
||||||
// updated.
|
// updated.
|
||||||
req, err = NewRouteRequest(
|
req, err = NewRouteRequest(
|
||||||
ctx.router.selfNode.PubKeyBytes, &targetPubKeyBytes,
|
ctx.router.cfg.SelfNode, &targetPubKeyBytes,
|
||||||
paymentAmt, 0, noRestrictions, nil, nil, nil, MinCLTVDelta,
|
paymentAmt, 0, noRestrictions, nil, nil, nil, MinCLTVDelta,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "invalid route request")
|
require.NoError(t, err, "invalid route request")
|
||||||
@@ -1765,8 +1770,12 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
|
|||||||
// Give time to process new blocks.
|
// Give time to process new blocks.
|
||||||
time.Sleep(time.Millisecond * 500)
|
time.Sleep(time.Millisecond * 500)
|
||||||
|
|
||||||
|
source, err := ctx.graph.SourceNode()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Create new router with same graph database.
|
// Create new router with same graph database.
|
||||||
router, err := New(Config{
|
router, err := New(Config{
|
||||||
|
SelfNode: source.PubKeyBytes,
|
||||||
RoutingGraph: newMockGraphSessionChanDB(ctx.graph),
|
RoutingGraph: newMockGraphSessionChanDB(ctx.graph),
|
||||||
Graph: ctx.graph,
|
Graph: ctx.graph,
|
||||||
Chain: ctx.chain,
|
Chain: ctx.chain,
|
||||||
|
|||||||
@@ -974,6 +974,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
|||||||
cfg.Routing.StrictZombiePruning
|
cfg.Routing.StrictZombiePruning
|
||||||
|
|
||||||
s.chanRouter, err = routing.New(routing.Config{
|
s.chanRouter, err = routing.New(routing.Config{
|
||||||
|
SelfNode: selfNode.PubKeyBytes,
|
||||||
RoutingGraph: graphsession.NewRoutingGraph(chanGraph),
|
RoutingGraph: graphsession.NewRoutingGraph(chanGraph),
|
||||||
Graph: chanGraph,
|
Graph: chanGraph,
|
||||||
Chain: cc.ChainIO,
|
Chain: cc.ChainIO,
|
||||||
|
|||||||
Reference in new issue
Block a user