@@ -33,6 +33,14 @@ mod sealed { // You should just use the type aliases instead.
33
33
pub trait VariableLengthOnion : Context { }
34
34
impl VariableLengthOnion for InitContext { }
35
35
impl VariableLengthOnion for NodeContext { }
36
+
37
+ pub trait PaymentSecret : Context { }
38
+ impl PaymentSecret for InitContext { }
39
+ impl PaymentSecret for NodeContext { }
40
+
41
+ pub trait BasicMPP : Context { }
42
+ impl BasicMPP for InitContext { }
43
+ impl BasicMPP for NodeContext { }
36
44
}
37
45
38
46
/// Tracks the set of features which a node implements, templated by the context in which it
@@ -73,7 +81,7 @@ impl InitFeatures {
73
81
/// Create a Features with the features we support
74
82
pub fn supported ( ) -> InitFeatures {
75
83
InitFeatures {
76
- flags : vec ! [ 2 | 1 << 5 , 1 << ( 9 -8 ) ] ,
84
+ flags : vec ! [ 2 | 1 << 5 , 1 << ( 9 -8 ) | 1 << ( 15 - 8 ) , 1 << ( 17 - 8 * 2 ) ] ,
77
85
mark : PhantomData ,
78
86
}
79
87
}
@@ -136,14 +144,14 @@ impl NodeFeatures {
136
144
#[ cfg( not( feature = "fuzztarget" ) ) ]
137
145
pub ( crate ) fn supported ( ) -> NodeFeatures {
138
146
NodeFeatures {
139
- flags : vec ! [ 2 | 1 << 5 , 1 << ( 9 -8 ) ] ,
147
+ flags : vec ! [ 2 | 1 << 5 , 1 << ( 9 -8 ) | 1 << ( 15 - 8 ) , 1 << ( 17 - 8 * 2 ) ] ,
140
148
mark : PhantomData ,
141
149
}
142
150
}
143
151
#[ cfg( feature = "fuzztarget" ) ]
144
152
pub fn supported ( ) -> NodeFeatures {
145
153
NodeFeatures {
146
- flags : vec ! [ 2 | 1 << 5 , 1 << ( 9 -8 ) ] ,
154
+ flags : vec ! [ 2 | 1 << 5 , 1 << ( 9 -8 ) | 1 << ( 15 - 8 ) , 1 << ( 17 - 8 * 2 ) ] ,
147
155
mark : PhantomData ,
148
156
}
149
157
}
@@ -188,7 +196,8 @@ impl<T: sealed::Context> Features<T> {
188
196
self . flags . iter ( ) . enumerate ( ) . any ( |( idx, & byte) | {
189
197
( match idx {
190
198
0 => ( byte & 0b01000100 ) ,
191
- 1 => ( byte & 0b01010100 ) ,
199
+ 1 => ( byte & 0b00010100 ) ,
200
+ 2 => ( byte & 0b01010100 ) ,
192
201
_ => ( byte & 0b01010101 ) ,
193
202
} ) != 0
194
203
} )
@@ -198,7 +207,8 @@ impl<T: sealed::Context> Features<T> {
198
207
self . flags . iter ( ) . enumerate ( ) . any ( |( idx, & byte) | {
199
208
( match idx {
200
209
0 => ( byte & 0b11000100 ) ,
201
- 1 => ( byte & 0b11111100 ) ,
210
+ 1 => ( byte & 0b00111100 ) ,
211
+ 2 => ( byte & 0b11111100 ) ,
202
212
_ => byte,
203
213
} ) != 0
204
214
} )
@@ -212,16 +222,19 @@ impl<T: sealed::Context> Features<T> {
212
222
213
223
#[ cfg( test) ]
214
224
pub ( crate ) fn set_require_unknown_bits ( & mut self ) {
215
- let newlen = cmp:: max ( 2 , self . flags . len ( ) ) ;
225
+ let newlen = cmp:: max ( 3 , self . flags . len ( ) ) ;
216
226
self . flags . resize ( newlen, 0u8 ) ;
217
- self . flags [ 1 ] |= 0x40 ;
227
+ self . flags [ 2 ] |= 0x40 ;
218
228
}
219
229
220
230
#[ cfg( test) ]
221
231
pub ( crate ) fn clear_require_unknown_bits ( & mut self ) {
222
- let newlen = cmp:: max ( 2 , self . flags . len ( ) ) ;
232
+ let newlen = cmp:: max ( 3 , self . flags . len ( ) ) ;
223
233
self . flags . resize ( newlen, 0u8 ) ;
224
- self . flags [ 1 ] &= !0x40 ;
234
+ self . flags [ 2 ] &= !0x40 ;
235
+ if self . flags . len ( ) == 3 && self . flags [ 2 ] == 0 {
236
+ self . flags . resize ( 2 , 0u8 ) ;
237
+ }
225
238
if self . flags . len ( ) == 2 && self . flags [ 1 ] == 0 {
226
239
self . flags . resize ( 1 , 0u8 ) ;
227
240
}
@@ -263,6 +276,23 @@ impl<T: sealed::InitialRoutingSync> Features<T> {
263
276
}
264
277
}
265
278
279
+ impl < T : sealed:: PaymentSecret > Features < T > {
280
+ #[ allow( dead_code) ]
281
+ // Note that we never need to test this since what really matters is the invoice - iff the
282
+ // invoice provides a payment_secret, we assume all the way through that we can do MPP.
283
+ pub ( crate ) fn payment_secret ( & self ) -> bool {
284
+ self . flags . len ( ) > 1 && ( self . flags [ 1 ] & ( 3 << ( 12 -8 ) ) ) != 0
285
+ }
286
+ }
287
+
288
+ impl < T : sealed:: BasicMPP > Features < T > {
289
+ // We currently never test for this since we don't actually *generate* multipath routes.
290
+ #[ allow( dead_code) ]
291
+ pub ( crate ) fn basic_mpp ( & self ) -> bool {
292
+ self . flags . len ( ) > 2 && ( self . flags [ 2 ] & ( 3 << ( 16 -8 * 2 ) ) ) != 0
293
+ }
294
+ }
295
+
266
296
impl < T : sealed:: Context > Writeable for Features < T > {
267
297
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
268
298
w. size_hint ( self . flags . len ( ) + 2 ) ;
0 commit comments