From 2ada7911b191f8761dde16b2c78eb5ba92bd4800 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 16 Feb 2024 18:41:54 +0000 Subject: [PATCH] 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. --- lightning/src/routing/router.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index f298f2784..42e7f76da 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -505,20 +505,20 @@ impl Writeable for Route { write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION); (self.paths.len() as u64).write(writer)?; let mut blinded_tails = Vec::new(); - for path in self.paths.iter() { + for (idx, path) in self.paths.iter().enumerate() { (path.hops.len() as u8).write(writer)?; - for (idx, hop) in path.hops.iter().enumerate() { + for hop in path.hops.iter() { hop.write(writer)?; - if let Some(blinded_tail) = &path.blinded_tail { - if blinded_tails.is_empty() { - blinded_tails = Vec::with_capacity(path.hops.len()); - for _ in 0..idx { - blinded_tails.push(None); - } - } - blinded_tails.push(Some(blinded_tail)); - } else if !blinded_tails.is_empty() { blinded_tails.push(None); } } + if let Some(blinded_tail) = &path.blinded_tail { + if blinded_tails.is_empty() { + blinded_tails = Vec::with_capacity(path.hops.len()); + for _ in 0..idx { + blinded_tails.push(None); + } + } + blinded_tails.push(Some(blinded_tail)); + } else if !blinded_tails.is_empty() { blinded_tails.push(None); } } write_tlv_fields!(writer, { // For compatibility with LDK versions prior to 0.0.117, we take the individual -- 2.39.5