Drop unnecessary `Arc`s around `KVStoreWrapper`
What changed, and why it matters
This commit is a routine internal cleanup: it removes unnecessary Arc (reference-counting pointer) wrappers around a KVStoreSyncWrapper type and adds a Clone derive so the wrapper can still be duplicated when needed. There is no user-visible behavior change, no bug fix, and no security relevance in the diff itself.
No security action required; treat as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch changes KVStoreSyncWrapper
Changed components
lightning-background-processor test codelightning-liquidity managerlightning::util::persist::KVStoreSyncWrapperlightning::util::sweep::OutputSweeperSyncInspect captured patch +19 / −24
diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs
index 57b4a11..a5df6b3 100644
--- a/lightning-background-processor/src/lib.rs
+++ b/lightning-background-processor/src/lib.rs
@@ -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 {
@@ -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 {
@@ -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(());
diff --git a/lightning-liquidity/src/manager.rs b/lightning-liquidity/src/manager.rs
index d0925e1..a2def4b 100644
--- a/lightning-liquidity/src/manager.rs
+++ b/lightning-liquidity/src/manager.rs
@@ -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.
@@ -246,7 +246,7 @@ where
Self::NS,
Self::CM,
Self::C,
- Arc<KVStoreSyncWrapper<Self::KS>>,
+ KVStoreSyncWrapper<Self::KS>,
Self::TP,
> {
&self.inner
@@ -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")]
@@ -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,
@@ -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,
@@ -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()
}
@@ -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()
}
@@ -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()
}
@@ -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()
}
@@ -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()
}
diff --git a/lightning/src/util/persist.rs b/lightning/src/util/persist.rs
index 9036a27..a646e09 100644
--- a/lightning/src/util/persist.rs
+++ b/lightning/src/util/persist.rs
@@ -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)]
pub struct KVStoreSyncWrapper<K: Deref>(pub K)
where
K::Target: KVStoreSync;
diff --git a/lightning/src/util/sweep.rs b/lightning/src/util/sweep.rs
index 51cb5b3..052a56d 100644
--- a/lightning/src/util/sweep.rs
+++ b/lightning/src/util/sweep.rs
@@ -986,7 +986,7 @@ where
Arc<ChangeDestinationSourceSyncWrapper<D>>,
E,
F,
- Arc<KVStoreSyncWrapper<K>>,
+ KVStoreSyncWrapper<K>,
L,
O,
>,
@@ -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,
@@ -1077,7 +1077,7 @@ where
Arc<ChangeDestinationSourceSyncWrapper<D>>,
E,
F,
- Arc<KVStoreSyncWrapper<K>>,
+ KVStoreSyncWrapper<K>,
L,
O,
> {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.