Skip to content

Commit de72542

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 4b81eb2 commit de72542

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
@@ -390,20 +390,20 @@ impl Writeable for Route {
390390
write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
391391
(self.paths.len() as u64).write(writer)?;
392392
let mut blinded_tails = Vec::new();
393-
for path in self.paths.iter() {
393+
for (idx, path) in self.paths.iter().enumerate() {
394394
(path.hops.len() as u8).write(writer)?;
395-
for (idx, hop) in path.hops.iter().enumerate() {
395+
for hop in path.hops.iter() {
396396
hop.write(writer)?;
397-
if let Some(blinded_tail) = &path.blinded_tail {
398-
if blinded_tails.is_empty() {
399-
blinded_tails = Vec::with_capacity(path.hops.len());
400-
for _ in 0..idx {
401-
blinded_tails.push(None);
402-
}
403-
}
404-
blinded_tails.push(Some(blinded_tail));
405-
} else if !blinded_tails.is_empty() { blinded_tails.push(None); }
406397
}
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); }
407407
}
408408
write_tlv_fields!(writer, {
409409
// For compatibility with LDK versions prior to 0.0.117, we take the individual

0 commit comments

Comments
 (0)