Merge pull request #2912 from jkczyz/2024-02-prefer-more-connections
authorElias Rohrer <dev@tnull.de>
Thu, 7 Mar 2024 11:06:42 +0000 (12:06 +0100)
committerGitHub <noreply@github.com>
Thu, 7 Mar 2024 11:06:42 +0000 (12:06 +0100)
Order blinded paths by reliability criteria

lightning/src/events/mod.rs
lightning/src/ln/mod.rs
lightning/src/util/hash_tables.rs
lightning/src/util/ser.rs

index d08d3c5ac6ba163b100e5392a4b86cea8fce6841..485a23e0292e520c28d47a226fe7de51abdd9690 100644 (file)
@@ -368,6 +368,10 @@ pub enum PaymentFailureReason {
        /// [`PaymentParameters::expiry_time`]: crate::routing::router::PaymentParameters::expiry_time
        PaymentExpired,
        /// We failed to find a route while retrying the payment.
+       ///
+       /// Note that this generally indicates that we've exhausted the available set of possible
+       /// routes - we tried the payment over a few routes but were not able to find any further
+       /// candidate routes beyond those.
        RouteNotFound,
        /// This error should generally never happen. This likely means that there is a problem with
        /// your router.
index e79f4bbd24d90d481735a7c602f64442a128d296..71b73390d1c80a9590afedecfbee6f542822a076 100644 (file)
@@ -85,6 +85,8 @@ mod offers_tests;
 
 pub use self::peer_channel_encryptor::LN_MAX_MSG_LEN;
 
+use bitcoin::hashes::{sha256::Hash as Sha256, Hash};
+
 /// payment_hash type, use to cross-lock hop
 ///
 /// This is not exported to bindings users as we just use [u8; 32] directly
@@ -109,6 +111,13 @@ impl core::fmt::Display for PaymentPreimage {
        }
 }
 
+/// Converts a `PaymentPreimage` into a `PaymentHash` by hashing the preimage with SHA256.
+impl From<PaymentPreimage> for PaymentHash {
+       fn from(value: PaymentPreimage) -> Self {
+               PaymentHash(Sha256::hash(&value.0).to_byte_array())
+       }
+}
+
 /// payment_secret type, use to authenticate sender to the receiver and tie MPP HTLCs together
 ///
 /// This is not exported to bindings users as we just use [u8; 32] directly
