Skip to content

Commit 4a752b1

Browse files
committed
Stop relying on Hash{Set,Map}::from_iter directly
In the next commit we'll bump the `hashbrown` version, which no longer randomizes its hasher by default. Thus, we'll need to call a different constructor in no-std builds from std builds. Here we do a quick prefactor to use wrappers for `FromIterator` constructors instead of calling the tables directly to make the version bump changeset smaller.
1 parent 81005b0 commit 4a752b1

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ use crate::ln::channelmanager::ChannelDetails;
4242

4343
use crate::prelude::*;
4444
use crate::sync::{RwLock, RwLockReadGuard, Mutex, MutexGuard};
45-
use core::iter::FromIterator;
4645
use core::ops::Deref;
4746
use core::sync::atomic::{AtomicUsize, Ordering};
4847
use bitcoin::secp256k1::PublicKey;
@@ -317,7 +316,7 @@ where C::Target: chain::Filter,
317316
FN: Fn(&ChannelMonitor<ChannelSigner>, &TransactionData) -> Vec<TransactionOutputs>
318317
{
319318
let err_str = "ChannelMonitor[Update] persistence failed unrecoverably. This indicates we cannot continue normal operation and must shut down.";
320-
let funding_outpoints: HashSet<OutPoint> = HashSet::from_iter(self.monitors.read().unwrap().keys().cloned());
319+
let funding_outpoints = hash_set_from_iter(self.monitors.read().unwrap().keys().cloned());
321320
for funding_outpoint in funding_outpoints.iter() {
322321
let monitor_lock = self.monitors.read().unwrap();
323322
if let Some(monitor_state) = monitor_lock.get(funding_outpoint) {
@@ -482,9 +481,15 @@ where C::Target: chain::Filter,
482481
#[cfg(not(c_bindings))]
483482
/// Lists the pending updates for each [`ChannelMonitor`] (by `OutPoint` being monitored).
484483
pub fn list_pending_monitor_updates(&self) -> HashMap<OutPoint, Vec<MonitorUpdateId>> {
485-
self.monitors.read().unwrap().iter().map(|(outpoint, holder)| {
484+
let monitors = self.monitors.read().unwrap();
485+
let mut updates = hash_map_with_capacity(monitors.len());
486+
let pending_updates = monitors.iter().map(|(outpoint, holder)| {
486487
(*outpoint, holder.pending_monitor_updates.lock().unwrap().clone())
487-
}).collect()
488+
});
489+
for (funding_txo, chan_updates) in pending_updates {
490+
updates.insert(funding_txo, chan_updates);
491+
}
492+
updates
488493
}
489494

490495
#[cfg(c_bindings)]

lightning/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ mod prelude {
201201
pub(crate) fn hash_set_with_capacity<K: core::hash::Hash + Eq>(cap: usize) -> HashSet<K> {
202202
HashSet::with_capacity(cap)
203203
}
204+
pub(crate) fn hash_set_from_iter<K: core::hash::Hash + Eq, I: IntoIterator<Item = K>>(iter: I) -> HashSet<K> {
205+
HashSet::from_iter(iter)
206+
}
204207

205208
pub use alloc::borrow::ToOwned;
206209
pub use alloc::string::ToString;

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10727,7 +10727,7 @@ where
1072710727
retry_strategy: None,
1072810728
attempts: PaymentAttempts::new(),
1072910729
payment_params: None,
10730-
session_privs: [session_priv_bytes].iter().map(|a| *a).collect(),
10730+
session_privs: hash_set_from_iter([session_priv_bytes]),
1073110731
payment_hash: htlc.payment_hash,
1073210732
payment_secret: None, // only used for retries, and we'll never retry on startup
1073310733
payment_metadata: None, // only used for retries, and we'll never retry on startup

0 commit comments

Comments
 (0)