Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1846,11 +1846,13 @@ mod tests {
SCORER_PERSISTENCE_SECONDARY_NAMESPACE,
};
use lightning::util::ser::Writeable;
use lightning::util::sweep::{OutputSpendStatus, OutputSweeperSync, PRUNE_DELAY_BLOCKS};
use lightning::util::sweep::{
OutputSpendStatus, OutputSweeper, OutputSweeperSync, PRUNE_DELAY_BLOCKS,
};
use lightning::util::test_utils;
use lightning::{get_event, get_event_msg};
use lightning_liquidity::utils::time::DefaultTimeProvider;
use lightning_liquidity::{ALiquidityManagerSync, LiquidityManagerSync};
use lightning_liquidity::{ALiquidityManagerSync, LiquidityManager, LiquidityManagerSync};
use lightning_persister::fs_store::FilesystemStore;
use lightning_rapid_gossip_sync::RapidGossipSync;
use std::collections::VecDeque;
Expand Down Expand Up @@ -2781,6 +2783,17 @@ mod tests {
);
let kv_store = Arc::new(KVStoreSyncWrapper(kv_store_sync));

// Yes, you can unsafe { turn off the borrow checker }
let lm_async: &'static LiquidityManager<_, _, _, _, _, _> = unsafe {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has a nice end result, but this - I am not sure how many devs understand it...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope the comment is clear enough? Easy to just update the comment later if it makes it more readable.

&*(nodes[0].liquidity_manager.get_lm_async()
as *const LiquidityManager<_, _, _, _, _, _>)
as &'static LiquidityManager<_, _, _, _, _, _>
};
let sweeper_async: &'static OutputSweeper<_, _, _, _, _, _, _> = unsafe {
&*(nodes[0].sweeper.sweeper_async() as *const OutputSweeper<_, _, _, _, _, _, _>)
as &'static OutputSweeper<_, _, _, _, _, _, _>
};

