Skip to content

Commit

Permalink
Fix Route serialization round-trip
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheBlueMatt committed Feb 16, 2024
1 parent 9de51f0 commit 2c2f39a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lightning/src/routing/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ impl Writeable for Route {
(1, self.route_params.as_ref().map(|p| &p.payment_params), option),
(2, blinded_tails, optional_vec),
(3, self.route_params.as_ref().map(|p| p.final_value_msat), option),
(5, self.route_params.as_ref().map(|p| p.max_total_routing_fee_msat), option),
(5, self.route_params.as_ref().and_then(|p| p.max_total_routing_fee_msat), option),
});
Ok(())
}
Expand Down
11 changes: 9 additions & 2 deletions lightning/src/util/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,18 @@ impl<'a> Router for TestRouter<'a> {
return find_route_res;
}
let logger = TestLogger::new();
find_route(
let route_res = find_route(
payer, params, &self.network_graph, first_hops, &logger,
&ScorerAccountingForInFlightHtlcs::new(self.scorer.read().unwrap(), &inflight_htlcs), &Default::default(),
&[42; 32]
)
);
if let Ok(route) = &route_res {
// Previously, `Route`s failed to round-trip through serialization due to a write/read
// mismatch. Thus, hwere we test all test-generated routes round-trip:
let ser = route.encode();
assert_eq!(Route::read(&mut &ser[..]).unwrap(), *route);
}
route_res
}
}

Expand Down

0 comments on commit 2c2f39a

Please sign in to comment.