@@ -13,6 +13,7 @@ use crate::ln::features::BlindedHopFeatures;
13
13
use crate :: ln:: msgs:: DecodeError ;
14
14
use crate :: offers:: invoice:: BlindedPayInfo ;
15
15
use crate :: prelude:: * ;
16
+ use crate :: routing:: gossip:: DirectedChannelInfo ;
16
17
use crate :: util:: ser:: { Readable , Writeable , Writer } ;
17
18
18
19
use core:: convert:: TryFrom ;
@@ -97,6 +98,19 @@ pub struct PaymentConstraints {
97
98
pub htlc_minimum_msat : u64 ,
98
99
}
99
100
101
+ impl PaymentRelay {
102
+ fn normalize_cltv_expiry_delta ( cltv_expiry_delta : u16 ) -> Result < u16 , ( ) > {
103
+ // Avoid exposing esoteric CLTV expiry deltas, which could de-anonymize the path.
104
+ match cltv_expiry_delta {
105
+ 0 ..=40 => Ok ( 40 ) ,
106
+ 41 ..=80 => Ok ( 80 ) ,
107
+ 81 ..=144 => Ok ( 144 ) ,
108
+ 145 ..=216 => Ok ( 216 ) ,
109
+ _ => Err ( ( ) ) ,
110
+ }
111
+ }
112
+ }
113
+
100
114
impl TryFrom < CounterpartyForwardingInfo > for PaymentRelay {
101
115
type Error = ( ) ;
102
116
@@ -105,16 +119,25 @@ impl TryFrom<CounterpartyForwardingInfo> for PaymentRelay {
105
119
fee_base_msat, fee_proportional_millionths, cltv_expiry_delta
106
120
} = info;
107
121
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
- } ;
122
+ Ok ( Self {
123
+ cltv_expiry_delta : Self :: normalize_cltv_expiry_delta ( cltv_expiry_delta) ?,
124
+ fee_proportional_millionths,
125
+ fee_base_msat
126
+ } )
127
+ }
128
+ }
129
+
130
+ impl < ' a > TryFrom < DirectedChannelInfo < ' a > > for PaymentRelay {
131
+ type Error = ( ) ;
132
+
133
+ fn try_from ( info : DirectedChannelInfo < ' a > ) -> Result < Self , ( ) > {
134
+ let direction = info. direction ( ) ;
116
135
117
- Ok ( Self { cltv_expiry_delta, fee_proportional_millionths, fee_base_msat } )
136
+ Ok ( Self {
137
+ cltv_expiry_delta : Self :: normalize_cltv_expiry_delta ( direction. cltv_expiry_delta ) ?,
138
+ fee_proportional_millionths : direction. fees . proportional_millionths ,
139
+ fee_base_msat : direction. fees . base_msat ,
140
+ } )
118
141
}
119
142
}
120
143
0 commit comments