Use consistent cltv_expiry_delta in ForwardTlvs
[rust-lightning] / lightning / src / blinded_path / payment.rs
index f4df1e379d931b3ac65cbcdae65441c629554c6c..5d332a76faf57fed3b2fe844b91d5c5d04ed8a81 100644 (file)
@@ -97,12 +97,24 @@ pub struct PaymentConstraints {
        pub htlc_minimum_msat: u64,
 }
 
-impl From<CounterpartyForwardingInfo> for PaymentRelay {
-       fn from(info: CounterpartyForwardingInfo) -> Self {
+impl TryFrom<CounterpartyForwardingInfo> for PaymentRelay {
+       type Error = ();
+
+       fn try_from(info: CounterpartyForwardingInfo) -> Result<Self, ()> {
                let CounterpartyForwardingInfo {
                        fee_base_msat, fee_proportional_millionths, cltv_expiry_delta
                } = info;
-               Self { cltv_expiry_delta, fee_proportional_millionths, fee_base_msat }
+
+               // 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 })
        }
 }