Skip to content

Commit b427238

Browse files
committed
Assert query's and route's final_value_msat are equal
1 parent 6ae1855 commit b427238

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lightning/src/ln/outbound_payment.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ impl OutboundPayments {
875875
}
876876
}
877877

878-
let route = router.find_route_with_id(
878+
let mut route = router.find_route_with_id(
879879
&node_signer.get_node_id(Recipient::Node).unwrap(), &route_params,
880880
Some(&first_hops.iter().collect::<Vec<_>>()), inflight_htlcs(),
881881
payment_hash, payment_id,
@@ -885,6 +885,14 @@ impl OutboundPayments {
885885
RetryableSendFailure::RouteNotFound
886886
})?;
887887

888+
if let Some(route_route_params) = route.route_params.as_mut() {
889+
if route_route_params.final_value_msat != route_params.final_value_msat {
890+
debug_assert!(false,
891+
"Routers are expected to return a route which includes the requested final_value_msat");
892+
route_route_params.final_value_msat = route_params.final_value_msat;
893+
}
894+
}
895+
888896
let onion_session_privs = self.add_new_pending_payment(payment_hash,
889897
recipient_onion.clone(), payment_id, keysend_preimage, &route, Some(retry_strategy),
890898
Some(route_params.payment_params.clone()), entropy_source, best_block_height)
@@ -926,7 +934,7 @@ impl OutboundPayments {
926934
}
927935
}
928936

929-
let route = match router.find_route_with_id(
937+
let mut route = match router.find_route_with_id(
930938
&node_signer.get_node_id(Recipient::Node).unwrap(), &route_params,
931939
Some(&first_hops.iter().collect::<Vec<_>>()), inflight_htlcs(),
932940
payment_hash, payment_id,
@@ -938,6 +946,15 @@ impl OutboundPayments {
938946
return
939947
}
940948
};
949+
950+
if let Some(route_route_params) = route.route_params.as_mut() {
951+
if route_route_params.final_value_msat != route_params.final_value_msat {
952+
debug_assert!(false,
953+
"Routers are expected to return a route which includes the requested final_value_msat");
954+
route_route_params.final_value_msat = route_params.final_value_msat;
955+
}
956+
}
957+
941958
for path in route.paths.iter() {
942959
if path.hops.len() == 0 {
943960
log_error!(logger, "Unusable path in route (path.hops.len() must be at least 1");

lightning/src/util/test_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ impl<'a> Router for TestRouter<'a> {
124124
if let Some((find_route_query, find_route_res)) = self.next_routes.lock().unwrap().pop_front() {
125125
assert_eq!(find_route_query, *params);
126126
if let Ok(ref route) = find_route_res {
127+
assert_eq!(route.route_params.as_ref().unwrap().final_value_msat, find_route_query.final_value_msat);
127128
let scorer = self.scorer.read().unwrap();
128129
let scorer = ScorerAccountingForInFlightHtlcs::new(scorer, &inflight_htlcs);
129130
for path in &route.paths {

0 commit comments

Comments
 (0)