Skip to content

Commit d429065

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 f8b0800 commit d429065

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lightning/src/routing/router.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -508,20 +508,20 @@ impl Writeable for Route {
508508
write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
509509
(self.paths.len() as u64).write(writer)?;
510510
let mut blinded_tails = Vec::new();
511-
for path in self.paths.iter() {
511+
for (idx, path) in self.paths.iter().enumerate() {
512512
(path.hops.len() as u8).write(writer)?;
513-
for (idx, hop) in path.hops.iter().enumerate() {
513+
for hop in path.hops.iter() {
514514
hop.write(writer)?;
515-
if let Some(blinded_tail) = &path.blinded_tail {
516-
if blinded_tails.is_empty() {
517-
blinded_tails = Vec::with_capacity(path.hops.len());
518-
for _ in 0..idx {
519-
blinded_tails.push(None);
520-
}
521-
}
522-
blinded_tails.push(Some(blinded_tail));
523-
} else if !blinded_tails.is_empty() { blinded_tails.push(None); }
524515
}
516+
if let Some(blinded_tail) = &path.blinded_tail {
517+
if blinded_tails.is_empty() {
518+
blinded_tails = Vec::with_capacity(path.hops.len());
519+
for _ in 0..idx {
520+
blinded_tails.push(None);
521+
}
522+
}
523+
blinded_tails.push(Some(blinded_tail));
524+
} else if !blinded_tails.is_empty() { blinded_tails.push(None); }
525525
}
526526
write_tlv_fields!(writer, {
527527
// For compatibility with LDK versions prior to 0.0.117, we take the individual

0 commit comments

Comments
 (0)