@@ -48,6 +48,38 @@ const FRESHNESS_TIMER: u64 = 60;
48
48
#[ cfg( test) ]
49
49
const FRESHNESS_TIMER : u64 = 1 ;
50
50
51
+ /// Trait which handles persisting a [`ChannelManager`] to disk.
52
+ ///
53
+ /// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
54
+ pub trait ChannelManagerPersister < Signer : Sign , M : Deref , T : Deref , K : Deref , F : Deref , L : Deref >
55
+ where
56
+ M :: Target : ' static + chain:: Watch < Signer > ,
57
+ T :: Target : ' static + BroadcasterInterface ,
58
+ K :: Target : ' static + KeysInterface < Signer = Signer > ,
59
+ F :: Target : ' static + FeeEstimator ,
60
+ L :: Target : ' static + Logger ,
61
+ {
62
+ /// Persist the given [`ChannelManager`] to disk, returning an error if persistence failed
63
+ /// (which will cause the [`BackgroundProcessor`] which called this method to exit.
64
+ ///
65
+ /// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
66
+ fn persist_manager ( & self , channel_manager : & ChannelManager < Signer , M , T , K , F , L > ) -> Result < ( ) , std:: io:: Error > ;
67
+ }
68
+
69
+ impl < Fun , Signer : Sign , M : Deref , T : Deref , K : Deref , F : Deref , L : Deref >
70
+ ChannelManagerPersister < Signer , M , T , K , F , L > for Fun where
71
+ M :: Target : ' static + chain:: Watch < Signer > ,
72
+ T :: Target : ' static + BroadcasterInterface ,
73
+ K :: Target : ' static + KeysInterface < Signer = Signer > ,
74
+ F :: Target : ' static + FeeEstimator ,
75
+ L :: Target : ' static + Logger ,
76
+ Fun : Fn ( & ChannelManager < Signer , M , T , K , F , L > ) -> Result < ( ) , std:: io:: Error > ,
77
+ {
78
+ fn persist_manager ( & self , channel_manager : & ChannelManager < Signer , M , T , K , F , L > ) -> Result < ( ) , std:: io:: Error > {
79
+ self ( channel_manager)
80
+ }
81
+ }
82
+
51
83
impl BackgroundProcessor {
52
84
/// Start a background thread that takes care of responsibilities enumerated in the top-level
53
85
/// documentation.
@@ -68,28 +100,28 @@ impl BackgroundProcessor {
68
100
/// [`ChannelManager::write`]: lightning::ln::channelmanager::ChannelManager#impl-Writeable
69
101
/// [`FilesystemPersister::persist_manager`]: lightning_persister::FilesystemPersister::persist_manager
70
102
pub fn start <
71
- PM , Signer ,
103
+ Signer : ' static + Sign ,
72
104
M : ' static + Deref + Send + Sync ,
73
105
T : ' static + Deref + Send + Sync ,
74
106
K : ' static + Deref + Send + Sync ,
75
107
F : ' static + Deref + Send + Sync ,
76
108
L : ' static + Deref + Send + Sync ,
77
109
Descriptor : ' static + SocketDescriptor + Send + Sync ,
78
- CM : ' static + Deref + Send + Sync ,
79
- RM : ' static + Deref + Send + Sync
80
- > (
81
- persist_channel_manager : PM , channel_manager : Arc < ChannelManager < Signer , M , T , K , F , L > > ,
82
- peer_manager : Arc < PeerManager < Descriptor , CM , RM , L > > , logger : L ,
83
- ) -> Self where
84
- Signer : ' static + Sign ,
110
+ CMH : ' static + Deref + Send + Sync ,
111
+ RMH : ' static + Deref + Send + Sync ,
112
+ CMP : ' static + Send + ChannelManagerPersister < Signer , M , T , K , F , L > ,
113
+ CM : ' static + Deref < Target = ChannelManager < Signer , M , T , K , F , L > > + Send + Sync ,
114
+ PM : ' static + Deref < Target = PeerManager < Descriptor , CMH , RMH , L > > + Send + Sync ,
115
+ >
116
+ ( handler : CMP , channel_manager : CM , peer_manager : PM , logger : L ) -> Self
117
+ where
85
118
M :: Target : ' static + chain:: Watch < Signer > ,
86
119
T :: Target : ' static + BroadcasterInterface ,
87
120
K :: Target : ' static + KeysInterface < Signer = Signer > ,
88
121
F :: Target : ' static + FeeEstimator ,
89
122
L :: Target : ' static + Logger ,
90
- CM :: Target : ' static + ChannelMessageHandler ,
91
- RM :: Target : ' static + RoutingMessageHandler ,
92
- PM : ' static + Send + Fn ( & ChannelManager < Signer , M , T , K , F , L > ) -> Result < ( ) , std:: io:: Error > ,
123
+ CMH :: Target : ' static + ChannelMessageHandler ,
124
+ RMH :: Target : ' static + RoutingMessageHandler ,
93
125
{
94
126
let stop_thread = Arc :: new ( AtomicBool :: new ( false ) ) ;
95
127
let stop_thread_clone = stop_thread. clone ( ) ;
@@ -100,7 +132,7 @@ impl BackgroundProcessor {
100
132
let updates_available =
101
133
channel_manager. await_persistable_update_timeout ( Duration :: from_millis ( 100 ) ) ;
102
134
if updates_available {
103
- persist_channel_manager ( & * channel_manager) ?;
135
+ handler . persist_manager ( & * channel_manager) ?;
104
136
}
105
137
// Exit the loop if the background processor was requested to stop.
106
138
if stop_thread. load ( Ordering :: Acquire ) == true {
0 commit comments