Skip to content

Commit 2c2f39a

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 9de51f0 commit 2c2f39a

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lightning/src/routing/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ impl Writeable for Route {
410410
(1, self.route_params.as_ref().map(|p| &p.payment_params), option),
411411
(2, blinded_tails, optional_vec),
412412
(3, self.route_params.as_ref().map(|p| p.final_value_msat), option),
413-
(5, self.route_params.as_ref().map(|p| p.max_total_routing_fee_msat), option),
413+
(5, self.route_params.as_ref().and_then(|p| p.max_total_routing_fee_msat), option),
414414
});
415415
Ok(())
416416
}

lightning/src/util/test_utils.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,18 @@ impl<'a> Router for TestRouter<'a> {
151151
return find_route_res;
152152
}
153153
let logger = TestLogger::new();
154-
find_route(
154+
let route_res = find_route(
155155
payer, params, &self.network_graph, first_hops, &logger,
156156
&ScorerAccountingForInFlightHtlcs::new(self.scorer.read().unwrap(), &inflight_htlcs), &Default::default(),
157157
&[42; 32]
158-
)
158+
);
159+
if let Ok(route) = &route_res {
160+
// Previously, `Route`s failed to round-trip through serialization due to a write/read
161+
// mismatch. Thus, hwere we test all test-generated routes round-trip:
162+
let ser = route.encode();
163+
assert_eq!(Route::read(&mut &ser[..]).unwrap(), *route);
164+
}
165+
route_res
159166
}
160167
}
161168

0 commit comments

Comments
 (0)