Skip to content

Commit 0ce7c9a

Browse files
authored
Merge pull request #4693 from valentinewallace/2026-06-sendwithroute-33b-pk
`Route::route_params`: `Option` -> required
2 parents 9df5c9d + d5d502a commit 0ce7c9a

13 files changed

Lines changed: 257 additions & 260 deletions

fuzz/src/chanmon_consistency.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,7 @@ impl PaymentTracker {
18661866
}],
18671867
blinded_tail: None,
18681868
}],
1869-
route_params: Some(route_params.clone()),
1869+
route_params: route_params.clone(),
18701870
};
18711871
let onion = RecipientOnionFields::secret_only(secret, amt);
18721872
let res = source.send_payment_with_route(route, hash, onion, id);
@@ -1946,7 +1946,7 @@ impl PaymentTracker {
19461946
],
19471947
blinded_tail: None,
19481948
}],
1949-
route_params: Some(route_params.clone()),
1949+
route_params: route_params.clone(),
19501950
};
19511951
let onion = RecipientOnionFields::secret_only(secret, amt);
19521952
let res = source.send_payment_with_route(route, hash, onion, id);
@@ -2028,7 +2028,7 @@ impl PaymentTracker {
20282028
PaymentParameters::from_node_id(dest.get_our_node_id(), TEST_FINAL_CLTV),
20292029
amt,
20302030
);
2031-
let route = Route { paths, route_params: Some(route_params) };
2031+
let route = Route { paths, route_params };
20322032
let onion = RecipientOnionFields::secret_only(secret, amt);
20332033
let res = source.send_payment_with_route(route, hash, onion, id);
20342034
let succeeded = match res {
@@ -2132,7 +2132,7 @@ impl PaymentTracker {
21322132
PaymentParameters::from_node_id(dest.get_our_node_id(), TEST_FINAL_CLTV),
21332133
amt,
21342134
);
2135-
let route = Route { paths, route_params: Some(route_params) };
2135+
let route = Route { paths, route_params };
21362136
let onion = RecipientOnionFields::secret_only(secret, amt);
21372137
let res = source.send_payment_with_route(route, hash, onion, id);
21382138
let succeeded = match res {

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,7 @@ fn test_trampoline_forward_payload_encoded_as_receive() {
20932093
let bob_carol_scid = nodes[1].node().list_channels().iter().find(|c| c.channel_id == chan_id_bob_carol).unwrap().short_channel_id.unwrap();
20942094

20952095
let amt_msat = 1000;
2096+
let carol_cltv_expiry_delta = 24 + 39;
20962097
let (payment_preimage, payment_hash, _) = get_payment_preimage_hash(&nodes[2], Some(amt_msat), None);
20972098

20982099
// We need the session priv to construct an invalid onion packet later.
@@ -2148,7 +2149,7 @@ fn test_trampoline_forward_payload_encoded_as_receive() {
21482149
short_channel_id: bob_carol_scid,
21492150
channel_features: ChannelFeatures::empty(),
21502151
fee_msat: 0,
2151-
cltv_expiry_delta: 24 + 39,
2152+
cltv_expiry_delta: carol_cltv_expiry_delta,
21522153
maybe_announced_channel: false,
21532154
}
21542155
],
@@ -2159,7 +2160,7 @@ fn test_trampoline_forward_payload_encoded_as_receive() {
21592160
pubkey: carol_node_id,
21602161
node_features: Features::empty(),
21612162
fee_msat: amt_msat,
2162-
cltv_expiry_delta: 24 + 39,
2163+
cltv_expiry_delta: carol_cltv_expiry_delta,
21632164
},
21642165
],
21652166
hops: carol_blinded_hops,
@@ -2168,7 +2169,10 @@ fn test_trampoline_forward_payload_encoded_as_receive() {
21682169
final_value_msat: amt_msat,
21692170
})
21702171
}],
2171-
route_params: None,
2172+
route_params: RouteParameters::from_payment_params_and_value(
2173+
PaymentParameters::from_node_id(carol_node_id, carol_cltv_expiry_delta),
2174+
amt_msat,
2175+
),
21722176
};
21732177

21742178
nodes[0].node.send_payment_with_route(route.clone(), payment_hash, RecipientOnionFields::spontaneous_empty(amt_msat), PaymentId(payment_hash.0)).unwrap();
@@ -2279,6 +2283,7 @@ fn do_test_trampoline_single_hop_receive(success: bool) {
22792283
let bob_carol_scid = nodes[1].node().list_channels().iter().find(|c| c.channel_id == chan_id_bob_carol).unwrap().short_channel_id.unwrap();
22802284

22812285
let amt_msat = 1000;
2286+
let carol_cltv_expiry_delta = 104 + 39;
22822287
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], Some(amt_msat), None);
22832288

