X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Fpersist.rs;fp=lightning%2Fsrc%2Futil%2Fpersist.rs;h=3f918935f16700008cae3b2854babeae60bbd740;hb=4b5504366b2e0c7e29e8bf4bee5d05445f363c35;hp=6fd0048daf7ddeec9e3f754c0f368e44572891d4;hpb=9a1649c2b2ca5b348d2e58624ccc936197bcb4d0;p=rust-lightning diff --git a/lightning/src/util/persist.rs b/lightning/src/util/persist.rs index 6fd0048d..3f918935 100644 --- a/lightning/src/util/persist.rs +++ b/lightning/src/util/persist.rs @@ -56,6 +56,11 @@ pub const CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE: &str = ""; /// The primary namespace under which [`ChannelMonitorUpdate`]s will be persisted. pub const CHANNEL_MONITOR_UPDATE_PERSISTENCE_PRIMARY_NAMESPACE: &str = "monitor_updates"; +/// The primary namespace under which archived [`ChannelMonitor`]s will be persisted. +pub const ARCHIVED_CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE: &str = "archived_monitors"; +/// The secondary namespace under which archived [`ChannelMonitor`]s will be persisted. +pub const ARCHIVED_CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE: &str = ""; + /// The primary namespace under which the [`NetworkGraph`] will be persisted. pub const NETWORK_GRAPH_PERSISTENCE_PRIMARY_NAMESPACE: &str = ""; /// The secondary namespace under which the [`NetworkGraph`] will be persisted. @@ -212,6 +217,33 @@ impl Persist chain::ChannelMonitorUpdateStatus::UnrecoverableError } } + + fn archive_persisted_channel(&self, funding_txo: OutPoint) { + let monitor_name = MonitorName::from(funding_txo); + let monitor = match self.read( + CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE, + CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE, + monitor_name.as_str(), + ) { + Ok(monitor) => monitor, + Err(_) => return + }; + match self.write( + ARCHIVED_CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE, + ARCHIVED_CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE, + monitor_name.as_str(), + &monitor, + ) { + Ok(()) => {} + Err(_e) => return + }; + let _ = self.remove( + CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE, + CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE, + monitor_name.as_str(), + true, + ); + } } /// Read previously persisted [`ChannelMonitor`]s from the store. @@ -718,6 +750,29 @@ where self.persist_new_channel(funding_txo, monitor, monitor_update_call_id) } } + + fn archive_persisted_channel(&self, funding_txo: OutPoint) { + let monitor_name = MonitorName::from(funding_txo); + let monitor = match self.read_monitor(&monitor_name) { + Ok((_block_hash, monitor)) => monitor, + Err(_) => return + }; + match self.kv_store.write( + ARCHIVED_CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE, + ARCHIVED_CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE, + monitor_name.as_str(), + &monitor.encode() + ) { + Ok(()) => {}, + Err(_e) => return, + }; + let _ = self.kv_store.remove( + CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE, + CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE, + monitor_name.as_str(), + true, + ); + } } impl MonitorUpdatingPersister