Skip to content

Commit 1deba29

Browse files
committed
ChainMonitorSync
1 parent 90c67c6 commit 1deba29

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,20 +263,22 @@ pub struct ChainMonitor<ChannelSigner: EcdsaChannelSigner, C: Deref, T: Deref, F
263263

264264
/// A synchronous wrapper around [`ChainMonitor`].
265265
pub struct ChainMonitorSync<ChannelSigner: EcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref, FS: FutureSpawner>
266-
(ChainMonitor<ChannelSigner, C, T, F, L, P, FS>) where C::Target: chain::Filter,
266+
(ChainMonitor<ChannelSigner, C, T, F, L, PersistSyncWrapper<P>, FS>) where C::Target: chain::Filter,
267267
T::Target: BroadcasterInterface,
268268
F::Target: FeeEstimator,
269269
L::Target: Logger,
270-
P::Target: Persist<ChannelSigner>;
270+
P::Target: PersistSync<ChannelSigner>;
271271

272272
impl<ChannelSigner: EcdsaChannelSigner + 'static, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref, FS: FutureSpawner> ChainMonitorSync<ChannelSigner, C, T, F, L, P, FS>
273273
where C::Target: chain::Filter,
274274
T::Target: BroadcasterInterface,
275275
F::Target: FeeEstimator,
276276
L::Target: Logger,
277-
P::Target: Persist<ChannelSigner> {
277+
P::Target: PersistSync<ChannelSigner> {
278278

279279
fn new(chain_source: Option<C>, broadcaster: T, logger: L, feeest: F, persister: P, future_spawner: FS) -> Self {
280+
let persister = PersistSyncWrapper(persister);
281+
280282
Self(ChainMonitor::new(chain_source, broadcaster, logger, feeest, persister, future_spawner))
281283
}
282284
}
@@ -1022,6 +1024,48 @@ impl<ChannelSigner: EcdsaChannelSigner, C: Deref, T: Deref, F: Deref, L: Deref,
10221024
}
10231025
}
10241026

1027+
/// A synchronous version of [`Persist`].
1028+
pub trait PersistSync<ChannelSigner: EcdsaChannelSigner> {
1029+
/// A synchronous version of [`Persist::persist_new_channel`].
1030+
fn persist_new_channel(&self, monitor_name: MonitorName, monitor: &ChannelMonitor<ChannelSigner>) -> Result<(), ()>;
1031+
1032+
/// A synchronous version of [`Persist::update_persisted_channel`].
1033+
fn update_persisted_channel(&self, monitor_name: MonitorName, monitor_update: Option<&ChannelMonitorUpdate>, monitor: &ChannelMonitor<ChannelSigner>) -> Result<(), ()>;
1034+
1035+
/// A synchronous version of [`Persist::archive_persisted_channel`].
1036+
fn archive_persisted_channel(&self, monitor_name: MonitorName);
1037+
}
1038+
1039+
struct PersistSyncWrapper<P: Deref>(P);
1040+
1041+
impl<T: Deref> Deref for PersistSyncWrapper<T> {
1042+
type Target = Self;
1043+
fn deref(&self) -> &Self { self }
1044+
}
1045+
1046+
impl<ChannelSigner: EcdsaChannelSigner, P: Deref> Persist<ChannelSigner> for PersistSyncWrapper<P> where P::Target: PersistSync<ChannelSigner> {
1047+
fn persist_new_channel(&self, monitor_name: MonitorName, monitor: &ChannelMonitor<ChannelSigner>) -> AsyncResult<'static, ()> {
1048+
let res = self.0.persist_new_channel(monitor_name, monitor);
1049+
1050+
Box::pin(async move {
1051+
res
1052+
})
1053+
}
1054+
1055+
fn update_persisted_channel(&self, monitor_name: MonitorName, monitor_update: Option<&ChannelMonitorUpdate>, monitor: &ChannelMonitor<ChannelSigner>)-> AsyncResult<'static, ()>{
1056+
let res = self.0.update_persisted_channel(monitor_name, monitor_update, monitor);
1057+
Box::pin(async move {
1058+
res
1059+
})
1060+
}
1061+
1062+
fn archive_persisted_channel(&self, monitor_name: MonitorName) -> AsyncVoid {
1063+
self.0.archive_persisted_channel(monitor_name);
1064+
1065+
Box::pin(async move {})
1066+
}
1067+
}
1068+
10251069
#[cfg(test)]
10261070
mod tests {
10271071
use crate::{check_added_monitors, check_closed_event};

0 commit comments

Comments
 (0)