]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Use `u64` for `required_unknown_bits_from` indexes, not `usize` 2024-08-no-pub-usize
authorMatt Corallo <git@bluematt.me>
Thu, 29 Aug 2024 16:45:27 +0000 (16:45 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 29 Aug 2024 16:47:54 +0000 (16:47 +0000)
While `usize` should be fine, we're multiplying the index by 8 so
if we have a jumbo feature bit fitting in a 32-bit size type may
not quite work. More importantly, this would be the first use of a
`usize` in the public API and dealing with it in bindings is
annoying so we just replace with a `u64`.

lightning-types/src/features.rs

index a3cb9db2f161a526b7d3b1fa83b0a206c440dd67..5d64a33b37df40e6be69708d393d325bf6b3216a 100644 (file)
@@ -911,7 +911,7 @@ impl<T: sealed::Context> Features<T> {
        }
 
        /// Returns the set of required features unknown by `other`, as their bit position.
-       pub fn required_unknown_bits_from(&self, other: &Self) -> Vec<usize> {
+       pub fn required_unknown_bits_from(&self, other: &Self) -> Vec<u64> {
                let mut unknown_bits = Vec::new();
 
                // Bitwise AND-ing with all even bits set except for known features will select required
@@ -921,7 +921,7 @@ impl<T: sealed::Context> Features<T> {
                        if byte & unknown_features != 0 {
                                for bit in (0..8).step_by(2) {
                                        if ((byte & unknown_features) >> bit) & 1 == 1 {
-                                               unknown_bits.push(i * 8 + bit);
+                                               unknown_bits.push((i as u64) * 8 + bit);
                                        }
                                }
                        }