Skip to content

Commit 4678f85

Browse files
committed
removed constraints
1 parent 7812b29 commit 4678f85

File tree

5 files changed

+89
-79
lines changed

5 files changed

+89
-79
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,9 @@ impl BackgroundProcessor {
979979
EH: 'static + EventHandler + Send,
980980
PS: 'static + Deref + Send,
981981
M: 'static
982-
+ Deref<Target = ChainMonitor<<CM::Target as AChannelManager>::Signer, CF, T, F, L, P, FS>>
982+
+ Deref<
983+
Target = ChainMonitor<<CM::Target as AChannelManager>::Signer, CF, T, F, L, P, FS>,
984+
>
983985
+ Send
984986
+ Sync,
985987
CM: 'static + Deref + Send,
@@ -994,7 +996,7 @@ impl BackgroundProcessor {
994996
O: 'static + Deref,
995997
K: 'static + Deref,
996998
OS: 'static + Deref<Target = OutputSweeperSync<T, D, F, CF, K, L, O>> + Send,
997-
FS: FutureSpawner
999+
FS: FutureSpawner,
9981000
>(
9991001
persister: PS, event_handler: EH, chain_monitor: M, channel_manager: CM,
10001002
onion_messenger: Option<OM>, gossip_sync: GossipSync<PGS, RGS, G, UL, L>, peer_manager: PM,

lightning-persister/src/fs_store.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! Objects related to [`FilesystemStore`] live here.
22
use crate::utils::{check_namespace_key_validity, is_valid_kvstore_str};
33

4+
use lightning::util::async_poll::AsyncResult;
45
use lightning::util::persist::{KVStore, MigratableKVStore};
56
use lightning::util::string::PrintableString;
6-
use lightning::util::async_poll::AsyncResult;
77

88
use std::collections::HashMap;
99
use std::fs;
@@ -12,8 +12,6 @@ use std::path::{Path, PathBuf};
1212
use std::sync::atomic::{AtomicUsize, Ordering};
1313
use std::sync::{Arc, Mutex, RwLock};
1414

15-
16-
1715
#[cfg(target_os = "windows")]
1816
use {std::ffi::OsStr, std::os::windows::ffi::OsStrExt};
1917

@@ -334,7 +332,7 @@ impl KVStore for FilesystemStore {
334332
}
335333

336334
fn write_async(
337-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: &[u8],
335+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: &[u8],
338336
) -> AsyncResult<'static, ()> {
339337
todo!()
340338
}

lightning/src/chain/chainmonitor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ where C::Target: chain::Filter,
721721
}
722722
}
723723

724-
impl<ChannelSigner: EcdsaChannelSigner + Send + Sync + 'static, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref, FS: FutureSpawner>
724+
impl<ChannelSigner: EcdsaChannelSigner + 'static, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref, FS: FutureSpawner>
725725
chain::Listen for ChainMonitor<ChannelSigner, C, T, F, L, P, FS>
726726
where
727727
C::Target: chain::Filter,
@@ -750,7 +750,7 @@ where
750750
}
751751
}
752752

753-
impl<ChannelSigner: EcdsaChannelSigner + Sync + Send + 'static, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref, FS: FutureSpawner>
753+
impl<ChannelSigner: EcdsaChannelSigner + 'static, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref, FS: FutureSpawner>
754754
chain::Confirm for ChainMonitor<ChannelSigner, C, T, F, L, P, FS>
755755
where
756756
C::Target: chain::Filter,
@@ -804,7 +804,7 @@ where
804804
}
805805
}
806806

807-
impl<ChannelSigner: EcdsaChannelSigner + Sync + Send + 'static, C: Deref , T: Deref , F: Deref , L: Deref , P: Deref, FS: FutureSpawner + Clone>
807+
impl<ChannelSigner: EcdsaChannelSigner + 'static, C: Deref , T: Deref , F: Deref , L: Deref , P: Deref, FS: FutureSpawner + Clone>
808808
chain::Watch<ChannelSigner> for ChainMonitor<ChannelSigner, C, T, F, L, P, FS>
809809
where C::Target: chain::Filter,
810810
T::Target: BroadcasterInterface,

lightning/src/util/async_poll.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -106,28 +106,30 @@ pub trait FutureSpawner: Send + Sync + 'static {
106106
}
107107

