Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit c6004e2

Browse files
committed
Fix no-std support
.. as we previously inluded `lightning-invoice` with default features, its `std` feature was always enabled. For it to correctly set `std`/`no-std`, we need to drop `Send + Sync` bounds in `no-std`.
1 parent 1e503b9 commit c6004e2

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

src/manager.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,71 @@ where {
286286
/// ```
287287
///
288288
/// [`PeerManager::process_events`]: lightning::ln::peer_handler::PeerManager::process_events
289+
#[cfg(feature = "std")]
289290
pub fn set_process_msgs_callback(&self, callback: impl Fn() + Send + Sync + 'static) {
290291
self.pending_messages.set_process_msgs_callback(callback)
291292
}
292293

294+
/// Allows to set a callback that will be called after new messages are pushed to the message
295+
/// queue.
296+
///
297+
/// Usually, you'll want to use this to call [`PeerManager::process_events`] to clear the
298+
/// message queue. For example:
299+
///
300+
/// ```
301+
/// # use lightning::io;
302+
/// # use lightning_liquidity::LiquidityManager;
303+
/// # use std::sync::{Arc, RwLock};
304+
/// # use std::sync::atomic::{AtomicBool, Ordering};
305+
/// # use std::time::SystemTime;
306+
/// # struct MyStore {}
307+
/// # impl lightning::util::persist::KVStore for MyStore {
308+
/// # fn read(&self, primary_namespace: &str, secondary_namespace: &str, key: &str) -> io::Result<Vec<u8>> { Ok(Vec::new()) }
309+
/// # fn write(&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: &[u8]) -> io::Result<()> { Ok(()) }
310+
/// # fn remove(&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool) -> io::Result<()> { Ok(()) }
311+
/// # fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> io::Result<Vec<String>> { Ok(Vec::new()) }
312+
/// # }
313+
/// # struct MyEntropySource {}
314+
/// # impl lightning::sign::EntropySource for MyEntropySource {
315+
/// # fn get_secure_random_bytes(&self) -> [u8; 32] { [0u8; 32] }
316+
/// # }
317+
/// # struct MyEventHandler {}
318+
/// # impl MyEventHandler {
319+
/// # async fn handle_event(&self, _: lightning::events::Event) {}
320+
/// # }
321+
/// # #[derive(Eq, PartialEq, Clone, Hash)]
322+
/// # struct MySocketDescriptor {}
323+
/// # impl lightning::ln::peer_handler::SocketDescriptor for MySocketDescriptor {
324+
/// # fn send_data(&mut self, _data: &[u8], _resume_read: bool) -> usize { 0 }
325+
/// # fn disconnect_socket(&mut self) {}
326+
/// # }
327+
/// # type MyBroadcaster = dyn lightning::chain::chaininterface::BroadcasterInterface;
328+
/// # type MyFeeEstimator = dyn lightning::chain::chaininterface::FeeEstimator;
329+
/// # type MyNodeSigner = dyn lightning::sign::NodeSigner;
330+
/// # type MyUtxoLookup = dyn lightning::routing::utxo::UtxoLookup;
331+
/// # type MyFilter = dyn lightning::chain::Filter;
332+
/// # type MyLogger = dyn lightning::util::logger::Logger;
333+
/// # type MyChainMonitor = lightning::chain::chainmonitor::ChainMonitor<lightning::sign::InMemorySigner, Arc<MyFilter>, Arc<MyBroadcaster>, Arc<MyFeeEstimator>, Arc<MyLogger>, Arc<MyStore>>;
334+
/// # type MyPeerManager = lightning::ln::peer_handler::SimpleArcPeerManager<MySocketDescriptor, MyChainMonitor, MyBroadcaster, MyFeeEstimator, Arc<MyUtxoLookup>, MyLogger>;
335+
/// # type MyNetworkGraph = lightning::routing::gossip::NetworkGraph<Arc<MyLogger>>;
336+
/// # type MyGossipSync = lightning::routing::gossip::P2PGossipSync<Arc<MyNetworkGraph>, Arc<MyUtxoLookup>, Arc<MyLogger>>;
337+
/// # type MyChannelManager = lightning::ln::channelmanager::SimpleArcChannelManager<MyChainMonitor, MyBroadcaster, MyFeeEstimator, MyLogger>;
338+
/// # type MyScorer = RwLock<lightning::routing::scoring::ProbabilisticScorer<Arc<MyNetworkGraph>, Arc<MyLogger>>>;
339+
/// # type MyLiquidityManager = LiquidityManager<Arc<MyEntropySource>, Arc<MyChannelManager>, Arc<MyFilter>>;
340+
/// # fn setup_background_processing(my_persister: Arc<MyStore>, my_event_handler: Arc<MyEventHandler>, my_chain_monitor: Arc<MyChainMonitor>, my_channel_manager: Arc<MyChannelManager>, my_logger: Arc<MyLogger>, my_peer_manager: Arc<MyPeerManager>, my_liquidity_manager: Arc<MyLiquidityManager>) {
341+
/// let process_msgs_pm = Arc::clone(&my_peer_manager);
342+
/// let process_msgs_callback = move || process_msgs_pm.process_events();
343+
///
344+
/// my_liquidity_manager.set_process_msgs_callback(process_msgs_callback);
345+
/// # }
346+
/// ```
347+
///
348+
/// [`PeerManager::process_events`]: lightning::ln::peer_handler::PeerManager::process_events
349+
#[cfg(feature = "no-std")]
350+
pub fn set_process_msgs_callback(&self, callback: impl Fn() + 'static) {
351+
self.pending_messages.set_process_msgs_callback(callback)
352+
}
353+
293354
/// Blocks the current thread until next event is ready and returns it.
294355
///
295356
/// Typically you would spawn a thread or task that calls this in a loop.

src/message_queue.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ use bitcoin::secp256k1::PublicKey;
1111
/// [`LiquidityManager`]: crate::LiquidityManager
1212
pub struct MessageQueue {
1313
queue: Mutex<VecDeque<(PublicKey, LSPSMessage)>>,
14+
#[cfg(feature = "std")]
1415
process_msgs_callback: RwLock<Option<Box<dyn Fn() + Send + Sync + 'static>>>,
16+
#[cfg(feature = "no-std")]
17+
process_msgs_callback: RwLock<Option<Box<dyn Fn() + 'static>>>,
1518
}
1619

1720
impl MessageQueue {
@@ -21,10 +24,16 @@ impl MessageQueue {
2124
Self { queue, process_msgs_callback }
2225
}
2326

27+
#[cfg(feature = "std")]
2428
pub(crate) fn set_process_msgs_callback(&self, callback: impl Fn() + Send + Sync + 'static) {
2529
*self.process_msgs_callback.write().unwrap() = Some(Box::new(callback));
2630
}
2731

32+
#[cfg(feature = "no-std")]
33+
pub(crate) fn set_process_msgs_callback(&self, callback: impl Fn() + 'static) {
34+
*self.process_msgs_callback.write().unwrap() = Some(Box::new(callback));
35+
}
36+
2837
pub(crate) fn get_and_clear_pending_msgs(&self) -> Vec<(PublicKey, LSPSMessage)> {
2938
self.queue.lock().unwrap().drain(..).collect()
3039
}

0 commit comments

Comments
 (0)