Skip to content

Commit b490dee

Browse files
committed
routing/blindedpath: dont error out unless all paths fail
In this commit, we adjust BuildBlindedPaymentPaths to only error out completely if none of the paths it received from FindRoutes resulted in a usable blinded path.
1 parent 3de6c54 commit b490dee

File tree

2 files changed

+73
-3
lines changed

2 files changed

+73
-3
lines changed

routing/blindedpath/blinded_path.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,11 @@ func BuildBlindedPaymentPaths(cfg *BuildBlindedPathCfg) (
141141
route)
142142

143143
continue
144-
}
144+
} else if err != nil {
145+
log.Errorf("Not using route (%s) as a blinded path: %v",
146+
err)
145147

146-
if err != nil {
147-
return nil, err
148+
continue
148149
}
149150

150151
paths = append(paths, path)

routing/blindedpath/blinded_path_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,75 @@ func TestBuildBlindedPathWithDummyHops(t *testing.T) {
922922
HtlcMinimumMsat: 1000,
923923
}, data.Constraints.UnwrapOrFail(t).Val)
924924
require.Equal(t, []byte{1, 2, 3}, data.PathID.UnwrapOrFail(t).Val)
925+
926+
// Demonstrate that BuildBlindedPaymentPaths continues to use any
927+
// functioning paths even if some routes cant be used to build a blinded
928+
// path. We do this by forcing FetchChannelEdgesByID to error out for
929+
// the first 2 calls. FindRoutes returns 3 routes and so by the end, we
930+
// still get 1 valid path.
931+
var errCount int
932+
paths, err = BuildBlindedPaymentPaths(&BuildBlindedPathCfg{
933+
FindRoutes: func(_ lnwire.MilliSatoshi) ([]*route.Route,
934+
error) {
935+
936+
return []*route.Route{realRoute, realRoute, realRoute},
937+
nil
938+
},
939+
FetchChannelEdgesByID: func(chanID uint64) (
940+
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
941+
*models.ChannelEdgePolicy, error) {
942+
943+
// Force the call to error for the first 2 channels.
944+
if errCount < 2 {
945+
errCount++
946+
947+
return nil, nil, nil,
948+
fmt.Errorf("edge not found")
949+
}
950+
951+
policy, ok := realPolicies[chanID]
952+
if !ok {
953+
return nil, nil, nil,
954+
fmt.Errorf("edge not found")
955+
}
956+
957+
return nil, policy, nil, nil
958+
},
959+
BestHeight: func() (uint32, error) {
960+
return 1000, nil
961+
},
962+
// In the spec example, all the policies get replaced with
963+
// the same static values.
964+
AddPolicyBuffer: func(_ *BlindedHopPolicy) (
965+
*BlindedHopPolicy, error) {
966+
967+
return &BlindedHopPolicy{
968+
FeeRate: 500,
969+
BaseFee: 100,
970+
CLTVExpiryDelta: 144,
971+
MinHTLCMsat: 1000,
972+
MaxHTLCMsat: lnwire.MaxMilliSatoshi,
973+
}, nil
974+
},
975+
PathID: []byte{1, 2, 3},
976+
ValueMsat: 1000,
977+
MinFinalCLTVExpiryDelta: 12,
978+
BlocksUntilExpiry: 200,
979+
980+
// By setting the minimum number of hops to 4, we force 2 dummy
981+
// hops to be added to the real route.
982+
MinNumHops: 4,
983+
984+
DefaultDummyHopPolicy: &BlindedHopPolicy{
985+
CLTVExpiryDelta: 50,
986+
FeeRate: 100,
987+
BaseFee: 100,
988+
MinHTLCMsat: 1000,
989+
MaxHTLCMsat: lnwire.MaxMilliSatoshi,
990+
},
991+
})
992+
require.NoError(t, err)
993+
require.Len(t, paths, 1)
925994
}
926995

927996
// TestSingleHopBlindedPath tests that blinded path construction is done

0 commit comments

Comments
 (0)