@@ -23,6 +23,7 @@ use crate::ln::msgs::DecodeError;
23
23
use crate :: offers:: invoice:: BlindedPayInfo ;
24
24
use crate :: offers:: invoice_request:: InvoiceRequestFields ;
25
25
use crate :: offers:: offer:: OfferId ;
26
+ use crate :: routing:: gossip:: DirectedChannelInfo ;
26
27
use crate :: util:: ser:: { HighZeroBytesDroppedBigSize , Readable , Writeable , Writer } ;
27
28
28
29
#[ allow( unused_imports) ]
@@ -170,6 +171,19 @@ impl PaymentContext {
170
171
}
171
172
}
172
173
174
+ impl PaymentRelay {
175
+ fn normalize_cltv_expiry_delta ( cltv_expiry_delta : u16 ) -> Result < u16 , ( ) > {
176
+ // Avoid exposing esoteric CLTV expiry deltas, which could de-anonymize the path.
177
+ match cltv_expiry_delta {
178
+ 0 ..=40 => Ok ( 40 ) ,
179
+ 41 ..=80 => Ok ( 80 ) ,
180
+ 81 ..=144 => Ok ( 144 ) ,
181
+ 145 ..=216 => Ok ( 216 ) ,
182
+ _ => Err ( ( ) ) ,
183
+ }
184
+ }
185
+ }
186
+
173
187
impl TryFrom < CounterpartyForwardingInfo > for PaymentRelay {
174
188
type Error = ( ) ;
175
189
@@ -178,16 +192,25 @@ impl TryFrom<CounterpartyForwardingInfo> for PaymentRelay {
178
192
fee_base_msat, fee_proportional_millionths, cltv_expiry_delta
179
193
} = info;
180
194
181
- // Avoid exposing esoteric CLTV expiry deltas
182
- let cltv_expiry_delta = match cltv_expiry_delta {
183
- 0 ..=40 => 40 ,
184
- 41 ..=80 => 80 ,
185
- 81 ..=144 => 144 ,
186
- 145 ..=216 => 216 ,
187
- _ => return Err ( ( ) ) ,
188
- } ;
195
+ Ok ( Self {
196
+ cltv_expiry_delta : Self :: normalize_cltv_expiry_delta ( cltv_expiry_delta) ?,
197
+ fee_proportional_millionths,
198
+ fee_base_msat
199
+ } )
200
+ }
201
+ }
202
+
203
+ impl < ' a > TryFrom < DirectedChannelInfo < ' a > > for PaymentRelay {
204
+ type Error = ( ) ;
205
+
206
+ fn try_from ( info : DirectedChannelInfo < ' a > ) -> Result < Self , ( ) > {
207
+ let direction = info. direction ( ) ;
189
208
190
- Ok ( Self { cltv_expiry_delta, fee_proportional_millionths, fee_base_msat } )
209
+ Ok ( Self {
210
+ cltv_expiry_delta : Self :: normalize_cltv_expiry_delta ( direction. cltv_expiry_delta ) ?,
211
+ fee_proportional_millionths : direction. fees . proportional_millionths ,
212
+ fee_base_msat : direction. fees . base_msat ,
213
+ } )
191
214
}
192
215
}
193
216
0 commit comments