Skip to content

Commit

Permalink
blindedpath: modify all the tests calling BuildBlindedPaymentPaths to…
Browse files Browse the repository at this point in the history
… use MaxNumPaths

MaxNumPaths restriction moved from FindBlindedPaths to BuildBlindedPaymentPaths
this way we have to fill the MaxNumPaths parameter.
  • Loading branch information
MPins committed Jan 20, 2025
1 parent 717743c commit c1251d7
Showing 1 changed file with 54 additions and 12 deletions.
66 changes: 54 additions & 12 deletions routing/blindedpath/blinded_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,35 +547,58 @@ func genBlindedRouteData(rand *rand.Rand) *record.BlindedRouteData {
// an example mentioned in this spec document:
// https://github.com/lightning/bolts/blob/master/proposals/route-blinding.md
// This example does not use any dummy hops.
// Added Dave to test MaxNumPaths restriction.
func TestBuildBlindedPath(t *testing.T) {
// Alice chooses the following path to herself for blinded path
// construction:
// Carol -> Bob -> Alice.
// Carol
// |
// -> Bob -> Alice.
// |
// Dave
// Let's construct the corresponding route.Route for this which will be
// returned from the `FindRoutes` config callback.
var (
privC, pkC = btcec.PrivKeyFromBytes([]byte{1})
privB, pkB = btcec.PrivKeyFromBytes([]byte{2})
privA, pkA = btcec.PrivKeyFromBytes([]byte{3})
_, pkD = btcec.PrivKeyFromBytes([]byte{4})

carol = route.NewVertex(pkC)
bob = route.NewVertex(pkB)
alice = route.NewVertex(pkA)
dave = route.NewVertex(pkD)

chanCB = uint64(1)
chanBA = uint64(2)
chanDB = uint64(3)
)

realRoute := &route.Route{
SourcePubKey: carol,
Hops: []*route.Hop{
{
PubKeyBytes: bob,
ChannelID: chanCB,
realRoute := []*route.Route{
{
SourcePubKey: carol,
Hops: []*route.Hop{
{
PubKeyBytes: bob,
ChannelID: chanCB,
},
{
PubKeyBytes: alice,
ChannelID: chanBA,
},
},
{
PubKeyBytes: alice,
ChannelID: chanBA,
},
{
SourcePubKey: dave,
Hops: []*route.Hop{
{
PubKeyBytes: bob,
ChannelID: chanDB,
},
{
PubKeyBytes: alice,
ChannelID: chanBA,
},
},
},
}
Expand All @@ -589,13 +612,17 @@ func TestBuildBlindedPath(t *testing.T) {
ChannelID: chanBA,
ToNode: alice,
},
chanDB: {
ChannelID: chanDB,
ToNode: bob,
},
}

paths, err := BuildBlindedPaymentPaths(&BuildBlindedPathCfg{
BlindedPathCfg := (&BuildBlindedPathCfg{
FindRoutes: func(_ lnwire.MilliSatoshi) ([]*route.Route,
error) {

return []*route.Route{realRoute}, nil
return realRoute, nil
},
FetchChannelEdgesByID: func(chanID uint64) (
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
Expand Down Expand Up @@ -623,7 +650,19 @@ func TestBuildBlindedPath(t *testing.T) {
ValueMsat: 1000,
MinFinalCLTVExpiryDelta: 12,
BlocksUntilExpiry: 200,
MaxNumPaths: 2,
})

// Two blinded payment paths expected
paths, err := BuildBlindedPaymentPaths(BlindedPathCfg)
require.NoError(t, err)
require.Len(t, paths, 2)

// Update only the MaxNumPaths
BlindedPathCfg.MaxNumPaths = 1

// Build blinded payment paths with the updated configuration
paths, err = BuildBlindedPaymentPaths(BlindedPathCfg)
require.NoError(t, err)
require.Len(t, paths, 1)

Expand Down Expand Up @@ -809,6 +848,7 @@ func TestBuildBlindedPathWithDummyHops(t *testing.T) {
MinHTLCMsat: 1000,
MaxHTLCMsat: lnwire.MaxMilliSatoshi,
},
MaxNumPaths: 1,
})
require.NoError(t, err)
require.Len(t, paths, 1)
Expand Down Expand Up @@ -988,6 +1028,7 @@ func TestBuildBlindedPathWithDummyHops(t *testing.T) {
MinHTLCMsat: 1000,
MaxHTLCMsat: lnwire.MaxMilliSatoshi,
},
MaxNumPaths: 1,
})
require.NoError(t, err)
require.Len(t, paths, 1)
Expand Down Expand Up @@ -1022,6 +1063,7 @@ func TestSingleHopBlindedPath(t *testing.T) {
ValueMsat: 1000,
MinFinalCLTVExpiryDelta: 12,
BlocksUntilExpiry: 200,
MaxNumPaths: 1,
})
require.NoError(t, err)
require.Len(t, paths, 1)
Expand Down

0 comments on commit c1251d7

Please sign in to comment.