108108
/// Polls a future and either returns true if it is ready or spawns it on the tokio runtime if it is not.
109-
pub fn poll_or_spawn<F, C, S>(mut fut: Pin<Box<F>>, callback: C, future_spawner: &S) -> Result<bool, ()>
109+
pub fn poll_or_spawn<F, C, S>(
110+
mut fut: Pin<Box<F>>, callback: C, future_spawner: &S,
111+
) -> Result<bool, ()>
110112
where
111-
F: Future<Output = Result<(), ()>> + Send + 'static + ?Sized,
112-
C: FnOnce() + Send + 'static,
113+
F: Future<Output = Result<(), ()>> + Send + 'static + ?Sized,
114+
C: FnOnce() + Send + 'static,
113115
S: FutureSpawner,
114116
{
115-
let waker = dummy_waker();
116-
let mut cx = Context::from_waker(&waker);
117+
let waker = dummy_waker();
118+
let mut cx = Context::from_waker(&waker);
117119

118-
match fut.as_mut().poll(&mut cx) {
119-
Poll::Ready(Ok(())) => Ok(true),
120+
match fut.as_mut().poll(&mut cx) {
121+
Poll::Ready(Ok(())) => Ok(true),
120122
Poll::Ready(Err(_)) => Err(()),
121-
Poll::Pending => {
122-
println!("Future not ready, using tokio runtime");
123-
124-
let callback = Box::new(callback);
125-
future_spawner.spawn(async move {
126-
fut.await;
127-
callback();
128-
});
129-
130-
Ok(false)
131-
}
132-
}
133-
}
123+
Poll::Pending => {
124+
println!("Future not ready, using tokio runtime");
125+
126+
let callback = Box::new(callback);
127+
future_spawner.spawn(async move {
128+
fut.await;
129+
callback();
130+
});
131+
132+
Ok(false)
133+
},
134+
}
135+
}

lightning/src/util/persist.rs

Lines changed: 58 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ use core::str::FromStr;
1919
use crate::prelude::*;
2020
use crate::{io, log_error};
2121

22-
use crate::sync::{Arc};
23-
use crate::chain;
2422
use crate::chain::chaininterface::{BroadcasterInterface, FeeEstimator};
2523
use crate::chain::chainmonitor::Persist;
2624
use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate};
@@ -30,6 +28,7 @@ use crate::ln::types::ChannelId;
3028
use crate::routing::gossip::NetworkGraph;
3129
use crate::routing::scoring::WriteableScore;
3230
use crate::sign::{ecdsa::EcdsaChannelSigner, EntropySource, SignerProvider};
31+
use crate::sync::Arc;
3332
use crate::util::logger::Logger;
3433
use crate::util::ser::{Readable, ReadableArgs, Writeable};
3534

@@ -262,7 +261,7 @@ where
262261
}
263262
}
264263

265-
impl<ChannelSigner: EcdsaChannelSigner + Send, K: KVStore + ?Sized + Sync + Send + 'static>
264+
impl<ChannelSigner: EcdsaChannelSigner, K: KVStore + ?Sized + Sync + Send + 'static>
266265
Persist<ChannelSigner> for Arc<K>
267266
{
268267
// TODO: We really need a way for the persister to inform the user that its time to crash/shut
@@ -277,13 +276,14 @@ impl<ChannelSigner: EcdsaChannelSigner + Send, K: KVStore + ?Sized + Sync + Send
277276
let kv_store = self.clone();
278277

279278
Box::pin(async move {
280-
kv_store.write_async(
281-
CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE,
282-
CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE,
283-
&monitor_name.to_string(),
284-
&encoded,
285-
)
286-
.await
279+
kv_store
280+
.write_async(
281+
CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE,
282+
CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE,
283+
&monitor_name.to_string(),
284+
&encoded,
285+
)
286+
.await
287287
})
288288
}
289289

@@ -295,13 +295,14 @@ impl<ChannelSigner: EcdsaChannelSigner + Send, K: KVStore + ?Sized + Sync + Send
295295
let kv_store = self.clone();
296296

297297
Box::pin(async move {
298-
kv_store.write_async(
299-
CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE,
300-
CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE,
301-
&monitor_name.to_string(),
302-
&encoded,
303-
)
304-
.await
298+
kv_store
299+
.write_async(
300+
CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE,
301+
CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE,
302+
&monitor_name.to_string(),
303+
&encoded,
304+
)
305+
.await
305306
})
306307
}
307308

@@ -492,7 +493,6 @@ where
492493
fee_estimator: FE,
493494
}
494495

495-
496496
#[allow(dead_code)]
497497
impl<K: Deref, L: Deref, ES: Deref, SP: Deref, BI: Deref, FE: Deref>
498498
MonitorUpdatingPersisterState<K, L, ES, SP, BI, FE>
@@ -728,7 +728,7 @@ where
728728
K::Target: KVStore + Sync,
729729
L::Target: Logger,
730730
ES::Target: EntropySource + Sized,
731-
SP::Target: SignerProvider + Send + Sync + Sized,
731+
SP::Target: SignerProvider + Sync + Sized,
732732
BI::Target: BroadcasterInterface,
733733
FE::Target: FeeEstimator,
734734
{
@@ -741,9 +741,7 @@ where
741741

742742
let encoded_monitor = Self::encode_monitor(monitor);
743743

744-
Box::pin(async move {
745-
state.persist_new_channel(monitor_name, &encoded_monitor).await
746-
})
744+
Box::pin(async move { state.persist_new_channel(monitor_name, &encoded_monitor).await })
747745
}
748746

