@@ -962,6 +962,170 @@ impl PaymentParameters {
962962 }
963963}
964964
965+ pub struct RouteParametersV2 {
966+ /// Parameters specified by user. Defaults to default if not provided.
967+ pub user_params : UserParameters ,
968+ // Parameters derived from the Invoice
969+ pub invoice_params : InvoiceParameters ,
970+ /// The amount in msats sent on the failed payment path.
971+ pub final_value_msat : u64 ,
972+ }
973+
974+ impl Writeable for RouteParametersV2 {
975+ fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
976+ write_tlv_fields ! ( writer, {
977+ ( 0 , self . user_params, required) ,
978+ ( 2 , self . invoice_params, required) ,
979+ ( 4 , self . final_value_msat, required) ,
980+ } ) ;
981+ Ok ( ( ) )
982+ }
983+ }
984+
985+ impl Readable for RouteParametersV2 {
986+ fn read < R : io:: Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
987+ _init_and_read_len_prefixed_tlv_fields ! ( reader, {
988+ ( 0 , user_params, required) ,
989+ ( 2 , invoice_params, ( required: ReadableArgs , 0 ) ) ,
990+ ( 4 , final_value_msat, required) ,
991+ } ) ;
992+ Ok ( Self {
993+ user_params : user_params. 0 . unwrap ( ) ,
994+ invoice_params : invoice_params. 0 . unwrap ( ) ,
995+ final_value_msat : final_value_msat. 0 . unwrap ( ) ,
996+ } )
997+ }
998+ }
999+
1000+ #[ derive( Clone , Copy ) ]
1001+ pub struct UserParameters {
1002+ /// The maximum total fees, in millisatoshi, that may accrue during route finding.
1003+ ///
1004+ /// This limit also applies to the total fees that may arise while retrying failed payment
1005+ /// paths.
1006+ ///
1007+ /// Note that values below a few sats may result in some paths being spuriously ignored.
1008+ pub max_total_routing_fee_msat : Option < u64 > ,
1009+
1010+ /// The maximum total CLTV delta we accept for the route.
1011+ /// Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
1012+ pub max_total_cltv_expiry_delta : u32 ,
1013+
1014+ /// The maximum number of paths that may be used by (MPP) payments.
1015+ /// Defaults to [`DEFAULT_MAX_PATH_COUNT`].
1016+ pub max_path_count : u8 ,
1017+
1018+ /// The maximum number of [`Path::hops`] in any returned path.
1019+ /// Defaults to [`MAX_PATH_LENGTH_ESTIMATE`].
1020+ pub max_path_length : u8 ,
1021+
1022+ /// Selects the maximum share of a channel's total capacity which will be sent over a channel,
1023+ /// as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
1024+ /// a lower value prefers to send larger MPP parts, potentially saturating channels and
1025+ /// increasing failure probability for those paths.
1026+ ///
1027+ /// Note that this restriction will be relaxed during pathfinding after paths which meet this
1028+ /// restriction have been found. While paths which meet this criteria will be searched for, it
1029+ /// is ultimately up to the scorer to select them over other paths.
1030+ ///
1031+ /// A value of 0 will allow payments up to and including a channel's total announced usable
1032+ /// capacity, a value of one will only use up to half its capacity, two 1/4, etc.
1033+ ///
1034+ /// Default value: [`DEFAULT_MAX_CHANNEL_SATURATION_POW_HALF`]
1035+ pub max_channel_saturation_power_of_half : u8 ,
1036+ }
1037+
1038+ impl_writeable_tlv_based ! ( UserParameters , {
1039+ ( 1 , max_total_routing_fee_msat, option) ,
1040+ ( 3 , max_total_cltv_expiry_delta, ( default_value, DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA ) ) ,
1041+ ( 5 , max_path_count, ( default_value, DEFAULT_MAX_PATH_COUNT ) ) ,
1042+ ( 7 , max_path_length, ( default_value, MAX_PATH_LENGTH_ESTIMATE ) ) ,
1043+ ( 9 , max_channel_saturation_power_of_half, ( default_value, DEFAULT_MAX_CHANNEL_SATURATION_POW_HALF ) )
1044+ } ) ;
1045+
1046+ pub struct InvoiceParameters {
1047+ /// Information about the payee, such as their features and route hints for their channels.
1048+ pub payee : Payee ,
1049+
1050+ /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
1051+ pub expiry_time : Option < u64 > ,
1052+
1053+ /// A list of SCIDs which this payment was previously attempted over and which caused the
1054+ /// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
1055+ /// these SCIDs.
1056+ pub previously_failed_channels : Vec < u64 > ,
1057+
1058+ /// A list of indices corresponding to blinded paths in [`Payee::Blinded::route_hints`] which this
1059+ /// payment was previously attempted over and which caused the payment to fail. Future attempts
1060+ /// for the same payment shouldn't be relayed through any of these blinded paths.
1061+ pub previously_failed_blinded_path_idxs : Vec < u64 > ,
1062+ }
1063+
1064+ impl Writeable for InvoiceParameters {
1065+ fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
1066+ let mut clear_hints = & vec ! [ ] ;
1067+ let mut blinded_hints = None ;
1068+ match & self . payee {
1069+ Payee :: Clear { route_hints, .. } => clear_hints = route_hints,
1070+ Payee :: Blinded { route_hints, .. } => {
1071+ let hints_iter = route_hints. iter ( ) . map ( |path| ( & path. payinfo , path. inner_blinded_path ( ) ) ) ;
1072+ blinded_hints = Some ( crate :: util:: ser:: IterableOwned ( hints_iter) ) ;
1073+ }
1074+ }
1075+ write_tlv_fields ! ( writer, {
1076+ ( 0 , self . payee. node_id( ) , option) ,
1077+ ( 2 , self . payee. features( ) , option) ,
1078+ ( 4 , * clear_hints, required_vec) ,
1079+ ( 6 , self . expiry_time, option) ,
1080+ ( 7 , self . previously_failed_channels, required_vec) ,
1081+ ( 8 , blinded_hints, option) ,
1082+ ( 9 , self . payee. final_cltv_expiry_delta( ) , option) ,
1083+ ( 11 , self . previously_failed_blinded_path_idxs, required_vec) ,
1084+ } ) ;
1085+ Ok ( ( ) )
1086+ }
1087+ }
1088+
1089+ impl ReadableArgs < u32 > for InvoiceParameters {
1090+ fn read < R : io:: Read > ( reader : & mut R , default_final_cltv_expiry_delta : u32 ) -> Result < Self , DecodeError > {
1091+ _init_and_read_len_prefixed_tlv_fields ! ( reader, {
1092+ ( 0 , payee_pubkey, option) ,
1093+ ( 2 , features, ( option: ReadableArgs , payee_pubkey. is_some( ) ) ) ,
1094+ ( 4 , clear_route_hints, required_vec) ,
1095+ ( 6 , expiry_time, option) ,
1096+ ( 7 , previously_failed_channels, optional_vec) ,
1097+ ( 8 , blinded_route_hints, optional_vec) ,
1098+ ( 9 , final_cltv_expiry_delta, ( default_value, default_final_cltv_expiry_delta) ) ,
1099+ ( 11 , previously_failed_blinded_path_idxs, optional_vec) ,
1100+ } ) ;
1101+ let blinded_route_hints = blinded_route_hints. unwrap_or ( vec ! [ ] ) ;
1102+ let payee = if blinded_route_hints. len ( ) != 0 {
1103+ if clear_route_hints. len ( ) != 0 || payee_pubkey. is_some ( ) { return Err ( DecodeError :: InvalidValue ) }
1104+ Payee :: Blinded {
1105+ route_hints : blinded_route_hints
1106+ . into_iter ( )
1107+ . map ( |( payinfo, path) | BlindedPaymentPath :: from_parts ( path, payinfo) )
1108+ . collect ( ) ,
1109+ features : features. and_then ( |f : Features | f. bolt12 ( ) ) ,
1110+ }
1111+ } else {
1112+ Payee :: Clear {
1113+ route_hints : clear_route_hints,
1114+ node_id : payee_pubkey. ok_or ( DecodeError :: InvalidValue ) ?,
1115+ features : features. and_then ( |f| f. bolt11 ( ) ) ,
1116+ final_cltv_expiry_delta : final_cltv_expiry_delta. 0 . unwrap ( ) ,
1117+ }
1118+ } ;
1119+
1120+ Ok ( Self {
1121+ payee,
1122+ expiry_time,
1123+ previously_failed_channels : previously_failed_channels. unwrap_or ( Vec :: new ( ) ) ,
1124+ previously_failed_blinded_path_idxs : previously_failed_blinded_path_idxs. unwrap_or ( Vec :: new ( ) ) ,
1125+ } )
1126+ }
1127+ }
1128+
9651129/// The recipient of a payment, differing based on whether they've hidden their identity with route
9661130/// blinding.
9671131#[ derive( Clone , Debug , Hash , PartialEq , Eq ) ]
0 commit comments