Skip to content

Commit 8053aa3

Browse files
committed
Use consistent cltv_expiry_delta in ForwardTlvs
When converting from CounterpartyForwardingInfo to PaymentRelay, the cltv_expiry_delta is copied. Then, when forming a blinded payment path, the value is mutated so that esoteric values don't reveal information about the path. However, the value was only used in computing PaymentConstraints and wasn't actually updated in PaymentRelay. Move the logic for modifying the cltv_expiry_delta to the conversion code to avoid this inconsistency.
1 parent ea5de93 commit 8053aa3

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

lightning/src/blinded_path/payment.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,24 @@ pub struct PaymentConstraints {
9797
pub htlc_minimum_msat: u64,
9898
}
9999

100-
impl From<CounterpartyForwardingInfo> for PaymentRelay {
101-
fn from(info: CounterpartyForwardingInfo) -> Self {
100+
impl TryFrom<CounterpartyForwardingInfo> for PaymentRelay {
101+
type Error = ();
102+
103+
fn try_from(info: CounterpartyForwardingInfo) -> Result<Self, ()> {
102104
let CounterpartyForwardingInfo {
103105
fee_base_msat, fee_proportional_millionths, cltv_expiry_delta
104106
} = info;
105-
Self { cltv_expiry_delta, fee_proportional_millionths, fee_base_msat }
107+
108+
// Avoid exposing esoteric CLTV expiry deltas
109+
let cltv_expiry_delta = match cltv_expiry_delta {
110+
0..=40 => 40,
111+
41..=80 => 80,
112+
81..=144 => 144,
113+
145..=216 => 216,
114+
_ => return Err(()),
115+
};
116+
117+
Ok(Self { cltv_expiry_delta, fee_proportional_millionths, fee_base_msat })
106118
}
107119
}
108120

lightning/src/routing/router.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,14 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, S: Deref, SP: Sized,
114114
None => return None,
115115
};
116116
let payment_relay: PaymentRelay = match details.counterparty.forwarding_info {
117-
Some(forwarding_info) => forwarding_info.into(),
117+
Some(forwarding_info) => match forwarding_info.try_into() {
118+
Ok(payment_relay) => payment_relay,
119+
Err(()) => return None,
120+
},
118121
None => return None,
119122
};
120123

121-
// Avoid exposing esoteric CLTV expiry deltas
122-
let cltv_expiry_delta = match payment_relay.cltv_expiry_delta {
123-
0..=40 => 40u32,
124-
41..=80 => 80u32,
125-
81..=144 => 144u32,
126-
145..=216 => 216u32,
127-
_ => return None,
128-
};
129-
124+
let cltv_expiry_delta = payment_relay.cltv_expiry_delta as u32;
130125
let payment_constraints = PaymentConstraints {
131126
max_cltv_expiry: tlvs.payment_constraints.max_cltv_expiry + cltv_expiry_delta,
132127
htlc_minimum_msat: details.inbound_htlc_minimum_msat.unwrap_or(0),

0 commit comments

Comments
 (0)