749747
/// Persists a channel update, writing only the update to the parameterized [`KVStore`] if possible.
@@ -766,7 +764,14 @@ where
766764
let monitor_latest_update_id = monitor.get_latest_update_id();
767765

768766
Box::pin(async move {
769-
state.update_persisted_channel(monitor_name, encoded_update, &encoded_monitor, monitor_latest_update_id).await
767+
state
768+
.update_persisted_channel(
769+
monitor_name,
770+
encoded_update,
771+
&encoded_monitor,
772+
monitor_latest_update_id,
773+
)
774+
.await
770775
})
771776
}
772777

@@ -775,7 +780,6 @@ where
775780
}
776781
}
777782

778-
779783
impl<
780784
K: Deref + Send + Sync + 'static,
781785
L: Deref + Send + Sync + 'static,
@@ -793,18 +797,18 @@ where
793797
FE::Target: FeeEstimator,
794798
{
795799
fn encode_monitor<ChannelSigner: EcdsaChannelSigner + Send + Sync>(
796-
monitor: &ChannelMonitor<ChannelSigner>,
797-
) -> Vec<u8> {
798-
// Serialize and write the new monitor
799-
let mut monitor_bytes = Vec::with_capacity(
800-
MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL.len() + monitor.serialized_length(),
801-
);
802-
monitor_bytes.extend_from_slice(MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL);
803-
monitor.write(&mut monitor_bytes).unwrap();
800+
monitor: &ChannelMonitor<ChannelSigner>,
801+
) -> Vec<u8> {
802+
// Serialize and write the new monitor
803+
let mut monitor_bytes = Vec::with_capacity(
804+
MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL.len() + monitor.serialized_length(),
805+
);
806+
monitor_bytes.extend_from_slice(MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL);
807+
monitor.write(&mut monitor_bytes).unwrap();
804808

805-
monitor_bytes
806-
}
809+
monitor_bytes
807810
}
811+
}
808812

809813
impl<
810814
K: Deref + Send + Sync + 'static,
@@ -831,12 +835,14 @@ where
831835
let monitor_key = monitor_name.to_string();
832836

833837
// Serialize and write the new monitor
834-
self.kv_store.write_async(
835-
CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE,
836-
CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE,
837-
monitor_key.as_str(),
838-
&monitor_bytes,
839-
).await
838+
self.kv_store
839+
.write_async(
840+
CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE,
841+
CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE,
842+
monitor_key.as_str(),
843+
&monitor_bytes,
844+
)
845+
.await
840846
}
841847

842848
/// Persists a channel update, writing only the update to the parameterized [`KVStore`] if possible.
@@ -849,8 +855,8 @@ where
849855
/// `update` is `None`.
850856
/// - The update is at [`u64::MAX`], indicating an update generated by pre-0.1 LDK.
851857
async fn update_persisted_channel(
852-
self: Arc<Self>, monitor_name: MonitorName, update: Option<(u64, Vec<u8>)>,
853-
monitor: &[u8], monitor_latest_update_id: u64,
858+
self: Arc<Self>, monitor_name: MonitorName, update: Option<(u64, Vec<u8>)>, monitor: &[u8],
859+
monitor_latest_update_id: u64,
854860
) -> Result<(), ()> {
855861
const LEGACY_CLOSED_CHANNEL_UPDATE_ID: u64 = u64::MAX;
856862
if let Some((update_id, update)) = update {
@@ -859,12 +865,14 @@ where
859865
if persist_update {
860866
let monitor_key = monitor_name.to_string();
861867
let update_name = UpdateName::from(update_id);
862-
self.kv_store.write_async(
863-
CHANNEL_MONITOR_UPDATE_PERSISTENCE_PRIMARY_NAMESPACE,
864-
monitor_key.as_str(),
865-
update_name.as_str(),
866-
&update,
867-
).await
868+
self.kv_store
869+
.write_async(
870+
CHANNEL_MONITOR_UPDATE_PERSISTENCE_PRIMARY_NAMESPACE,
871+
monitor_key.as_str(),
872+
update_name.as_str(),
873+
&update,
874+
)
875+
.await
868876
} else {
869877
// In case of channel-close monitor update, we need to read old monitor before persisting
870878
// the new one in order to determine the cleanup range.
@@ -877,7 +885,8 @@ where
877885
};
878886

879887
// We could write this update, but it meets criteria of our design that calls for a full monitor write.
880-
let monitor_update_status = self.clone().persist_new_channel(monitor_name, &monitor).await;
888+
let monitor_update_status =
889+
self.clone().persist_new_channel(monitor_name, &monitor).await;
881890

882891
if monitor_update_status.is_ok() {
883892
let channel_closed_legacy =
@@ -936,7 +945,6 @@ where
936945
}
937946
}
938947

939-
940948
impl<K: Deref, L: Deref, ES: Deref, SP: Deref, BI: Deref, FE: Deref>
941949
MonitorUpdatingPersisterState<K, L, ES, SP, BI, FE>
942950
where

0 commit comments

Comments
 (0)