22842289
// Create a 1-hop blinded path for Carol.
@@ -2314,7 +2319,7 @@ fn do_test_trampoline_single_hop_receive(success: bool) {
23142319
short_channel_id: bob_carol_scid,
23152320
channel_features: ChannelFeatures::empty(),
23162321
fee_msat: 0,
2317-
cltv_expiry_delta: 104 + 39,
2322+
cltv_expiry_delta: carol_cltv_expiry_delta,
23182323
maybe_announced_channel: false,
23192324
}
23202325
],
@@ -2325,7 +2330,7 @@ fn do_test_trampoline_single_hop_receive(success: bool) {
23252330
pubkey: carol_node_id,
23262331
node_features: Features::empty(),
23272332
fee_msat: amt_msat,
2328-
cltv_expiry_delta: 104 + 39,
2333+
cltv_expiry_delta: carol_cltv_expiry_delta,
23292334
},
23302335
],
23312336
hops: blinded_path.blinded_hops().to_vec(),
@@ -2334,7 +2339,10 @@ fn do_test_trampoline_single_hop_receive(success: bool) {
23342339
final_value_msat: amt_msat,
23352340
})
23362341
}],
2337-
route_params: None,
2342+
route_params: RouteParameters::from_payment_params_and_value(
2343+
PaymentParameters::from_node_id(carol_node_id, carol_cltv_expiry_delta),
2344+
amt_msat,
2345+
),
23382346
};
23392347

23402348
nodes[0].node.send_payment_with_route(route.clone(), payment_hash, RecipientOnionFields::spontaneous_empty(amt_msat), PaymentId(payment_hash.0)).unwrap();
@@ -2618,7 +2626,13 @@ fn do_test_trampoline_relay(blinded: bool, test_case: TrampolineTestCase) {
26182626
original_amt_msat,
26192627
)),
26202628
}],
2621-
route_params: None,
2629+
route_params: RouteParameters::from_payment_params_and_value(
2630+
PaymentParameters::from_node_id(
2631+
carol_node_id,
2632+
original_trampoline_cltv + excess_final_cltv,
2633+
),
2634+
original_amt_msat,
2635+
),
26222636
};
26232637

26242638
nodes[0]
@@ -2753,6 +2767,7 @@ fn test_trampoline_forward_rejection() {
27532767
let bob_carol_scid = nodes[1].node().list_channels().iter().find(|c| c.channel_id == chan_id_bob_carol).unwrap().short_channel_id.unwrap();
27542768

27552769
let amt_msat = 1000;
2770+
let carol_cltv_expiry_delta = 24 + 24 + 39;
27562771
let (payment_preimage, payment_hash, _) = get_payment_preimage_hash(&nodes[2], Some(amt_msat), None);
27572772

27582773
let route = Route {
@@ -2776,7 +2791,7 @@ fn test_trampoline_forward_rejection() {
27762791
short_channel_id: bob_carol_scid,
27772792
channel_features: ChannelFeatures::empty(),
27782793
fee_msat: 0,
2779-
cltv_expiry_delta: 24 + 24 + 39,
2794+
cltv_expiry_delta: carol_cltv_expiry_delta,
27802795
maybe_announced_channel: false,
27812796
}
27822797
],
@@ -2808,7 +2823,10 @@ fn test_trampoline_forward_rejection() {
28082823
final_value_msat: amt_msat,
28092824
})
28102825
}],
2811-
route_params: None,
2826+
route_params: RouteParameters::from_payment_params_and_value(
2827+
PaymentParameters::from_node_id(carol_node_id, carol_cltv_expiry_delta),
2828+
amt_msat,
2829+
),
28122830
};
28132831

