@@ -58,6 +58,11 @@ pub const CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE: &str = "";
58
58
/// The primary namespace under which [`ChannelMonitorUpdate`]s will be persisted.
59
59
pub const CHANNEL_MONITOR_UPDATE_PERSISTENCE_PRIMARY_NAMESPACE : & str = "monitor_updates" ;
60
60
61
+ /// The primary namespace under which archived [`ChannelMonitor`]s will be persisted.
62
+ pub const ARCHIVED_CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE : & str = "archived_monitors" ;
63
+ /// The secondary namespace under which archived [`ChannelMonitor`]s will be persisted.
64
+ pub const ARCHIVED_CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE : & str = "" ;
65
+
61
66
/// The primary namespace under which the [`NetworkGraph`] will be persisted.
62
67
pub const NETWORK_GRAPH_PERSISTENCE_PRIMARY_NAMESPACE : & str = "" ;
63
68
/// The secondary namespace under which the [`NetworkGraph`] will be persisted.
@@ -214,6 +219,40 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner, K: KVStore + ?Sized> Persist<Ch
214
219
Err ( _) => chain:: ChannelMonitorUpdateStatus :: UnrecoverableError
215
220
}
216
221
}
222
+
223
+ fn archive_persisted_channel ( & self , funding_txo : OutPoint ) -> chain:: ChannelMonitorUpdateStatus {
224
+ let monitor_name = MonitorName :: from ( funding_txo) ;
225
+ let monitor = match self . read (
226
+ CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE ,
227
+ CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE ,
228
+ monitor_name. as_str ( ) ,
229
+ ) {
230
+ Ok ( monitor) => monitor,
231
+ Err ( _) => {
232
+ return chain:: ChannelMonitorUpdateStatus :: UnrecoverableError ;
233
+ }
234
+
235
+ } ;
236
+ match self . write (
237
+ ARCHIVED_CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE ,
238
+ ARCHIVED_CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE ,
239
+ monitor_name. as_str ( ) ,
240
+ & monitor
241
+ ) {
242
+ Ok ( ( ) ) => { }
243
+ Err ( _e) => return chain:: ChannelMonitorUpdateStatus :: UnrecoverableError
244
+ } ;
245
+ let key = format ! ( "{}_{}" , funding_txo. txid. to_string( ) , funding_txo. index) ;
246
+ match self . remove (
247
+ CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE ,
248
+ CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE ,
249
+ & key,
250
+ false ,
251
+ ) {
252
+ Ok ( ( ) ) => chain:: ChannelMonitorUpdateStatus :: Completed ,
253
+ Err ( _) => chain:: ChannelMonitorUpdateStatus :: UnrecoverableError
254
+ }
255
+ }
217
256
}
218
257
219
258
/// Read previously persisted [`ChannelMonitor`]s from the store.
@@ -720,6 +759,34 @@ where
720
759
self . persist_new_channel ( funding_txo, monitor, monitor_update_call_id)
721
760
}
722
761
}
762
+
763
+ fn archive_persisted_channel ( & self , funding_txo : OutPoint ) -> chain:: ChannelMonitorUpdateStatus {
764
+ let monitor_name = MonitorName :: from ( funding_txo) ;
765
+ let monitor = match self . read_monitor ( & monitor_name) {
766
+ Ok ( ( _block_hash, monitor) ) => monitor,
767
+ Err ( _) => return chain:: ChannelMonitorUpdateStatus :: UnrecoverableError
768
+ } ;
769
+ match self . kv_store . write (
770
+ ARCHIVED_CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE ,
771
+ ARCHIVED_CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE ,
772
+ monitor_name. as_str ( ) ,
773
+ & monitor. encode ( )
774
+ ) {
775
+ Ok ( ( ) ) => { } ,
776
+ Err ( _e) => {
777
+ return chain:: ChannelMonitorUpdateStatus :: UnrecoverableError ;
778
+ } // TODO: Should we return UnrecoverableError here
779
+ } ;
780
+ match self . kv_store . remove (
781
+ CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE ,
782
+ CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE ,
783
+ monitor_name. as_str ( ) ,
784
+ false ,
785
+ ) {
786
+ Ok ( ( ) ) => chain:: ChannelMonitorUpdateStatus :: Completed ,
787
+ Err ( _) => chain:: ChannelMonitorUpdateStatus :: UnrecoverableError
788
+ }
789
+ }
723
790
}
724
791
725
792
impl < K : Deref , L : Deref , ES : Deref , SP : Deref > MonitorUpdatingPersister < K , L , ES , SP >
0 commit comments