Skip to content

Commit e2108f2

Browse files
authored
Merge pull request #2902 from TheBlueMatt/2024-02-fix-route-ser-121-bindings
[121-bindings] Fix Route serialization round-trip
2 parents c57cd65 + 1036549 commit e2108f2

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
@@ -502,28 +502,28 @@ impl Writeable for Route {
502502
write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
503503
(self.paths.len() as u64).write(writer)?;
504504
let mut blinded_tails = Vec::new();
505-
for path in self.paths.iter() {
505+
for (idx, path) in self.paths.iter().enumerate() {
506506
(path.hops.len() as u8).write(writer)?;
507-
for (idx, hop) in path.hops.iter().enumerate() {
507+
for hop in path.hops.iter() {
508508
hop.write(writer)?;
509-
if let Some(blinded_tail) = &path.blinded_tail {
510-
if blinded_tails.is_empty() {
511-
blinded_tails = Vec::with_capacity(path.hops.len());
512-
for _ in 0..idx {
513-
blinded_tails.push(None);
514-
}
515-
}
516-
blinded_tails.push(Some(blinded_tail));
517-
} else if !blinded_tails.is_empty() { blinded_tails.push(None); }
518509
}
510+
if let Some(blinded_tail) = &path.blinded_tail {
511+
if blinded_tails.is_empty() {
512+
blinded_tails = Vec::with_capacity(path.hops.len());
513+
for _ in 0..idx {
514+
blinded_tails.push(None);
515+
}
516+
}
517+
blinded_tails.push(Some(blinded_tail));
518+
} else if !blinded_tails.is_empty() { blinded_tails.push(None); }
519519
}
520520
write_tlv_fields!(writer, {
521521
// For compatibility with LDK versions prior to 0.0.117, we take the individual
522522
// RouteParameters' fields and reconstruct them on read.
523523
(1, self.route_params.as_ref().map(|p| &p.payment_params), option),
524524
(2, blinded_tails, optional_vec),
525525
(3, self.route_params.as_ref().map(|p| p.final_value_msat), option),
526-
(5, self.route_params.as_ref().map(|p| p.max_total_routing_fee_msat), option),
526+
(5, self.route_params.as_ref().and_then(|p| p.max_total_routing_fee_msat), option),
527527
});
528528
Ok(())
529529
}

0 commit comments

Comments
 (0)