28142832
nodes[0].node.send_payment_with_route(route.clone(), payment_hash, RecipientOnionFields::spontaneous_empty(amt_msat), PaymentId(payment_hash.0)).unwrap();

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,7 +2315,7 @@ fn test_path_paused_mpp() {
23152315
route.paths[1].hops[0].pubkey = node_c_id;
23162316
route.paths[1].hops[0].short_channel_id = chan_2_ann.contents.short_channel_id;
23172317
route.paths[1].hops[1].short_channel_id = chan_4_id;
2318-
route.route_params.as_mut().unwrap().final_value_msat *= 2;
2318+
route.route_params.final_value_msat *= 2;
23192319

23202320
// Set it so that the first monitor update (for the path 0 -> 1 -> 3) succeeds, but the second
23212321
// (for the path 0 -> 2 -> 3) fails.
@@ -4315,7 +4315,7 @@ fn do_test_partial_claim_mon_update_compl_actions(reload_a: bool, reload_b: bool
43154315
route.paths[1].hops[0].pubkey = node_c_id;
43164316
route.paths[1].hops[0].short_channel_id = chan_2_scid;
43174317
route.paths[1].hops[1].short_channel_id = chan_4_scid;
4318-
route.route_params.as_mut().unwrap().final_value_msat *= 2;
4318+
route.route_params.final_value_msat *= 2;
43194319

43204320
let paths = &[&[&nodes[1], &nodes[3]][..], &[&nodes[2], &nodes[3]][..]];
43214321
send_along_route_with_secret(&nodes[0], route, paths, 200_000, payment_hash, payment_secret);

lightning/src/ln/channelmanager.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5631,30 +5631,32 @@ impl<
56315631
///
56325632
/// LDK will not automatically retry this payment, though it may be manually re-sent after an
56335633
/// [`Event::PaymentFailed`] is generated.
5634-
#[rustfmt::skip]
56355634
pub fn send_payment_with_route(
5636-
&self, mut route: Route, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields,
5637-
payment_id: PaymentId
5635+
&self, route: Route, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields,
5636+
payment_id: PaymentId,
56385637
) -> Result<(), RetryableSendFailure> {
56395638
let best_block_height = self.best_block.read().unwrap().height;
56405639
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
5641-
let route_params = route.route_params.clone().unwrap_or_else(|| {
5642-
// Create a dummy route params since they're a required parameter but unused in this case
5643-
let (payee_node_id, cltv_delta) = route.paths.first()
5644-
.and_then(|path| path.hops.last().map(|hop| (hop.pubkey, hop.cltv_expiry_delta as u32)))
5645-
.unwrap_or_else(|| (PublicKey::from_slice(&[2; 33]).unwrap(), MIN_FINAL_CLTV_EXPIRY_DELTA as u32));
5646-
let dummy_payment_params = PaymentParameters::from_node_id(payee_node_id, cltv_delta);
5647-
RouteParameters::from_payment_params_and_value(dummy_payment_params, route.get_total_amount())
5648-
});
5649-
if route.route_params.is_none() { route.route_params = Some(route_params.clone()); }
5640+
let route_params = route.route_params.clone();
56505641
let router = FixedRouter::new(route);
56515642
let logger =
56525643
WithContext::for_payment(&self.logger, None, None, Some(payment_hash), payment_id);
5653-
self.pending_outbound_payments
5654-
.send_payment(payment_hash, recipient_onion, payment_id, Retry::Attempts(0),
5655-
route_params, &&router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
5656-
&self.entropy_source, &self.node_signer, best_block_height,
5657-
&self.pending_events, |args| self.send_payment_along_path(args), &logger)
5644+
self.pending_outbound_payments.send_payment(
5645+
payment_hash,
5646+
recipient_onion,
5647+
payment_id,
5648+
Retry::Attempts(0),
5649+
route_params,
5650+
&&router,
5651+
self.list_usable_channels(),
5652+
|| self.compute_inflight_htlcs(),
5653+
&self.entropy_source,
5654+
&self.node_signer,
5655+
best_block_height,
5656+
&self.pending_events,
5657+
|args| self.send_payment_along_path(args),
5658+
&logger,
5659+
)
56585660
}
56595661

56605662
/// Sends a payment to the route found using the provided [`RouteParameters`], retrying failed
@@ -21095,7 +21097,7 @@ mod tests {
2109521097
// Next, send a keysend payment with the same payment_hash and make sure it fails.
2109621098
nodes[0].node.send_spontaneous_payment(
2109721099
Some(payment_preimage), RecipientOnionFields::spontaneous_empty(100_000),
21098-
PaymentId(payment_preimage.0), route.route_params.clone().unwrap(), Retry::Attempts(0)
21100+
PaymentId(payment_preimage.0), route.route_params.clone(), Retry::Attempts(0)
2109921101
).unwrap();
2110021102
check_added_monitors(&nodes[0], 1);
2110121103
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
@@ -21251,7 +21253,7 @@ mod tests {
2125121253
).unwrap();
2125221254
let payment_hash = nodes[0].node.send_spontaneous_payment(
2125321255
Some(payment_preimage), RecipientOnionFields::spontaneous_empty(100_000),
21254-
PaymentId(payment_preimage.0), route.route_params.clone().unwrap(), Retry::Attempts(0)
21256+
PaymentId(payment_preimage.0), route.route_params.clone(), Retry::Attempts(0)
2125521257
).unwrap();
2125621258
check_added_monitors(&nodes[0], 1);
2125721259
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
@@ -21294,7 +21296,7 @@ mod tests {
2129421296
let payment_id_1 = PaymentId([44; 32]);
2129521297
let payment_hash = nodes[0].node.send_spontaneous_payment(
2129621298
Some(payment_preimage), RecipientOnionFields::spontaneous_empty(100_000), payment_id_1,
21297-
route.route_params.clone().unwrap(), Retry::Attempts(0)
21299+
route.route_params.clone(), Retry::Attempts(0)
2129821300
).unwrap();
2129921301
check_added_monitors(&nodes[0], 1);
2130021302
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
@@ -21412,7 +21414,7 @@ mod tests {
2141221414
route.paths[1].hops[0].pubkey = nodes[2].node.get_our_node_id();
2141321415
route.paths[1].hops[0].short_channel_id = chan_2_id;
2141421416
route.paths[1].hops[1].short_channel_id = chan_4_id;
21415-
route.route_params.as_mut().unwrap().final_value_msat *= 2;
21417+
route.route_params.final_value_msat *= 2;
2141621418

2141721419
nodes[0].node.send_payment_with_route(route, payment_hash,
2141821420
RecipientOnionFields::spontaneous_empty(200000), PaymentId(payment_hash.0)).unwrap();

lightning/src/ln/functional_test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3492,14 +3492,14 @@ pub fn send_along_route_with_secret<'a, 'b, 'c>(
34923492
recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: PaymentSecret,
34933493
) -> PaymentId {
34943494
let payment_id = PaymentId(origin_node.keys_manager.backing.get_secure_random_bytes());
3495-
origin_node.router.expect_find_route(route.route_params.clone().unwrap(), Ok(route.clone()));
3495+
origin_node.router.expect_find_route(route.route_params.clone(), Ok(route.clone()));
34963496
origin_node
34973497
.node
34983498
.send_payment(
34993499
our_payment_hash,
35003500
RecipientOnionFields::secret_only(our_payment_secret, recv_value),
35013501
payment_id,
3502-
route.route_params.unwrap(),
3502+
route.route_params,
35033503
Retry::Attempts(0),
35043504
)
35053505
.unwrap();

lightning/src/ln/functional_tests.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub fn fake_network_test() {
164164
let route_params = RouteParameters::from_payment_params_and_value(payment_params, 1000000);
165165
let route = Route {
166166
paths: vec![Path { hops, blinded_tail: None }],
167-
route_params: Some(route_params.clone()),
167+
route_params: route_params.clone(),
168168
};
169169
let path: &[_] = &[&nodes[2], &nodes[3], &nodes[1]];
170170
let payment_preimage_1 = send_along_route(&nodes[1], route, path, 1000000).0;
@@ -202,8 +202,7 @@ pub fn fake_network_test() {
202202
+ chan_2.1.contents.fee_proportional_millionths as u64 * hops[2].fee_msat as u64 / 1000000;
203203
hops[0].fee_msat = chan_3.1.contents.fee_base_msat as u64
204204
+ chan_3.1.contents.fee_proportional_millionths as u64 * hops[1].fee_msat as u64 / 1000000;
205-
let route =
206-
Route { paths: vec![Path { hops, blinded_tail: None }], route_params: Some(route_params) };
205+
let route = Route { paths: vec![Path { hops, blinded_tail: None }], route_params };
207206
let path: &[_] = &[&nodes[3], &nodes[2], &nodes[1]];
208207
let payment_hash_2 = send_along_route(&nodes[1], route, path, 1000000).1;
209208

@@ -7214,7 +7213,7 @@ pub fn test_simple_mpp() {
72147213
route.paths[1].hops[0].pubkey = node_c_id;
72157214
route.paths[1].hops[0].short_channel_id = chan_2_id;
72167215
route.paths[1].hops[1].short_channel_id = chan_4_id;
7217-
route.route_params.as_mut().unwrap().final_value_msat = 200_000;
7216+
route.route_params.final_value_msat = 200_000;
72187217
let paths: &[&[_]] = &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]];
72197218
send_along_route_with_secret(&nodes[0], route, paths, 200_000, payment_hash, payment_secret);
72207219
claim_payment_along_route(ClaimAlongRouteArgs::new(&nodes[0], paths, payment_preimage));

lightning/src/ln/max_payment_path_len_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn large_payment_metadata() {
110110
custom_tlvs: Vec::new(),
111111
total_mpp_amount_msat: amt_msat,
112112
};
113-
let route_params = route_0_1.route_params.clone().unwrap();
113+
let route_params = route_0_1.route_params.clone();
114114
let id = PaymentId(payment_hash.0);
115115
nodes[0]
116116
.node
@@ -138,14 +138,14 @@ fn large_payment_metadata() {
138138
let (payment_hash_2, _, payment_secret_2, encrypted_metadata_2) =
139139
get_payment_hash!(nodes[2], payment_metadata.clone());
140140
let (mut route_0_2, ..) = get_route_and_payment_hash!(&nodes[0], &nodes[2], amt_msat);
141-
let mut route_params_0_2 = route_0_2.route_params.clone().unwrap();
141+
let mut route_params_0_2 = route_0_2.route_params.clone();
142142
route_params_0_2.payment_params.max_path_length = 1;
143143
nodes[0].router.expect_find_route_query(route_params_0_2);
144144
max_sized_onion.payment_secret = Some(payment_secret_2);
145145
max_sized_onion.payment_metadata = Some(encrypted_metadata_2);
146146

147147
let id = PaymentId(payment_hash_2.0);
148-
let mut route_params = route_0_2.route_params.clone().unwrap();
148+
let mut route_params = route_0_2.route_params.clone();
149149
let err = nodes[0]
150150
.node
151151
.send_payment(payment_hash_2, max_sized_onion.clone(), id, route_params, Retry::Attempts(0))
@@ -184,7 +184,7 @@ fn large_payment_metadata() {
184184
_ => panic!(),
185185
}
186186

187-
let route_params = route_0_1.route_params.clone().unwrap();
187+
let route_params = route_0_1.route_params.clone();
188188
let err = nodes[0]
189189
.node
190190
.send_payment(payment_hash_2, too_large_onion, id, route_params, Retry::Attempts(0))
@@ -202,10 +202,10 @@ fn large_payment_metadata() {
202202
custom_tlvs: Vec::new(),
203203
total_mpp_amount_msat: amt_msat,
204204
};
205-
let mut route_params_0_2 = route_0_2.route_params.clone().unwrap();
205+
let mut route_params_0_2 = route_0_2.route_params.clone();
206206
route_params_0_2.payment_params.max_path_length = 2;
207207
nodes[0].router.expect_find_route_query(route_params_0_2);
208-
let route_params = route_0_2.route_params.unwrap();
208+
let route_params = route_0_2.route_params;
209209
nodes[0]
210210
.node
211211
.send_payment(payment_hash_2, onion_allowing_2_hops, id, route_params, Retry::Attempts(0))

lightning/src/ln/onion_utils.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3034,7 +3034,7 @@ mod tests {
30343034
use crate::ln::channelmanager::PaymentId;
30353035
use crate::ln::msgs::{self, UpdateFailHTLC};
30363036
use crate::ln::types::ChannelId;
3037-
use crate::routing::router::{Path, PaymentParameters, Route, RouteHop};
3037+
use crate::routing::router::{Path, PaymentParameters, Route, RouteHop, RouteParameters};
30383038
use crate::types::features::{ChannelFeatures, NodeFeatures};
30393039
use crate::types::payment::PaymentHash;
30403040
use crate::util::ser::{VecWriter, Writeable, Writer};
@@ -3142,7 +3142,10 @@ mod tests {
31423142
let secp_ctx = Secp256k1::new();
31433143

31443144
let path = build_test_path();
3145-
let route = Route { paths: vec![path], route_params: None };
3145+
let payment_params = PaymentParameters::from_node_id(path.hops.last().unwrap().pubkey, 0);
3146+
let route_params =
3147+
RouteParameters::from_payment_params_and_value(payment_params, path.final_value_msat());
3148+
let route = Route { paths: vec![path], route_params };
31463149

31473150
let onion_keys =
31483151
super::construct_onion_keys(&secp_ctx, &route.paths[0], &get_test_session_key());

0 commit comments

Comments
 (0)