@@ -6,6 +6,7 @@ use crate::logger::{log_error, log_info, FilesystemLogger, Logger};
66use crate :: payment:: store:: {
77 PaymentDetails , PaymentDirection , PaymentKind , PaymentStatus , PaymentStore ,
88} ;
9+ use crate :: payment:: SendingParameters ;
910use crate :: types:: { ChannelManager , KeysManager } ;
1011
1112use lightning:: ln:: channelmanager:: { PaymentId , RecipientOnionFields , Retry , RetryableSendFailure } ;
@@ -41,8 +42,15 @@ impl SpontaneousPayment {
4142 Self { runtime, channel_manager, keys_manager, payment_store, config, logger }
4243 }
4344
44- /// Send a spontaneous, aka. "keysend", payment
45- pub fn send ( & self , amount_msat : u64 , node_id : PublicKey ) -> Result < PaymentId , Error > {
45+ /// Send a spontaneous aka. "keysend", payment.
46+ ///
47+ /// If [`SendingParameters`] are provided they will override the node's default routing parameters
48+ /// on a per-field basis. Each field in `SendingParameters` that is set replaces the corresponding
49+ /// default value. Fields that are not set fall back to the node's configured defaults. If no
50+ /// `SendingParameters` are provided, the method fully relies on these defaults.
51+ pub fn send (
52+ & self , amount_msat : u64 , node_id : PublicKey , sending_parameters : Option < SendingParameters > ,
53+ ) -> Result < PaymentId , Error > {
4654 let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
4755 if rt_lock. is_none ( ) {
4856 return Err ( Error :: NotRunning ) ;
@@ -61,10 +69,45 @@ impl SpontaneousPayment {
6169 }
6270 }
6371
64- let route_params = RouteParameters :: from_payment_params_and_value (
72+ let mut route_params = RouteParameters :: from_payment_params_and_value (
6573 PaymentParameters :: from_node_id ( node_id, self . config . default_cltv_expiry_delta ) ,
6674 amount_msat,
6775 ) ;
76+
77+ if let Some ( user_set_params) = sending_parameters {
78+ if let Some ( mut default_params) =
79+ self . config . sending_parameters_config . as_ref ( ) . cloned ( )
80+ {
81+ default_params. max_total_routing_fee_msat = user_set_params
82+ . max_total_routing_fee_msat
83+ . or ( default_params. max_total_routing_fee_msat ) ;
84+ default_params. max_total_cltv_expiry_delta = user_set_params
85+ . max_total_cltv_expiry_delta
86+ . or ( default_params. max_total_cltv_expiry_delta ) ;
87+ default_params. max_path_count =
88+ user_set_params. max_path_count . or ( default_params. max_path_count ) ;
89+ default_params. max_channel_saturation_power_of_half = user_set_params
90+ . max_channel_saturation_power_of_half
91+ . or ( default_params. max_channel_saturation_power_of_half ) ;
92+
93+ route_params. max_total_routing_fee_msat = default_params. max_total_routing_fee_msat ;
94+ route_params. payment_params . max_total_cltv_expiry_delta =
95+ default_params. max_total_cltv_expiry_delta . unwrap_or_default ( ) ;
96+ route_params. payment_params . max_path_count =
97+ default_params. max_path_count . unwrap_or_default ( ) ;
98+ route_params. payment_params . max_channel_saturation_power_of_half =
99+ default_params. max_channel_saturation_power_of_half . unwrap_or_default ( ) ;
100+ }
101+ } else if let Some ( default_params) = & self . config . sending_parameters_config {
102+ route_params. max_total_routing_fee_msat = default_params. max_total_routing_fee_msat ;
103+ route_params. payment_params . max_total_cltv_expiry_delta =
104+ default_params. max_total_cltv_expiry_delta . unwrap_or_default ( ) ;
105+ route_params. payment_params . max_path_count =
106+ default_params. max_path_count . unwrap_or_default ( ) ;
107+ route_params. payment_params . max_channel_saturation_power_of_half =
108+ default_params. max_channel_saturation_power_of_half . unwrap_or_default ( ) ;
109+ }
110+
68111 let recipient_fields = RecipientOnionFields :: spontaneous_empty ( ) ;
69112
70113 match self . channel_manager . send_spontaneous_payment_with_retry (
0 commit comments