diff --git a/plugins/lsps-plugin/src/client.rs b/plugins/lsps-plugin/src/client.rs index fafa36c4c..6116fa4a0 100644 --- a/plugins/lsps-plugin/src/client.rs +++ b/plugins/lsps-plugin/src/client.rs @@ -591,9 +591,7 @@ async fn ensure_lsp_connected(cln_client: &mut ClnRpc, lsp_id: &str) -> Result<( // Check that feature bit is set peer.features.as_deref().map_or(false, |f_str| { if let Some(feature_bits) = hex::decode(f_str).ok() { - let mut fb = feature_bits.clone(); - fb.reverse(); - util::is_feature_bit_set(&fb, LSP_FEATURE_BIT) + util::is_feature_bit_set_reversed(&feature_bits, LSP_FEATURE_BIT) } else { false } diff --git a/plugins/lsps-plugin/src/util.rs b/plugins/lsps-plugin/src/util.rs index fe61bb376..06784911d 100644 --- a/plugins/lsps-plugin/src/util.rs +++ b/plugins/lsps-plugin/src/util.rs @@ -5,6 +5,32 @@ use core::fmt; use serde_json::Value; use std::str::FromStr; +/// Checks whether a feature bit is set in a bitmap interpreted as +/// **big-endian across bytes**, while keeping **LSB-first within each byte**. +/// +/// This function creates a reversed copy of `bitmap` (so the least-significant +/// byte becomes last), then calls the simple LSB-first `is_feature_bit_set` on it. +/// No mutation of the caller’s slice occurs. +/// +/// In other words: +/// - byte order: **reversed** (big-endian across the slice) +/// - bit order within a byte: **LSB-first** (unchanged) +/// +/// If you need *full* MSB-first (also within a byte), don’t use this helper— +/// rewrite the mask as `1u8 << (7 - bit_index)` instead. +/// +/// # Arguments +/// * `bitmap` – byte slice containing the bitfield (original order, not modified) +/// * `feature_bit` – zero-based bit index across the entire bitmap +/// +/// # Returns +/// `true` if the bit is set; `false` if the bit is unset or out of bounds +pub fn is_feature_bit_set_reversed(bitmap: &[u8], feature_bit: usize) -> bool { + let mut reversed = bitmap.to_vec(); + reversed.reverse(); + is_feature_bit_set(&reversed, feature_bit) +} + /// Checks if the feature bit is set in the provided bitmap. /// Returns true if the `feature_bit` is set in the `bitmap`. Returns false if /// the `feature_bit` is unset or our ouf bounds.