X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Ffeatures.rs;h=400888ff9784ff0f8217de151f5b4f24d23509a7;hb=38a2186cb6091f4b041bf18c3fd0e3f714db93b7;hp=0b580b92ad87751a12c53e6700e20f4c53e24c79;hpb=432d1808982e072a1a93a84a18806a5b347ab869;p=rust-lightning diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index 0b580b92..400888ff 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -65,6 +65,12 @@ //! [BOLT-3](https://github.com/lightning/bolts/blob/master/03-transactions.md) for more //! information). //! +//! LDK knows about the following features, but does not support them: +//! - `AnchorsNonzeroFeeHtlcTx` - the initial version of anchor outputs, which was later found to be +//! vulnerable (see this +//! [mailing list post](https://lists.linuxfoundation.org/pipermail/lightning-dev/2020-September/002796.html) +//! for more information). +//! //! [BOLT #9]: https://github.com/lightning/bolts/blob/master/09-features.md //! [messages]: crate::ln::msgs @@ -134,7 +140,7 @@ mod sealed { // Byte 1 VariableLengthOnion | StaticRemoteKey | PaymentSecret, // Byte 2 - BasicMPP | Wumbo | AnchorsZeroFeeHtlcTx, + BasicMPP | Wumbo | AnchorsNonzeroFeeHtlcTx | AnchorsZeroFeeHtlcTx, // Byte 3 ShutdownAnySegwit, // Byte 4 @@ -150,7 +156,7 @@ mod sealed { // Byte 1 VariableLengthOnion | StaticRemoteKey | PaymentSecret, // Byte 2 - BasicMPP | Wumbo | AnchorsZeroFeeHtlcTx, + BasicMPP | Wumbo | AnchorsNonzeroFeeHtlcTx | AnchorsZeroFeeHtlcTx, // Byte 3 ShutdownAnySegwit, // Byte 4 @@ -196,7 +202,7 @@ mod sealed { // Byte 1 StaticRemoteKey, // Byte 2 - AnchorsZeroFeeHtlcTx, + AnchorsNonzeroFeeHtlcTx | AnchorsZeroFeeHtlcTx, // Byte 3 , // Byte 4 @@ -378,6 +384,9 @@ mod sealed { define_feature!(19, Wumbo, [InitContext, NodeContext], "Feature flags for `option_support_large_channel` (aka wumbo channels).", set_wumbo_optional, set_wumbo_required, supports_wumbo, requires_wumbo); + define_feature!(21, AnchorsNonzeroFeeHtlcTx, [InitContext, NodeContext, ChannelTypeContext], + "Feature flags for `option_anchors_nonzero_fee_htlc_tx`.", set_anchors_nonzero_fee_htlc_tx_optional, + set_anchors_nonzero_fee_htlc_tx_required, supports_anchors_nonzero_fee_htlc_tx, requires_anchors_nonzero_fee_htlc_tx); define_feature!(23, AnchorsZeroFeeHtlcTx, [InitContext, NodeContext, ChannelTypeContext], "Feature flags for `option_anchors_zero_fee_htlc_tx`.", set_anchors_zero_fee_htlc_tx_optional, set_anchors_zero_fee_htlc_tx_required, supports_anchors_zero_fee_htlc_tx, requires_anchors_zero_fee_htlc_tx); @@ -453,6 +462,16 @@ impl PartialEq for Features { self.flags.eq(&o.flags) } } +impl PartialOrd for Features { + fn partial_cmp(&self, other: &Self) -> Option { + self.flags.partial_cmp(&other.flags) + } +} +impl Ord for Features { + fn cmp(&self, other: &Self) -> cmp::Ordering { + self.flags.cmp(&other.flags) + } +} impl fmt::Debug for Features { fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { self.flags.fmt(fmt) @@ -525,15 +544,29 @@ impl InvoiceFeatures { /// [`PaymentParameters::for_keysend`], thus omitting the need for payers to manually construct an /// `InvoiceFeatures` for [`find_route`]. /// + /// MPP keysend is not widely supported yet, so we parameterize support to allow the user to + /// choose whether their router should find multi-part routes. + /// /// [`PaymentParameters::for_keysend`]: crate::routing::router::PaymentParameters::for_keysend /// [`find_route`]: crate::routing::router::find_route - pub(crate) fn for_keysend() -> InvoiceFeatures { + pub(crate) fn for_keysend(allow_mpp: bool) -> InvoiceFeatures { let mut res = InvoiceFeatures::empty(); res.set_variable_length_onion_optional(); + if allow_mpp { + res.set_basic_mpp_optional(); + } res } } +impl Bolt12InvoiceFeatures { + /// Converts `Bolt12InvoiceFeatures` to `Features`. Only known `Bolt12InvoiceFeatures` relevant + /// to context `C` are included in the result. + pub(crate) fn to_context(&self) -> Features { + self.to_context_internal() + } +} + impl ChannelTypeFeatures { // Maps the relevant `InitFeatures` to `ChannelTypeFeatures`. Any unknown features to // `ChannelTypeFeatures` are not included in the result. @@ -856,6 +889,7 @@ impl_feature_len_prefixed_write!(InitFeatures); impl_feature_len_prefixed_write!(ChannelFeatures); impl_feature_len_prefixed_write!(NodeFeatures); impl_feature_len_prefixed_write!(InvoiceFeatures); +impl_feature_len_prefixed_write!(Bolt12InvoiceFeatures); impl_feature_len_prefixed_write!(BlindedHopFeatures); // Some features only appear inside of TLVs, so they don't have a length prefix when serialized.