Skip to content

Commit b435384

Browse files
authored
Merge pull request #2900 from TheBlueMatt/2024-02-fix-route-ser-117-bindings
[117-bindings] Fix Route serialization round-trip
2 parents 4b81eb2 + 795000c commit b435384

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
@@ -390,28 +390,28 @@ 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
410410
// RouteParameters' fields and reconstruct them on read.
411411
(1, self.route_params.as_ref().map(|p| &p.payment_params), option),
412412
(2, blinded_tails, optional_vec),
413413
(3, self.route_params.as_ref().map(|p| p.final_value_msat), option),
414-
(5, self.route_params.as_ref().map(|p| p.max_total_routing_fee_msat), option),
414+
(5, self.route_params.as_ref().and_then(|p| p.max_total_routing_fee_msat), option),
415415
});
416416
Ok(())
417417
}

0 commit comments

Comments
 (0)