Skip to content

Commit 4bb7257

Browse files
Support (de)serializing Path::blinded_tails in Routes
1 parent 4f74ba0 commit 4bb7257

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lightning/src/routing/router.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,14 +344,23 @@ impl Writeable for Route {
344344
fn write<W: crate::util::ser::Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
345345
write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
346346
(self.paths.len() as u64).write(writer)?;
347+
let mut blinded_tails = None;
347348
for path in self.paths.iter() {
348349
(path.hops.len() as u8).write(writer)?;
349350
for hop in path.hops.iter() {
350351
hop.write(writer)?;
352+
if let Some(blinded_tail) = &path.blinded_tail {
353+
if blinded_tails.is_none() { blinded_tails = Some(Vec::new()); }
354+
blinded_tails.as_mut().map(|tails| tails.push(blinded_tail));
355+
}
351356
}
352357
}
358+
if blinded_tails.is_some() && blinded_tails.as_ref().unwrap().len() != self.paths.len() {
359+
return Err(io::Error::new(io::ErrorKind::Other, "Missing blinded tail for path (if blinded tails are included, there must be 1 set per path)"))
360+
}
353361
write_tlv_fields!(writer, {
354362
(1, self.payment_params, option),
363+
(2, blinded_tails, option),
355364
});
356365
Ok(())
357366
}
@@ -375,10 +384,17 @@ impl Readable for Route {
375384
cmp::min(min_final_cltv_expiry_delta, hops.last().unwrap().cltv_expiry_delta);
376385
paths.push(Path { hops, blinded_tail: None });
377386
}
378-
let mut payment_params = None;
379-
read_tlv_fields!(reader, {
387+
_init_and_read_tlv_fields!(reader, {
380388
(1, payment_params, (option: ReadableArgs, min_final_cltv_expiry_delta)),
389+
(2, blinded_tails, vec_type),
381390
});
391+
let blinded_tails = blinded_tails.unwrap_or(Vec::new());
392+
if blinded_tails.len() != 0 {
393+
if blinded_tails.len() != paths.len() { return Err(DecodeError::InvalidValue) }
394+
for (mut path, blinded_tail) in paths.iter_mut().zip(blinded_tails.into_iter()) {
395+
path.blinded_tail = Some(blinded_tail);
396+
}
397+
}
382398
Ok(Route { paths, payment_params })
383399
}
384400
}

lightning/src/util/ser.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,8 @@ impl Readable for Vec<u8> {
814814
impl_for_vec!(ecdsa::Signature);
815815
impl_for_vec!(crate::ln::channelmanager::MonitorUpdateCompletionAction);
816816
impl_for_vec!((A, B), A, B);
817+
impl_writeable_for_vec!(&crate::routing::router::BlindedTail);
818+
impl_readable_for_vec!(crate::routing::router::BlindedTail);
817819

818820
impl Writeable for Script {
819821
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {

0 commit comments

Comments
 (0)