mirror of
https://github.com/aljazceru/breez-lnd.git
synced 2025-12-18 14:44:22 +01:00
routing: FindRoute is now FindRoutes, uses our KSP algo, ranks by fee
This commit modifies the existing FindRoute method on the ChannelRouter to now use the KSP implementation added in a prior commit. This new method FindRoutes, is able to find all the possible paths between a source and destination. The method takes all paths reported by findPaths, and attempt to turn each of them into a route. A route differs from a path in that is has complete time-lock and fee information. Some paths may not be able to be turned into routes as once fees are accounted for the have an insufficient flow. We then take the routes, sort them by total fee (with time-lock being a time-breaker), then return them in sorted order.
This commit is contained in:
@@ -107,72 +107,6 @@ func randChannelEdge(ctx *testCtx, chanValue btcutil.Amount,
|
||||
return fundingTx, chanUtxo, chanID
|
||||
}
|
||||
|
||||
type testCtx struct {
|
||||
router *ChannelRouter
|
||||
|
||||
graph *channeldb.ChannelGraph
|
||||
|
||||
chain *mockChain
|
||||
|
||||
notifier *mockNotifier
|
||||
}
|
||||
|
||||
func createTestCtx(startingHeight uint32) (*testCtx, func(), error) {
|
||||
// First we'll set up a test graph for usage within the test.
|
||||
graph, cleanup, err := makeTestGraph()
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("unable to create test graph: %v", err)
|
||||
}
|
||||
|
||||
sourceNode, err := createGraphNode()
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("unable to create source node: %v", err)
|
||||
}
|
||||
if err := graph.SetSourceNode(sourceNode); err != nil {
|
||||
return nil, nil, fmt.Errorf("unable to set source node: %v", err)
|
||||
}
|
||||
|
||||
// Next we'll initialize an instance of the channel router with mock
|
||||
// versions of the chain and channel notifier. As we don't need to test
|
||||
// any p2p functionality, the peer send and switch send messages won't
|
||||
// be populated.
|
||||
chain := newMockChain(startingHeight)
|
||||
notifier := newMockNotifier()
|
||||
router, err := New(Config{
|
||||
Graph: graph,
|
||||
Chain: chain,
|
||||
Notifier: notifier,
|
||||
Broadcast: func(_ *btcec.PublicKey, msg ...lnwire.Message) error {
|
||||
return nil
|
||||
},
|
||||
SendMessages: func(_ *btcec.PublicKey, msg ...lnwire.Message) error {
|
||||
return nil
|
||||
},
|
||||
SendToSwitch: func(_ *btcec.PublicKey,
|
||||
_ *lnwire.UpdateAddHTLC) ([32]byte, error) {
|
||||
return [32]byte{}, nil
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("unable to create router %v", err)
|
||||
}
|
||||
if err := router.Start(); err != nil {
|
||||
return nil, nil, fmt.Errorf("unable to start router: %v", err)
|
||||
}
|
||||
|
||||
cleanUp := func() {
|
||||
router.Stop()
|
||||
cleanup()
|
||||
}
|
||||
|
||||
return &testCtx{
|
||||
router: router,
|
||||
graph: graph,
|
||||
chain: chain,
|
||||
notifier: notifier,
|
||||
}, cleanUp, nil
|
||||
}
|
||||
|
||||
type mockChain struct {
|
||||
blocks map[chainhash.Hash]*wire.MsgBlock
|
||||
blockIndex map[uint32]chainhash.Hash
|
||||
|
||||
Reference in New Issue
Block a user