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
6 changes: 3 additions & 3 deletions lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2779,7 +2779,7 @@ mod tests {
let kv_store_sync = Arc::new(
Persister::new(data_dir).with_manager_error(std::io::ErrorKind::Other, "test"),
);
let kv_store = Arc::new(KVStoreSyncWrapper(kv_store_sync));
let kv_store = 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.

Expand Down Expand Up @@ -3298,7 +3298,7 @@ mod tests {
let data_dir = nodes[0].kv_store.get_data_dir();
let kv_store_sync =
Arc::new(Persister::new(data_dir).with_graph_persistence_notifier(sender));
let kv_store = Arc::new(KVStoreSyncWrapper(kv_store_sync));
let kv_store = KVStoreSyncWrapper(kv_store_sync);

// Yes, you can unsafe { turn off the borrow checker }
let lm_async: &'static LiquidityManager<_, _, _, _, _, _> = unsafe {
Expand Down Expand Up @@ -3523,7 +3523,7 @@ mod tests {
let (_, nodes) = create_nodes(1, "test_payment_path_scoring_async");
let data_dir = nodes[0].kv_store.get_data_dir();
let kv_store_sync = Arc::new(Persister::new(data_dir));
let kv_store = Arc::new(KVStoreSyncWrapper(kv_store_sync));
let kv_store = KVStoreSyncWrapper(kv_store_sync);

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

Expand Down
30 changes: 12 additions & 18 deletions lightning-liquidity/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub trait ALiquidityManagerSync {
Self::NS,
Self::CM,
Self::C,
Arc<KVStoreSyncWrapper<Self::KS>>,
KVStoreSyncWrapper<Self::KS>,
Self::TP,
>;
/// Returns a reference to the actual [`LiquidityManager`] object.
Expand Down Expand Up @@ -246,7 +246,7 @@ where
Self::NS,
Self::CM,
Self::C,
Arc<KVStoreSyncWrapper<Self::KS>>,
KVStoreSyncWrapper<Self::KS>,
Self::TP,
> {
&self.inner
Expand Down Expand Up @@ -1036,7 +1036,7 @@ pub struct LiquidityManagerSync<
KS::Target: KVStoreSync,
TP::Target: TimeProvider,
{
inner: LiquidityManager<ES, NS, CM, C, Arc<KVStoreSyncWrapper<KS>>, TP>,
inner: LiquidityManager<ES, NS, CM, C, KVStoreSyncWrapper<KS>, TP>,
}

#[cfg(feature = "time")]
Expand All @@ -1063,7 +1063,7 @@ where
service_config: Option<LiquidityServiceConfig>,
client_config: Option<LiquidityClientConfig>,
) -> Result<Self, lightning::io::Error> {
let kv_store = Arc::new(KVStoreSyncWrapper(kv_store_sync));
let kv_store = KVStoreSyncWrapper(kv_store_sync);

let mut fut = Box::pin(LiquidityManager::new(
entropy_source,
Expand Down Expand Up @@ -1114,7 +1114,7 @@ where
service_config: Option<LiquidityServiceConfig>,
client_config: Option<LiquidityClientConfig>, time_provider: TP,
) -> Result<Self, lightning::io::Error> {
let kv_store = Arc::new(KVStoreSyncWrapper(kv_store_sync));
let kv_store = KVStoreSyncWrapper(kv_store_sync);
let mut fut = Box::pin(LiquidityManager::new_with_custom_time_provider(
entropy_source,
node_signer,
Expand Down Expand Up @@ -1142,7 +1142,7 @@ where
/// Returns a reference to the LSPS0 client-side handler.
///
/// Wraps [`LiquidityManager::lsps0_client_handler`].
pub fn lsps0_client_handler(&self) -> &LSPS0ClientHandler<ES, Arc<KVStoreSyncWrapper<KS>>> {
pub fn lsps0_client_handler(&self) -> &LSPS0ClientHandler<ES, KVStoreSyncWrapper<KS>> {
self.inner.lsps0_client_handler()
}

Expand All @@ -1156,9 +1156,7 @@ where
/// Returns a reference to the LSPS1 client-side handler.
///
/// Wraps [`LiquidityManager::lsps1_client_handler`].
pub fn lsps1_client_handler(
&self,
) -> Option<&LSPS1ClientHandler<ES, Arc<KVStoreSyncWrapper<KS>>>> {
pub fn lsps1_client_handler(&self) -> Option<&LSPS1ClientHandler<ES, KVStoreSyncWrapper<KS>>> {
self.inner.lsps1_client_handler()
}

Expand All @@ -1168,16 +1166,14 @@ where
#[cfg(lsps1_service)]
pub fn lsps1_service_handler(
&self,
) -> Option<&LSPS1ServiceHandler<ES, CM, C, Arc<KVStoreSyncWrapper<KS>>>> {
) -> Option<&LSPS1ServiceHandler<ES, CM, C, KVStoreSyncWrapper<KS>>> {
self.inner.lsps1_service_handler()
}

/// Returns a reference to the LSPS2 client-side handler.
///
/// Wraps [`LiquidityManager::lsps2_client_handler`].
pub fn lsps2_client_handler(
&self,
) -> Option<&LSPS2ClientHandler<ES, Arc<KVStoreSyncWrapper<KS>>>> {
pub fn lsps2_client_handler(&self) -> Option<&LSPS2ClientHandler<ES, KVStoreSyncWrapper<KS>>> {
self.inner.lsps2_client_handler()
}

Expand All @@ -1186,16 +1182,14 @@ where
/// Wraps [`LiquidityManager::lsps2_service_handler`].
pub fn lsps2_service_handler<'a>(
&'a self,
) -> Option<LSPS2ServiceHandlerSync<'a, CM, Arc<KVStoreSyncWrapper<KS>>>> {
) -> Option<LSPS2ServiceHandlerSync<'a, CM, KVStoreSyncWrapper<KS>>> {
self.inner.lsps2_service_handler.as_ref().map(|r| LSPS2ServiceHandlerSync::from_inner(r))
}

/// Returns a reference to the LSPS5 client-side handler.
///
/// Wraps [`LiquidityManager::lsps5_client_handler`].
pub fn lsps5_client_handler(
&self,
) -> Option<&LSPS5ClientHandler<ES, Arc<KVStoreSyncWrapper<KS>>>> {
pub fn lsps5_client_handler(&self) -> Option<&LSPS5ClientHandler<ES, KVStoreSyncWrapper<KS>>> {
self.inner.lsps5_client_handler()
}

Expand All @@ -1204,7 +1198,7 @@ where
/// Wraps [`LiquidityManager::lsps5_service_handler`].
pub fn lsps5_service_handler(
&self,
) -> Option<&LSPS5ServiceHandler<CM, NS, Arc<KVStoreSyncWrapper<KS>>, TP>> {
) -> Option<&LSPS5ServiceHandler<CM, NS, KVStoreSyncWrapper<KS>, TP>> {
self.inner.lsps5_service_handler()
}

Expand Down
1 change: 1 addition & 0 deletions lightning/src/util/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ pub trait KVStoreSync {

/// A wrapper around a [`KVStoreSync`] that implements the [`KVStore`] trait. It is not necessary to use this type
/// directly.
#[derive(Clone)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Right, so instead of ref counting, this will now be cloned

pub struct KVStoreSyncWrapper<K: Deref>(pub K)
where
K::Target: KVStoreSync;
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/util/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ where
Arc<ChangeDestinationSourceSyncWrapper<D>>,
E,
F,
Arc<KVStoreSyncWrapper<K>>,
KVStoreSyncWrapper<K>,
L,
O,
>,
Expand All @@ -1011,7 +1011,7 @@ where
let change_destination_source =
Arc::new(ChangeDestinationSourceSyncWrapper::new(change_destination_source));

let kv_store = Arc::new(KVStoreSyncWrapper(kv_store));
let kv_store = KVStoreSyncWrapper(kv_store);

let sweeper = OutputSweeper::new(
best_block,
Expand Down Expand Up @@ -1077,7 +1077,7 @@ where
Arc<ChangeDestinationSourceSyncWrapper<D>>,
E,
F,
Arc<KVStoreSyncWrapper<K>>,
KVStoreSyncWrapper<K>,
L,
O,
> {
Expand Down