Skip to content

Commit 161ee62

Browse files
authored
Merge pull request #2901 from TheBlueMatt/2024-02-fix-route-ser-118-bindings
[118-bindings] Fix Route serialization round-trip
2 parents 5df414c + 8ad35c5 commit 161ee62

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

lightning/src/routing/router.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -391,28 +391,28 @@ impl Writeable for Route {
391391
write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
392392
(self.paths.len() as u64).write(writer)?;
393393
let mut blinded_tails = Vec::new();
394-
for path in self.paths.iter() {
394+
for (idx, path) in self.paths.iter().enumerate() {
395395
(path.hops.len() as u8).write(writer)?;
396-
for (idx, hop) in path.hops.iter().enumerate() {
396+
for hop in path.hops.iter() {
397397
hop.write(writer)?;
398-
if let Some(blinded_tail) = &path.blinded_tail {
399-
if blinded_tails.is_empty() {
400-
blinded_tails = Vec::with_capacity(path.hops.len());
401-
for _ in 0..idx {
402-
blinded_tails.push(None);
403-
}
404-
}
405-
blinded_tails.push(Some(blinded_tail));
406-
} else if !blinded_tails.is_empty() { blinded_tails.push(None); }
407398
}
399+
if let Some(blinded_tail) = &path.blinded_tail {
400+
if blinded_tails.is_empty() {
401+
blinded_tails = Vec::with_capacity(path.hops.len());
402+
for _ in 0..idx {
403+
blinded_tails.push(None);
404+
}
405+
}
406+
blinded_tails.push(Some(blinded_tail));
407+
} else if !blinded_tails.is_empty() { blinded_tails.push(None); }
408408
}
409409
write_tlv_fields!(writer, {
410410
// For compatibility with LDK versions prior to 0.0.117, we take the individual
411411
// RouteParameters' fields and reconstruct them on read.
412412
(1, self.route_params.as_ref().map(|p| &p.payment_params), option),
413413
(2, blinded_tails, optional_vec),
414414
(3, self.route_params.as_ref().map(|p| p.final_value_msat), option),
415-
(5, self.route_params.as_ref().map(|p| p.max_total_routing_fee_msat), option),
415+
(5, self.route_params.as_ref().and_then(|p| p.max_total_routing_fee_msat), option),
416416
});
417417
Ok(())
418418
}

0 commit comments

Comments
 (0)