index 69581e5e20a42e0c8ca79338cd2fc476f092f075..6c3d1ec42cb41dbc618c002c15eee4cf190f809a 100644 (file)
@@ -15,10 +15,10 @@ extern crate possiblyrandom;
 
 #[cfg(not(feature = "hashbrown"))]
 mod std_hashtables {
-       pub use std::collections::HashMap;
        pub use std::collections::hash_map::RandomState;
+       pub use std::collections::HashMap;
 
-       pub(crate) use std::collections::{HashSet, hash_map};
+       pub(crate) use std::collections::{hash_map, HashSet};
 
        pub(crate) type OccupiedHashMapEntry<'a, K, V> =
                std::collections::hash_map::OccupiedEntry<'a, K, V>;
@@ -26,20 +26,32 @@ mod std_hashtables {
                std::collections::hash_map::VacantEntry<'a, K, V>;
 
        /// Builds a new [`HashMap`].
-       pub fn new_hash_map<K, V>() -> HashMap<K, V> { HashMap::new() }
+       pub fn new_hash_map<K, V>() -> HashMap<K, V> {
+               HashMap::new()
+       }
        /// Builds a new [`HashMap`] with the given capacity.
        pub fn hash_map_with_capacity<K, V>(cap: usize) -> HashMap<K, V> {
                HashMap::with_capacity(cap)
        }
-       pub(crate) fn hash_map_from_iter<K: core::hash::Hash + Eq, V, I: IntoIterator<Item=(K, V)>>(iter: I) -> HashMap<K, V> {
+       pub(crate) fn hash_map_from_iter<
+               K: core::hash::Hash + Eq,
+               V,
+               I: IntoIterator<Item = (K, V)>,
+       >(
+               iter: I,
+       ) -> HashMap<K, V> {
                HashMap::from_iter(iter)
        }
 
-       pub(crate) fn new_hash_set<K>() -> HashSet<K> { HashSet::new() }
+       pub(crate) fn new_hash_set<K>() -> HashSet<K> {
+               HashSet::new()
+       }
        pub(crate) fn hash_set_with_capacity<K>(cap: usize) -> HashSet<K> {
                HashSet::with_capacity(cap)
        }
-       pub(crate) fn hash_set_from_iter<K: core::hash::Hash + Eq, I: IntoIterator<Item=K>>(iter: I) -> HashSet<K> {
+       pub(crate) fn hash_set_from_iter<K: core::hash::Hash + Eq, I: IntoIterator<Item = K>>(
+               iter: I,
+       ) -> HashSet<K> {
                HashSet::from_iter(iter)
        }
 }
@@ -64,7 +76,8 @@ mod hashbrown_tables {
                /// A simple implementation of [`BuildHasher`] that uses `getrandom` to opportunistically
                /// randomize, if the platform supports it.
                pub struct RandomState {
-                       k0: u64, k1: u64,
+                       k0: u64,
+                       k1: u64,
                }
 
                impl RandomState {
@@ -72,7 +85,8 @@ mod hashbrown_tables {
                        /// target platform.
                        pub fn new() -> RandomState {
                                let (k0, k1);
-                               #[cfg(all(not(fuzzing), feature = "possiblyrandom"))] {
+                               #[cfg(all(not(fuzzing), feature = "possiblyrandom"))]
+                               {
                                        let mut keys = [0; 16];
                                        possiblyrandom::getpossiblyrandom(&mut keys);
 
@@ -83,7 +97,8 @@ mod hashbrown_tables {
                                        k0 = u64::from_le_bytes(k0_bytes);
                                        k1 = u64::from_le_bytes(k1_bytes);
                                }
-                               #[cfg(any(fuzzing, not(feature = "possiblyrandom")))] {
+                               #[cfg(any(fuzzing, not(feature = "possiblyrandom")))]
+                               {
                                        k0 = 0;
                                        k1 = 0;
                                }
@@ -92,7 +107,9 @@ mod hashbrown_tables {
                }
 
                impl Default for RandomState {
-                       fn default() -> RandomState { RandomState::new() }
+                       fn default() -> RandomState {
+                               RandomState::new()
+                       }
                }
 
                impl BuildHasher for RandomState {
@@ -103,8 +120,8 @@ mod hashbrown_tables {
                }
        }
 
-       pub use hasher::*;
        use super::*;
+       pub use hasher::*;
 
        /// The HashMap type used in LDK.
        pub type HashMap<K, V> = hashbrown::HashMap<K, V, RandomState>;
@@ -123,7 +140,13 @@ mod hashbrown_tables {
        pub fn hash_map_with_capacity<K, V>(cap: usize) -> HashMap<K, V> {
                HashMap::with_capacity_and_hasher(cap, RandomState::new())
        }
-       pub(crate) fn hash_map_from_iter<K: core::hash::Hash + Eq, V, I: IntoIterator<Item=(K, V)>>(iter: I) -> HashMap<K, V> {
+       pub(crate) fn hash_map_from_iter<
+               K: core::hash::Hash + Eq,
+               V,
+               I: IntoIterator<Item = (K, V)>,
+       >(
+               iter: I,
+       ) -> HashMap<K, V> {
                let iter = iter.into_iter();
                let min_size = iter.size_hint().0;
                let mut res = HashMap::with_capacity_and_hasher(min_size, RandomState::new());
@@ -137,7 +160,9 @@ mod hashbrown_tables {
        pub(crate) fn hash_set_with_capacity<K>(cap: usize) -> HashSet<K> {
                HashSet::with_capacity_and_hasher(cap, RandomState::new())
        }
-       pub(crate) fn hash_set_from_iter<K: core::hash::Hash + Eq, I: IntoIterator<Item=K>>(iter: I) -> HashSet<K> {
+       pub(crate) fn hash_set_from_iter<K: core::hash::Hash + Eq, I: IntoIterator<Item = K>>(
+               iter: I,
+       ) -> HashSet<K> {
                let iter = iter.into_iter();
                let min_size = iter.size_hint().0;
                let mut res = HashSet::with_capacity_and_hasher(min_size, RandomState::new());
index c24a99f8f97109dde673a59eb7fbb28200a6e3b9..7447c92d4be8b61abc23b0527d458796687bd29e 100644 (file)
@@ -847,6 +847,7 @@ impl Readable for Vec<u8> {
 impl_for_vec!(ecdsa::Signature);
 impl_for_vec!(crate::chain::channelmonitor::ChannelMonitorUpdate);
 impl_for_vec!(crate::ln::channelmanager::MonitorUpdateCompletionAction);
+impl_for_vec!(crate::ln::msgs::SocketAddress);
 impl_for_vec!((A, B), A, B);
 impl_writeable_for_vec!(&crate::routing::router::BlindedTail);
 impl_readable_for_vec!(crate::routing::router::BlindedTail);