Skip to content

Commit 2ada791

Browse files
committed
Fix blinded path serialization in Route
`Route`'s blinded_path serialization logic writes a blinded path `Option` per path hop, however on read we (correctly) only read one blinded path `Option` per path. This causes serialization of `Route`s with blinded paths to fail to round-trip. Here we fix this by writing blinded paths per path.
1 parent f3067b8 commit 2ada791

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lightning/src/routing/router.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -505,20 +505,20 @@ impl Writeable for Route {
505505
write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
506506
(self.paths.len() as u64).write(writer)?;
507507
let mut blinded_tails = Vec::new();
508-
for path in self.paths.iter() {
508+
for (idx, path) in self.paths.iter().enumerate() {
509509
(path.hops.len() as u8).write(writer)?;
510-
for (idx, hop) in path.hops.iter().enumerate() {
510+
for hop in path.hops.iter() {
511511
hop.write(writer)?;
512-
if let Some(blinded_tail) = &path.blinded_tail {
513-
if blinded_tails.is_empty() {
514-
blinded_tails = Vec::with_capacity(path.hops.len());
515-
for _ in 0..idx {
516-
blinded_tails.push(None);
517-
}
518-
}
519-
blinded_tails.push(Some(blinded_tail));
520-
} else if !blinded_tails.is_empty() { blinded_tails.push(None); }
521512
}
513+
if let Some(blinded_tail) = &path.blinded_tail {
514+
if blinded_tails.is_empty() {
515+
blinded_tails = Vec::with_capacity(path.hops.len());
516+
for _ in 0..idx {
517+
blinded_tails.push(None);
518+
}
519+
}
520+
blinded_tails.push(Some(blinded_tail));
521+
} else if !blinded_tails.is_empty() { blinded_tails.push(None); }
522522
}
523523
write_tlv_fields!(writer, {
524524
// For compatibility with LDK versions prior to 0.0.117, we take the individual

0 commit comments

Comments
 (0)