Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ser for PaymentRelay and PaymentConstraints #2936

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions lightning/src/blinded_path/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<W: Writer>(&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: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
let cltv_expiry_delta: u16 = Readable::read(r)?;
let fee_proportional_millionths: u32 = Readable::read(r)?;
let fee_base_msat: HighZeroBytesDroppedBigSize<u32> = 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<W: Writer>(&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: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
let max_cltv_expiry: u32 = Readable::read(r)?;
let htlc_minimum_msat: HighZeroBytesDroppedBigSize<u64> = Readable::read(r)?;
Ok(Self { max_cltv_expiry, htlc_minimum_msat: htlc_minimum_msat.0 })
}
}

#[cfg(test)]
mod tests {
Expand Down
7 changes: 7 additions & 0 deletions pending_changelog/relay-constraints-ser.txt
Original file line number Diff line number Diff line change
@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not write release notes with the technical internal details, but rather focus on the resulting behavior that is user-facing.

`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.
Loading