@@ -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