@@ -24,6 +24,7 @@ import (
2424 "github.com/lightningnetwork/lnd/channeldb"
2525 "github.com/lightningnetwork/lnd/channeldb/models"
2626 "github.com/lightningnetwork/lnd/clock"
27+ "github.com/lightningnetwork/lnd/fn"
2728 "github.com/lightningnetwork/lnd/graph"
2829 "github.com/lightningnetwork/lnd/htlcswitch"
2930 "github.com/lightningnetwork/lnd/input"
@@ -1641,14 +1642,16 @@ func TestBuildRoute(t *testing.T) {
16411642 _ , err = rand .Read (payAddr [:])
16421643 require .NoError (t , err )
16431644
1645+ noAmt := fn .None [lnwire.MilliSatoshi ]()
1646+
16441647 // Test that we can't build a route when no hops are given.
16451648 hops = []route.Vertex {}
1646- _ , err = ctx .router .BuildRoute (nil , hops , nil , 40 , nil )
1649+ _ , err = ctx .router .BuildRoute (noAmt , hops , nil , 40 , nil )
16471650 require .Error (t , err )
16481651
16491652 // Create hop list for an unknown destination.
16501653 hops := []route.Vertex {ctx .aliases ["b" ], ctx .aliases ["y" ]}
1651- _ , err = ctx .router .BuildRoute (nil , hops , nil , 40 , & payAddr )
1654+ _ , err = ctx .router .BuildRoute (noAmt , hops , nil , 40 , & payAddr )
16521655 noChanErr := ErrNoChannel {}
16531656 require .ErrorAs (t , err , & noChanErr )
16541657 require .Equal (t , 1 , noChanErr .position )
@@ -1658,7 +1661,7 @@ func TestBuildRoute(t *testing.T) {
16581661 amt := lnwire .NewMSatFromSatoshis (100 )
16591662
16601663 // Build the route for the given amount.
1661- rt , err := ctx .router .BuildRoute (& amt , hops , nil , 40 , & payAddr )
1664+ rt , err := ctx .router .BuildRoute (fn . Some ( amt ) , hops , nil , 40 , & payAddr )
16621665 require .NoError (t , err )
16631666
16641667 // Check that we get the expected route back. The total amount should be
@@ -1668,7 +1671,7 @@ func TestBuildRoute(t *testing.T) {
16681671 require .Equal (t , lnwire .MilliSatoshi (106000 ), rt .TotalAmount )
16691672
16701673 // Build the route for the minimum amount.
1671- rt , err = ctx .router .BuildRoute (nil , hops , nil , 40 , & payAddr )
1674+ rt , err = ctx .router .BuildRoute (noAmt , hops , nil , 40 , & payAddr )
16721675 require .NoError (t , err )
16731676
16741677 // Check that we get the expected route back. The minimum that we can
@@ -1684,7 +1687,7 @@ func TestBuildRoute(t *testing.T) {
16841687 // Test a route that contains incompatible channel htlc constraints.
16851688 // There is no amount that can pass through both channel 5 and 4.
16861689 hops = []route.Vertex {ctx .aliases ["e" ], ctx .aliases ["c" ]}
1687- _ , err = ctx .router .BuildRoute (nil , hops , nil , 40 , nil )
1690+ _ , err = ctx .router .BuildRoute (noAmt , hops , nil , 40 , nil )
16881691 require .Error (t , err )
16891692 noChanErr = ErrNoChannel {}
16901693 require .ErrorAs (t , err , & noChanErr )
@@ -1702,7 +1705,7 @@ func TestBuildRoute(t *testing.T) {
17021705 // amount that could be delivered to the receiver of 21819 msat, using
17031706 // policy of channel 3.
17041707 hops = []route.Vertex {ctx .aliases ["b" ], ctx .aliases ["z" ]}
1705- rt , err = ctx .router .BuildRoute (nil , hops , nil , 40 , & payAddr )
1708+ rt , err = ctx .router .BuildRoute (noAmt , hops , nil , 40 , & payAddr )
17061709 require .NoError (t , err )
17071710 checkHops (rt , []uint64 {1 , 8 }, payAddr )
17081711 require .Equal (t , lnwire .MilliSatoshi (21200 ), rt .TotalAmount )
@@ -1714,7 +1717,7 @@ func TestBuildRoute(t *testing.T) {
17141717 // We get 106000 - 1000 (base in) - 0.001 * 106000 (rate in) = 104894.
17151718 hops = []route.Vertex {ctx .aliases ["d" ], ctx .aliases ["f" ]}
17161719 amt = lnwire .NewMSatFromSatoshis (100 )
1717- rt , err = ctx .router .BuildRoute (& amt , hops , nil , 40 , & payAddr )
1720+ rt , err = ctx .router .BuildRoute (fn . Some ( amt ) , hops , nil , 40 , & payAddr )
17181721 require .NoError (t , err )
17191722 checkHops (rt , []uint64 {9 , 10 }, payAddr )
17201723 require .EqualValues (t , 104894 , rt .TotalAmount )
@@ -1728,7 +1731,7 @@ func TestBuildRoute(t *testing.T) {
17281731 // of 20179 msat, which results in underpayment of 1 msat in fee. There
17291732 // is a third pass through newRoute in which this gets corrected to end
17301733 hops = []route.Vertex {ctx .aliases ["d" ], ctx .aliases ["f" ]}
1731- rt , err = ctx .router .BuildRoute (nil , hops , nil , 40 , & payAddr )
1734+ rt , err = ctx .router .BuildRoute (noAmt , hops , nil , 40 , & payAddr )
17321735 require .NoError (t , err )
17331736 checkHops (rt , []uint64 {9 , 10 }, payAddr )
17341737 require .EqualValues (t , 20180 , rt .TotalAmount , "%v" , rt .TotalAmount )
@@ -1919,20 +1922,20 @@ func TestSenderAmtBackwardPass(t *testing.T) {
19191922 // A search for an amount that is below the minimum HTLC amount should
19201923 // fail.
19211924 _ , _ , err := senderAmtBackwardPass (
1922- edgeUnifiers , false , minHTLC - 1 , & bandwidthHints ,
1925+ edgeUnifiers , fn . Some ( minHTLC - 1 ) , & bandwidthHints ,
19231926 )
19241927 require .Error (t , err )
19251928
19261929 // Do a min amount search.
1927- unifiedEdges , senderAmount , err := senderAmtBackwardPass (
1928- edgeUnifiers , true , 1 , & bandwidthHints ,
1930+ _ , senderAmount , err := senderAmtBackwardPass (
1931+ edgeUnifiers , fn . None [lnwire. MilliSatoshi ]() , & bandwidthHints ,
19291932 )
19301933 require .NoError (t , err )
19311934 require .Equal (t , minHTLC + 333 + 222 + 222 + 111 , senderAmount )
19321935
19331936 // Do a search for a specific amount.
1934- unifiedEdges , senderAmount , err = senderAmtBackwardPass (
1935- edgeUnifiers , false , testReceiverAmt , & bandwidthHints ,
1937+ unifiedEdges , senderAmount , err : = senderAmtBackwardPass (
1938+ edgeUnifiers , fn . Some ( testReceiverAmt ) , & bandwidthHints ,
19361939 )
19371940 require .NoError (t , err )
19381941 require .Equal (t , testReceiverAmt + 333 + 222 + 222 + 111 , senderAmount )
@@ -1961,7 +1964,7 @@ func TestSenderAmtBackwardPass(t *testing.T) {
19611964 }
19621965
19631966 unifiedEdges , senderAmount , err = senderAmtBackwardPass (
1964- edgeUnifiers , false , testReceiverAmt , & bandwidthHints ,
1967+ edgeUnifiers , fn . Some ( testReceiverAmt ) , & bandwidthHints ,
19651968 )
19661969 require .NoError (t , err )
19671970
0 commit comments