X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fblinded_path%2Fpayment.rs;h=5d332a76faf57fed3b2fe844b91d5c5d04ed8a81;hb=7c9463668a4f71663746e57bdb09ee6b91797d5a;hp=7b604fbdcb1d8af0a6dffbdfd40b1898d7d19d52;hpb=d2222c8224923feb90c1b0efd3ef920d56f342f9;p=rust-lightning diff --git a/lightning/src/blinded_path/payment.rs b/lightning/src/blinded_path/payment.rs index 7b604fbd..5d332a76 100644 --- a/lightning/src/blinded_path/payment.rs +++ b/lightning/src/blinded_path/payment.rs @@ -8,6 +8,7 @@ use crate::blinded_path::BlindedHop; use crate::blinded_path::utils; use crate::io; use crate::ln::PaymentSecret; +use crate::ln::channelmanager::CounterpartyForwardingInfo; use crate::ln::features::BlindedHopFeatures; use crate::ln::msgs::DecodeError; use crate::offers::invoice::BlindedPayInfo; @@ -96,6 +97,27 @@ pub struct PaymentConstraints { pub htlc_minimum_msat: u64, } +impl TryFrom for PaymentRelay { + type Error = (); + + fn try_from(info: CounterpartyForwardingInfo) -> Result { + let CounterpartyForwardingInfo { + fee_base_msat, fee_proportional_millionths, cltv_expiry_delta + } = info; + + // Avoid exposing esoteric CLTV expiry deltas + let cltv_expiry_delta = match cltv_expiry_delta { + 0..=40 => 40, + 41..=80 => 80, + 81..=144 => 144, + 145..=216 => 216, + _ => return Err(()), + }; + + Ok(Self { cltv_expiry_delta, fee_proportional_millionths, fee_base_msat }) + } +} + impl Writeable for ForwardTlvs { fn write(&self, w: &mut W) -> Result<(), io::Error> { encode_tlv_stream!(w, {