From: Matt Corallo Date: Wed, 15 Jan 2020 04:31:21 +0000 (-0500) Subject: Add/announce features for payment_secret and basic_mpp X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=c676cd8bd6d65d1c585488ab94eaa904bde58a6d;p=rust-lightning Add/announce features for payment_secret and basic_mpp --- diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index b87501eb0..641c1ffb6 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -33,6 +33,14 @@ mod sealed { // You should just use the type aliases instead. pub trait VariableLengthOnion: Context {} impl VariableLengthOnion for InitContext {} impl VariableLengthOnion for NodeContext {} + + pub trait PaymentSecret: Context {} + impl PaymentSecret for InitContext {} + impl PaymentSecret for NodeContext {} + + pub trait BasicMPP: Context {} + impl BasicMPP for InitContext {} + impl BasicMPP for NodeContext {} } /// Tracks the set of features which a node implements, templated by the context in which it @@ -73,7 +81,7 @@ impl InitFeatures { /// Create a Features with the features we support pub fn supported() -> InitFeatures { InitFeatures { - flags: vec![2 | 1 << 5, 1 << (9-8)], + flags: vec![2 | 1 << 5, 1 << (9-8) | 1 << (15 - 8), 1 << (17 - 8*2)], mark: PhantomData, } } @@ -136,14 +144,14 @@ impl NodeFeatures { #[cfg(not(feature = "fuzztarget"))] pub(crate) fn supported() -> NodeFeatures { NodeFeatures { - flags: vec![2 | 1 << 5, 1 << (9-8)], + flags: vec![2 | 1 << 5, 1 << (9-8) | 1 << (15 - 8), 1 << (17 - 8*2)], mark: PhantomData, } } #[cfg(feature = "fuzztarget")] pub fn supported() -> NodeFeatures { NodeFeatures { - flags: vec![2 | 1 << 5, 1 << (9-8)], + flags: vec![2 | 1 << 5, 1 << (9-8) | 1 << (15 - 8), 1 << (17 - 8*2)], mark: PhantomData, } } @@ -188,7 +196,8 @@ impl Features { self.flags.iter().enumerate().any(|(idx, &byte)| { (match idx { 0 => (byte & 0b01000100), - 1 => (byte & 0b01010100), + 1 => (byte & 0b00010100), + 2 => (byte & 0b01010100), _ => (byte & 0b01010101), }) != 0 }) @@ -198,7 +207,8 @@ impl Features { self.flags.iter().enumerate().any(|(idx, &byte)| { (match idx { 0 => (byte & 0b11000100), - 1 => (byte & 0b11111100), + 1 => (byte & 0b00111100), + 2 => (byte & 0b11111100), _ => byte, }) != 0 }) @@ -212,16 +222,19 @@ impl Features { #[cfg(test)] pub(crate) fn set_require_unknown_bits(&mut self) { - let newlen = cmp::max(2, self.flags.len()); + let newlen = cmp::max(3, self.flags.len()); self.flags.resize(newlen, 0u8); - self.flags[1] |= 0x40; + self.flags[2] |= 0x40; } #[cfg(test)] pub(crate) fn clear_require_unknown_bits(&mut self) { - let newlen = cmp::max(2, self.flags.len()); + let newlen = cmp::max(3, self.flags.len()); self.flags.resize(newlen, 0u8); - self.flags[1] &= !0x40; + self.flags[2] &= !0x40; + if self.flags.len() == 3 && self.flags[2] == 0 { + self.flags.resize(2, 0u8); + } if self.flags.len() == 2 && self.flags[1] == 0 { self.flags.resize(1, 0u8); } @@ -263,6 +276,23 @@ impl Features { } } +impl Features { + #[allow(dead_code)] + // Note that we never need to test this since what really matters is the invoice - iff the + // invoice provides a payment_secret, we assume all the way through that we can do MPP. + pub(crate) fn payment_secret(&self) -> bool { + self.flags.len() > 1 && (self.flags[1] & (3 << (12-8))) != 0 + } +} + +impl Features { + // We currently never test for this since we don't actually *generate* multipath routes. + #[allow(dead_code)] + pub(crate) fn basic_mpp(&self) -> bool { + self.flags.len() > 2 && (self.flags[2] & (3 << (16-8*2))) != 0 + } +} + impl Writeable for Features { fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { w.size_hint(self.flags.len() + 2);