@@ -6,6 +6,7 @@ use crate::logger::{log_error, log_info, FilesystemLogger, Logger};
6
6
use crate :: payment:: store:: {
7
7
PaymentDetails , PaymentDirection , PaymentKind , PaymentStatus , PaymentStore ,
8
8
} ;
9
+ use crate :: payment:: SendingParameters ;
9
10
use crate :: types:: { ChannelManager , KeysManager } ;
10
11
11
12
use lightning:: ln:: channelmanager:: { PaymentId , RecipientOnionFields , Retry , RetryableSendFailure } ;
@@ -41,8 +42,15 @@ impl SpontaneousPayment {
41
42
Self { runtime, channel_manager, keys_manager, payment_store, config, logger }
42
43
}
43
44
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 > {
46
54
let rt_lock = self . runtime . read ( ) . unwrap ( ) ;
47
55
if rt_lock. is_none ( ) {
48
56
return Err ( Error :: NotRunning ) ;
@@ -61,10 +69,45 @@ impl SpontaneousPayment {
61
69
}
62
70
}
63
71
64
- let route_params = RouteParameters :: from_payment_params_and_value (
72
+ let mut route_params = RouteParameters :: from_payment_params_and_value (
65
73
PaymentParameters :: from_node_id ( node_id, self . config . default_cltv_expiry_delta ) ,
66
74
amount_msat,
67
75
) ;
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
+
68
111
let recipient_fields = RecipientOnionFields :: spontaneous_empty ( ) ;
69
112
70
113
match self . channel_manager . send_spontaneous_payment_with_retry (
0 commit comments