Skip to content

Commit 66ee854

Browse files
committed
Add/announce features for payment_secret and basic_mpp
1 parent 884ca16 commit 66ee854

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

lightning/src/ln/features.rs

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
@@ -188,7 +196,8 @@ impl<T: sealed::Context> Features<T> {
188196
self.flags.iter().enumerate().any(|(idx, &byte)| {
189197
(match idx {
190198
0 => (byte & 0b01000100),
191-
1 => (byte & 0b01010100),
199+
1 => (byte & 0b00010100),
200+
2 => (byte & 0b01010100),
192201
_ => (byte & 0b01010101),
193202
}) != 0
194203
})
@@ -198,7 +207,8 @@ impl<T: sealed::Context> Features<T> {
198207
self.flags.iter().enumerate().any(|(idx, &byte)| {
199208
(match idx {
200209
0 => (byte & 0b11000100),
201-
1 => (byte & 0b11111100),
210+
1 => (byte & 0b00111100),
211+
2 => (byte & 0b11111100),
202212
_ => byte,
203213
}) != 0
204214
})
@@ -212,16 +222,19 @@ impl<T: sealed::Context> Features<T> {
212222

213223
#[cfg(test)]
214224
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());
216226
self.flags.resize(newlen, 0u8);
217-
self.flags[1] |= 0x40;
227+
self.flags[2] |= 0x40;
218228
}
219229

220230
#[cfg(test)]
221231
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());
223233
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+
}
225238
if self.flags.len() == 2 && self.flags[1] == 0 {
226239
self.flags.resize(1, 0u8);
227240
}
@@ -263,6 +276,23 @@ impl<T: sealed::InitialRoutingSync> Features<T> {
263276
}
264277
}
265278

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+
266296
impl<T: sealed::Context> Writeable for Features<T> {
267297
fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
268298
w.size_hint(self.flags.len() + 2);

0 commit comments

Comments
 (0)