From ef02b9e6f9caf1ce7a6bf625dc8b4b445d5cc699 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Thu, 14 Mar 2024 15:19:10 -0400 Subject: [PATCH] Fix ser for PaymentRelay and PaymentConstraints. Two fields were serialized as u32/u64 when the spec said *tu32/tu64*. /facepalm. --- lightning/src/blinded_path/payment.rs | 39 +++++++++++++++------ pending_changelog/relay-constraints-ser.txt | 7 ++++ 2 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 pending_changelog/relay-constraints-ser.txt diff --git a/lightning/src/blinded_path/payment.rs b/lightning/src/blinded_path/payment.rs index 5d332a76f..7f938d661 100644 --- a/lightning/src/blinded_path/payment.rs +++ b/lightning/src/blinded_path/payment.rs @@ -13,7 +13,7 @@ use crate::ln::features::BlindedHopFeatures; use crate::ln::msgs::DecodeError; use crate::offers::invoice::BlindedPayInfo; use crate::prelude::*; -use crate::util::ser::{Readable, Writeable, Writer}; +use crate::util::ser::{HighZeroBytesDroppedBigSize, Readable, Writeable, Writer}; use core::convert::TryFrom; @@ -275,16 +275,35 @@ pub(super) fn compute_payinfo( }) } -impl_writeable_msg!(PaymentRelay, { - cltv_expiry_delta, - fee_proportional_millionths, - fee_base_msat -}, {}); +impl Writeable for PaymentRelay { + fn write(&self, w: &mut W) -> Result<(), io::Error> { + self.cltv_expiry_delta.write(w)?; + self.fee_proportional_millionths.write(w)?; + HighZeroBytesDroppedBigSize(self.fee_base_msat).write(w) + } +} +impl Readable for PaymentRelay { + fn read(r: &mut R) -> Result { + let cltv_expiry_delta: u16 = Readable::read(r)?; + let fee_proportional_millionths: u32 = Readable::read(r)?; + let fee_base_msat: HighZeroBytesDroppedBigSize = Readable::read(r)?; + Ok(Self { cltv_expiry_delta, fee_proportional_millionths, fee_base_msat: fee_base_msat.0 }) + } +} -impl_writeable_msg!(PaymentConstraints, { - max_cltv_expiry, - htlc_minimum_msat -}, {}); +impl Writeable for PaymentConstraints { + fn write(&self, w: &mut W) -> Result<(), io::Error> { + self.max_cltv_expiry.write(w)?; + HighZeroBytesDroppedBigSize(self.htlc_minimum_msat).write(w) + } +} +impl Readable for PaymentConstraints { + fn read(r: &mut R) -> Result { + let max_cltv_expiry: u32 = Readable::read(r)?; + let htlc_minimum_msat: HighZeroBytesDroppedBigSize = Readable::read(r)?; + Ok(Self { max_cltv_expiry, htlc_minimum_msat: htlc_minimum_msat.0 }) + } +} #[cfg(test)] mod tests { diff --git a/pending_changelog/relay-constraints-ser.txt b/pending_changelog/relay-constraints-ser.txt new file mode 100644 index 000000000..f0da509b9 --- /dev/null +++ b/pending_changelog/relay-constraints-ser.txt @@ -0,0 +1,7 @@ +## Bug fixes + +* LDK previously serialized `PaymentRelay::fee_base_msat` as a u32 when it + should have been serialized as a tu32. Similarly, we were serializing + `PaymentConstraints::htlc_minimum_msat` as a u64 when we should have been + serializing it as tu64. This caused lack of interoperability when using other + implementations as forwarding nodes along blinded payment paths. -- 2.39.5