Skip to content

Commit eda574d

Browse files
committed
Fix Route serialization round-trip
When the `max_total_routing_fee_msat` parameter was added to `RouteParameters`, the serialization used `map` to get the max fee, accidentally writing an `Option<Option<u64>>`, but then read it as an `Option<u64>`. Thus, any `Route`s with a `route_params` written will fail to be read back. Luckily, this is an incredibly rarely-used bit of code, so only one user managed to hit it.
1 parent 3fd4b39 commit eda574d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lightning/src/routing/router.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl Writeable for Route {
526526
(1, self.route_params.as_ref().map(|p| &p.payment_params), option),
527527
(2, blinded_tails, optional_vec),
528528
(3, self.route_params.as_ref().map(|p| p.final_value_msat), option),
529-
(5, self.route_params.as_ref().map(|p| p.max_total_routing_fee_msat), option),
529+
(5, self.route_params.as_ref().and_then(|p| p.max_total_routing_fee_msat), option),
530530
});
531531
Ok(())
532532
}

lightning/src/util/test_utils.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ impl<'a> Router for TestRouter<'a> {
143143
&self, payer: &PublicKey, params: &RouteParameters, first_hops: Option<&[&ChannelDetails]>,
144144
inflight_htlcs: InFlightHtlcs
145145
) -> Result<Route, msgs::LightningError> {
146+
let route_res;
146147
if let Some((find_route_query, find_route_res)) = self.next_routes.lock().unwrap().pop_front() {
147148
assert_eq!(find_route_query, *params);
148149
if let Ok(ref route) = find_route_res {
@@ -201,10 +202,18 @@ impl<'a> Router for TestRouter<'a> {
201202
}
202203
}
203204
}
204-
return find_route_res;
205-
}
205+
route_res = find_route_res;
206+
} else {
207+
route_res = self.router.find_route(payer, params, first_hops, inflight_htlcs);
208+
};
206209

207-
self.router.find_route(payer, params, first_hops, inflight_htlcs)
210+
if let Ok(route) = &route_res {
211+
// Previously, `Route`s failed to round-trip through serialization due to a write/read
212+
// mismatch. Thus, hwere we test all test-generated routes round-trip:
213+
let ser = route.encode();
214+
assert_eq!(Route::read(&mut &ser[..]).unwrap(), *route);
215+
}
216+
route_res
208217
}
209218

210219
fn create_blinded_payment_paths<

0 commit comments

Comments
 (0)