@@ -33,6 +33,14 @@ mod sealed { // You should just use the type aliases instead.
3333 pub trait VariableLengthOnion : Context { }
3434 impl VariableLengthOnion for InitContext { }
3535 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 { }
3644}
3745
3846/// Tracks the set of features which a node implements, templated by the context in which it
@@ -73,7 +81,7 @@ impl InitFeatures {
7381 /// Create a Features with the features we support
7482 pub fn supported ( ) -> InitFeatures {
7583 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 ) ] ,
7785 mark : PhantomData ,
7886 }
7987 }
@@ -136,14 +144,14 @@ impl NodeFeatures {
136144 #[ cfg( not( feature = "fuzztarget" ) ) ]
137145 pub ( crate ) fn supported ( ) -> NodeFeatures {
138146 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 ) ] ,
140148 mark : PhantomData ,
141149 }
142150 }
143151 #[ cfg( feature = "fuzztarget" ) ]
144152 pub fn supported ( ) -> NodeFeatures {
145153 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 ) ] ,
147155 mark : PhantomData ,
148156 }
149157 }
@@ -199,8 +207,10 @@ impl<T: sealed::Context> Features<T> {
199207 // unknown, upfront_shutdown_script, unknown (actually initial_routing_sync, but it
200208 // is only valid as an optional feature), and data_loss_protect:
201209 0 => ( byte & 0b01000100 ) ,
202- // unknown, unknown, unknown, var_onion_optin:
203- 1 => ( byte & 0b01010100 ) ,
210+ // payment_secret, unknown, unknown, var_onion_optin:
211+ 1 => ( byte & 0b00010100 ) ,
212+ // unknown, unknown, unknown, basic_mpp:
213+ 2 => ( byte & 0b01010100 ) ,
204214 // fallback, all even bits set:
205215 _ => ( byte & 0b01010101 ) ,
206216 } ) != 0
@@ -213,8 +223,10 @@ impl<T: sealed::Context> Features<T> {
213223 // unknown, upfront_shutdown_script, initial_routing_sync (is only valid as an
214224 // optional feature), and data_loss_protect:
215225 0 => ( byte & 0b11000100 ) ,
216- // unknown, unknown, unknown, var_onion_optin:
217- 1 => ( byte & 0b11111100 ) ,
226+ // payment_secret, unknown, unknown, var_onion_optin:
227+ 1 => ( byte & 0b00111100 ) ,
228+ // unknown, unknown, unknown, basic_mpp:
229+ 2 => ( byte & 0b11111100 ) ,
218230 _ => byte,
219231 } ) != 0
220232 } )
@@ -228,16 +240,19 @@ impl<T: sealed::Context> Features<T> {
228240
229241 #[ cfg( test) ]
230242 pub ( crate ) fn set_require_unknown_bits ( & mut self ) {
231- let newlen = cmp:: max ( 2 , self . flags . len ( ) ) ;
243+ let newlen = cmp:: max ( 3 , self . flags . len ( ) ) ;
232244 self . flags . resize ( newlen, 0u8 ) ;
233- self . flags [ 1 ] |= 0x40 ;
245+ self . flags [ 2 ] |= 0x40 ;
234246 }
235247
236248 #[ cfg( test) ]
237249 pub ( crate ) fn clear_require_unknown_bits ( & mut self ) {
238- let newlen = cmp:: max ( 2 , self . flags . len ( ) ) ;
250+ let newlen = cmp:: max ( 3 , self . flags . len ( ) ) ;
239251 self . flags . resize ( newlen, 0u8 ) ;
240- self . flags [ 1 ] &= !0x40 ;
252+ self . flags [ 2 ] &= !0x40 ;
253+ if self . flags . len ( ) == 3 && self . flags [ 2 ] == 0 {
254+ self . flags . resize ( 2 , 0u8 ) ;
255+ }
241256 if self . flags . len ( ) == 2 && self . flags [ 1 ] == 0 {
242257 self . flags . resize ( 1 , 0u8 ) ;
243258 }
@@ -279,6 +294,24 @@ impl<T: sealed::InitialRoutingSync> Features<T> {
279294 }
280295}
281296
297+ impl < T : sealed:: PaymentSecret > Features < T > {
298+ #[ allow( dead_code) ]
299+ // Note that we never need to test this since what really matters is the invoice - iff the
300+ // invoice provides a payment_secret, we assume that we can use it (ie that the recipient
301+ // supports payment_secret).
302+ pub ( crate ) fn payment_secret ( & self ) -> bool {
303+ self . flags . len ( ) > 1 && ( self . flags [ 1 ] & ( 3 << ( 14 -8 ) ) ) != 0
304+ }
305+ }
306+
307+ impl < T : sealed:: BasicMPP > Features < T > {
308+ // We currently never test for this since we don't actually *generate* multipath routes.
309+ #[ allow( dead_code) ]
310+ pub ( crate ) fn basic_mpp ( & self ) -> bool {
311+ self . flags . len ( ) > 2 && ( self . flags [ 2 ] & ( 3 << ( 16 -8 * 2 ) ) ) != 0
312+ }
313+ }
314+
282315impl < T : sealed:: Context > Writeable for Features < T > {
283316 fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
284317 w. size_hint ( self . flags . len ( ) + 2 ) ;
0 commit comments