@@ -538,6 +538,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
538
538
539
539
aliasMap := make (map [string ]route.Vertex )
540
540
privKeyMap := make (map [string ]* btcec.PrivateKey )
541
+ channelIDs := make (map [route.Vertex ]map [route.Vertex ]uint64 )
541
542
542
543
nodeIndex := byte (0 )
543
544
addNodeWithAlias := func (alias string , features * lnwire.FeatureVector ) (
@@ -652,6 +653,16 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
652
653
node1Vertex , node2Vertex = node2Vertex , node1Vertex
653
654
}
654
655
656
+ if _ , ok := channelIDs [node1Vertex ]; ! ok {
657
+ channelIDs [node1Vertex ] = map [route.Vertex ]uint64 {}
658
+ }
659
+ channelIDs [node1Vertex ][node2Vertex ] = channelID
660
+
661
+ if _ , ok := channelIDs [node2Vertex ]; ! ok {
662
+ channelIDs [node2Vertex ] = map [route.Vertex ]uint64 {}
663
+ }
664
+ channelIDs [node2Vertex ][node1Vertex ] = channelID
665
+
655
666
// We first insert the existence of the edge between the two
656
667
// nodes.
657
668
edgeInfo := models.ChannelEdgeInfo {
@@ -765,6 +776,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
765
776
mcBackend : graphBackend ,
766
777
aliasMap : aliasMap ,
767
778
privKeyMap : privKeyMap ,
779
+ channelIDs : channelIDs ,
768
780
links : links ,
769
781
}, nil
770
782
}
@@ -3192,6 +3204,16 @@ func newPathFindingTestContext(t *testing.T, useCache bool,
3192
3204
return ctx
3193
3205
}
3194
3206
3207
+ func (c * pathFindingTestContext ) nodePairChannel (alias1 , alias2 string ) uint64 {
3208
+ node1 := c .keyFromAlias (alias1 )
3209
+ node2 := c .keyFromAlias (alias2 )
3210
+
3211
+ channel , ok := c .testGraphInstance .channelIDs [node1 ][node2 ]
3212
+ require .True (c .t , ok )
3213
+
3214
+ return channel
3215
+ }
3216
+
3195
3217
func (c * pathFindingTestContext ) keyFromAlias (alias string ) route.Vertex {
3196
3218
return c .testGraphInstance .aliasMap [alias ]
3197
3219
}
@@ -3914,9 +3936,11 @@ func TestFindBlindedPaths(t *testing.T) {
3914
3936
// with one hop other than the destination hop. Now with bob-dave as the
3915
3937
// incoming channel.
3916
3938
paths , err = ctx .findBlindedPaths (& blindedPathRestrictions {
3917
- minNumHops : 1 ,
3918
- maxNumHops : 1 ,
3919
- incomingChainedChannels : []uint64 {2 },
3939
+ minNumHops : 1 ,
3940
+ maxNumHops : 1 ,
3941
+ incomingChainedChannels : []uint64 {
3942
+ ctx .nodePairChannel ("bob" , "dave" ),
3943
+ },
3920
3944
})
3921
3945
require .NoError (t , err )
3922
3946
@@ -3928,9 +3952,11 @@ func TestFindBlindedPaths(t *testing.T) {
3928
3952
// 8) Extend the search to include 2 hops other than the destination,
3929
3953
// with bob-dave as the incoming channel.
3930
3954
paths , err = ctx .findBlindedPaths (& blindedPathRestrictions {
3931
- minNumHops : 1 ,
3932
- maxNumHops : 2 ,
3933
- incomingChainedChannels : []uint64 {2 },
3955
+ minNumHops : 1 ,
3956
+ maxNumHops : 2 ,
3957
+ incomingChainedChannels : []uint64 {
3958
+ ctx .nodePairChannel ("bob" , "dave" ),
3959
+ },
3934
3960
})
3935
3961
require .NoError (t , err )
3936
3962
@@ -3945,9 +3971,11 @@ func TestFindBlindedPaths(t *testing.T) {
3945
3971
// 9) Extend the search even further and also increase the minimum path
3946
3972
// length, but this time with charlie-dave as the incoming channel.
3947
3973
paths , err = ctx .findBlindedPaths (& blindedPathRestrictions {
3948
- minNumHops : 2 ,
3949
- maxNumHops : 3 ,
3950
- incomingChainedChannels : []uint64 {3 },
3974
+ minNumHops : 2 ,
3975
+ maxNumHops : 3 ,
3976
+ incomingChainedChannels : []uint64 {
3977
+ ctx .nodePairChannel ("charlie" , "dave" ),
3978
+ },
3951
3979
})
3952
3980
require .NoError (t , err )
3953
3981
@@ -3962,19 +3990,27 @@ func TestFindBlindedPaths(t *testing.T) {
3962
3990
// 10) Repeat the above test but instruct the function to never use
3963
3991
// charlie.
3964
3992
_ , err = ctx .findBlindedPaths (& blindedPathRestrictions {
3965
- minNumHops : 2 ,
3966
- maxNumHops : 3 ,
3967
- nodeOmissionSet : fn .NewSet (ctx .keyFromAlias ("charlie" )),
3968
- incomingChainedChannels : []uint64 {3 },
3993
+ minNumHops : 2 ,
3994
+ maxNumHops : 3 ,
3995
+ nodeOmissionSet : fn .NewSet (ctx .keyFromAlias ("charlie" )),
3996
+ incomingChainedChannels : []uint64 {
3997
+ ctx .nodePairChannel ("charlie" , "dave" ),
3998
+ },
3969
3999
})
3970
4000
require .ErrorContains (t , err , "cannot simultaneously be included in " +
3971
4001
"the omission set and in the partially specified path" )
3972
4002
3973
- // 11) Test the circular route error.
4003
+ // 11) Assert that an error is returned if a user accidentally tries
4004
+ // to force a circular path.
3974
4005
_ , err = ctx .findBlindedPaths (& blindedPathRestrictions {
3975
- minNumHops : 2 ,
3976
- maxNumHops : 3 ,
3977
- incomingChainedChannels : []uint64 {2 , 7 , 6 , 3 },
4006
+ minNumHops : 2 ,
4007
+ maxNumHops : 3 ,
4008
+ incomingChainedChannels : []uint64 {
4009
+ ctx .nodePairChannel ("dave" , "alice" ),
4010
+ ctx .nodePairChannel ("alice" , "frank" ),
4011
+ ctx .nodePairChannel ("frank" , "bob" ),
4012
+ ctx .nodePairChannel ("bob" , "dave" ),
4013
+ },
3978
4014
})
3979
- require .ErrorContains (t , err , "a circular route cannot be specified " )
4015
+ require .ErrorContains (t , err , "circular route" )
3980
4016
}
0 commit comments