Skip to content

Commit 87390d5

Browse files
f support None route params and test
1 parent 87b8679 commit 87390d5

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

lightning/src/ln/channelmanager.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -4602,14 +4602,20 @@ where
46024602
}
46034603

46044604
/// Sends a payment along a given route. See [`Self::send_payment`] for more info.
4605-
/// [`Route::route_params`] is required to be `Some`.
46064605
pub fn send_payment_with_route(
4607-
&self, route: Route, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields,
4606+
&self, mut route: Route, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields,
46084607
payment_id: PaymentId
46094608
) -> Result<(), RetryableSendFailure> {
46104609
let best_block_height = self.best_block.read().unwrap().height;
46114610
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4612-
let route_params = route.route_params.clone().ok_or(RetryableSendFailure::RouteNotFound)?;
4611+
let route_params = route.route_params.clone().unwrap_or_else(|| {
4612+
// Create a dummy since route params are a required parameter but unused in this case
4613+
let payment_params = PaymentParameters::from_node_id(
4614+
self.get_our_node_id(), MIN_FINAL_CLTV_EXPIRY_DELTA as u32
4615+
);
4616+
RouteParameters::from_payment_params_and_value(payment_params, route.get_total_amount())
4617+
});
4618+
if route.route_params.is_none() { route.route_params = Some(route_params.clone()); }
46134619
self.router.route_cache.lock().unwrap().insert(payment_id, route);
46144620
self.pending_outbound_payments
46154621
.send_payment(payment_hash, recipient_onion, payment_id, Retry::Attempts(0),

lightning/src/ln/payment_tests.rs

+29
Original file line numberDiff line numberDiff line change
@@ -4450,3 +4450,32 @@ fn remove_pending_outbound_probe_on_buggy_path() {
44504450
);
44514451
assert!(nodes[0].node.list_recent_payments().is_empty());
44524452
}
4453+
4454+
#[test]
4455+
fn pay_route_without_params() {
4456+
// Make sure we can use ChannelManager::send_payment_with_route to pay a route where
4457+
// Route::route_parameters is None.
4458+
let chanmon_cfgs = create_chanmon_cfgs(2);
4459+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
4460+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
4461+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
4462+
create_announced_chan_between_nodes(&nodes, 0, 1);
4463+
4464+
let amt_msat = 10_000;
4465+
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
4466+
.with_bolt11_features(nodes[1].node.bolt11_invoice_features()).unwrap();
4467+
let (mut route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], payment_params, amt_msat);
4468+
route.route_params.take();
4469+
nodes[0].node.send_payment_with_route(
4470+
route, payment_hash, RecipientOnionFields::secret_only(payment_secret),
4471+
PaymentId(payment_hash.0)
4472+
).unwrap();
4473+
check_added_monitors!(nodes[0], 1);
4474+
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
4475+
assert_eq!(events.len(), 1);
4476+
let node_1_msgs = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut events);
4477+
pass_along_path(&nodes[0], &[&nodes[1]], amt_msat, payment_hash, Some(payment_secret), node_1_msgs, true, None);
4478+
claim_payment_along_route(
4479+
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], payment_preimage)
4480+
);
4481+
}

0 commit comments

Comments
 (0)