let bp_future = super::process_events_async(
kv_store,
|_: _| async { Ok(()) },
Expand All @@ -2789,8 +2802,8 @@ mod tests {
Some(Arc::clone(&nodes[0].messenger)),
nodes[0].rapid_gossip_sync(),
Arc::clone(&nodes[0].peer_manager),
Some(nodes[0].liquidity_manager.get_lm_async()),
Some(nodes[0].sweeper.sweeper_async()),
Some(lm_async),
Some(sweeper_async),
Arc::clone(&nodes[0].logger),
Some(Arc::clone(&nodes[0].scorer)),
move |dur: Duration| {
Expand Down Expand Up @@ -3289,6 +3302,17 @@ mod tests {
Arc::new(Persister::new(data_dir).with_graph_persistence_notifier(sender));
let kv_store = Arc::new(KVStoreSyncWrapper(kv_store_sync));

// Yes, you can unsafe { turn off the borrow checker }
let lm_async: &'static LiquidityManager<_, _, _, _, _, _> = unsafe {
&*(nodes[0].liquidity_manager.get_lm_async()
as *const LiquidityManager<_, _, _, _, _, _>)
as &'static LiquidityManager<_, _, _, _, _, _>
};
let sweeper_async: &'static OutputSweeper<_, _, _, _, _, _, _> = unsafe {
&*(nodes[0].sweeper.sweeper_async() as *const OutputSweeper<_, _, _, _, _, _, _>)
as &'static OutputSweeper<_, _, _, _, _, _, _>
};

let (exit_sender, exit_receiver) = tokio::sync::watch::channel(());
let bp_future = super::process_events_async(
kv_store,
Expand All @@ -3298,8 +3322,8 @@ mod tests {
Some(Arc::clone(&nodes[0].messenger)),
nodes[0].rapid_gossip_sync(),
Arc::clone(&nodes[0].peer_manager),
Some(nodes[0].liquidity_manager.get_lm_async()),
Some(nodes[0].sweeper.sweeper_async()),
Some(lm_async),
Some(sweeper_async),
Arc::clone(&nodes[0].logger),
Some(Arc::clone(&nodes[0].scorer)),
move |dur: Duration| {
Expand Down Expand Up @@ -3505,6 +3529,17 @@ mod tests {

let (exit_sender, exit_receiver) = tokio::sync::watch::channel(());

// Yes, you can unsafe { turn off the borrow checker }
let lm_async: &'static LiquidityManager<_, _, _, _, _, _> = unsafe {
&*(nodes[0].liquidity_manager.get_lm_async()
as *const LiquidityManager<_, _, _, _, _, _>)
as &'static LiquidityManager<_, _, _, _, _, _>
};
let sweeper_async: &'static OutputSweeper<_, _, _, _, _, _, _> = unsafe {
&*(nodes[0].sweeper.sweeper_async() as *const OutputSweeper<_, _, _, _, _, _, _>)
as &'static OutputSweeper<_, _, _, _, _, _, _>
};

let bp_future = super::process_events_async(
kv_store,
event_handler,
Expand All @@ -3513,8 +3548,8 @@ mod tests {
Some(Arc::clone(&nodes[0].messenger)),
nodes[0].no_gossip_sync(),
Arc::clone(&nodes[0].peer_manager),
Some(nodes[0].liquidity_manager.get_lm_async()),
Some(nodes[0].sweeper.sweeper_async()),
Some(lm_async),
Some(sweeper_async),
Arc::clone(&nodes[0].logger),
Some(Arc::clone(&nodes[0].scorer)),
move |dur: Duration| {
Expand Down
40 changes: 18 additions & 22 deletions lightning-liquidity/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,13 @@ pub trait ALiquidityManagerSync {
#[cfg(any(test, feature = "_test_utils"))]
fn get_lm_async(
&self,
) -> Arc<
LiquidityManager<
Self::ES,
Self::NS,
Self::CM,
Self::C,
Arc<KVStoreSyncWrapper<Self::KS>>,
Self::TP,
>,
) -> &LiquidityManager<
Self::ES,
Self::NS,
Self::CM,
Self::C,
Arc<KVStoreSyncWrapper<Self::KS>>,
Self::TP,
>;
/// Returns a reference to the actual [`LiquidityManager`] object.
fn get_lm(
Expand Down Expand Up @@ -243,17 +241,15 @@ where
#[cfg(any(test, feature = "_test_utils"))]
fn get_lm_async(
&self,
) -> Arc<
LiquidityManager<
Self::ES,
Self::NS,
Self::CM,
Self::C,
Arc<KVStoreSyncWrapper<Self::KS>>,
Self::TP,
>,
) -> &LiquidityManager<
Self::ES,
Self::NS,
Self::CM,
Self::C,
Arc<KVStoreSyncWrapper<Self::KS>>,
Self::TP,
> {
Arc::clone(&self.inner)
&self.inner
}
fn get_lm(&self) -> &LiquidityManagerSync<ES, NS, CM, C, KS, TP> {
self
Expand Down Expand Up @@ -1040,7 +1036,7 @@ pub struct LiquidityManagerSync<
KS::Target: KVStoreSync,
TP::Target: TimeProvider,
{
inner: Arc<LiquidityManager<ES, NS, CM, C, Arc<KVStoreSyncWrapper<KS>>, TP>>,
inner: LiquidityManager<ES, NS, CM, C, Arc<KVStoreSyncWrapper<KS>>, TP>,
}

#[cfg(feature = "time")]
Expand Down Expand Up @@ -1089,7 +1085,7 @@ where
unreachable!("LiquidityManager::new should not be pending in a sync context");
},
}?;
Ok(Self { inner: Arc::new(inner) })
Ok(Self { inner })
}
}

Expand Down Expand Up @@ -1140,7 +1136,7 @@ where
unreachable!("LiquidityManager::new should not be pending in a sync context");
},
}?;
Ok(Self { inner: Arc::new(inner) })
Ok(Self { inner })
}

/// Returns a reference to the LSPS0 client-side handler.
Expand Down
40 changes: 18 additions & 22 deletions lightning/src/util/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,16 +981,14 @@ where
L::Target: Logger,
O::Target: OutputSpender,
{
sweeper: Arc<
OutputSweeper<
B,
Arc<ChangeDestinationSourceSyncWrapper<D>>,
E,
F,
Arc<KVStoreSyncWrapper<K>>,
L,
O,
>,
sweeper: OutputSweeper<
B,
Arc<ChangeDestinationSourceSyncWrapper<D>>,
E,
F,
Arc<KVStoreSyncWrapper<K>>,
L,
O,
>,
}

Expand Down Expand Up @@ -1025,7 +1023,7 @@ where
kv_store,
logger,
);
Self { sweeper: Arc::new(sweeper) }
Self { sweeper }
}

/// Regenerates and broadcasts the spending transaction for any outputs that are pending. Wraps
Expand Down Expand Up @@ -1074,18 +1072,16 @@ where
#[cfg(any(test, feature = "_test_utils"))]
pub fn sweeper_async(
&self,
) -> Arc<
OutputSweeper<
B,
Arc<ChangeDestinationSourceSyncWrapper<D>>,
E,
F,
Arc<KVStoreSyncWrapper<K>>,
L,
O,
>,
) -> &OutputSweeper<
B,
Arc<ChangeDestinationSourceSyncWrapper<D>>,
E,
F,
Arc<KVStoreSyncWrapper<K>>,
L,
O,
> {
Arc::clone(&self.sweeper)
&self.sweeper
}
}

Expand Down