@@ -261,9 +261,8 @@ impl<ChannelSigner: EcdsaChannelSigner, K: KVStore + ?Sized> Persist<ChannelSign
261261 // just shut down the node since we're not retrying persistence!
262262
263263 fn persist_new_channel (
264- & self , monitor : & ChannelMonitor < ChannelSigner > ,
264+ & self , monitor_name : MonitorName , monitor : & ChannelMonitor < ChannelSigner > ,
265265 ) -> chain:: ChannelMonitorUpdateStatus {
266- let monitor_name = monitor. persistence_key ( ) ;
267266 match self . write (
268267 CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE ,
269268 CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE ,
@@ -276,9 +275,9 @@ impl<ChannelSigner: EcdsaChannelSigner, K: KVStore + ?Sized> Persist<ChannelSign
276275 }
277276
278277 fn update_persisted_channel (
279- & self , _update : Option < & ChannelMonitorUpdate > , monitor : & ChannelMonitor < ChannelSigner > ,
278+ & self , monitor_name : MonitorName , _update : Option < & ChannelMonitorUpdate > ,
279+ monitor : & ChannelMonitor < ChannelSigner > ,
280280 ) -> chain:: ChannelMonitorUpdateStatus {
281- let monitor_name = monitor. persistence_key ( ) ;
282281 match self . write (
283282 CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE ,
284283 CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE ,
@@ -707,10 +706,9 @@ where
707706 /// Persists a new channel. This means writing the entire monitor to the
708707 /// parametrized [`KVStore`].
709708 fn persist_new_channel (
710- & self , monitor : & ChannelMonitor < ChannelSigner > ,
709+ & self , monitor_name : MonitorName , monitor : & ChannelMonitor < ChannelSigner > ,
711710 ) -> chain:: ChannelMonitorUpdateStatus {
712711 // Determine the proper key for this monitor
713- let monitor_name = monitor. persistence_key ( ) ;
714712 let monitor_key = monitor_name. to_string ( ) ;
715713 // Serialize and write the new monitor
716714 let mut monitor_bytes = Vec :: with_capacity (
@@ -749,15 +747,15 @@ where
749747 /// `update` is `None`.
750748 /// - The update is at [`u64::MAX`], indicating an update generated by pre-0.1 LDK.
751749 fn update_persisted_channel (
752- & self , update : Option < & ChannelMonitorUpdate > , monitor : & ChannelMonitor < ChannelSigner > ,
750+ & self , monitor_name : MonitorName , update : Option < & ChannelMonitorUpdate > ,
751+ monitor : & ChannelMonitor < ChannelSigner > ,
753752 ) -> chain:: ChannelMonitorUpdateStatus {
754753 const LEGACY_CLOSED_CHANNEL_UPDATE_ID : u64 = u64:: MAX ;
755754 if let Some ( update) = update {
756- let monitor_name = monitor . persistence_key ( ) ;
755+ let monitor_key = monitor_name . to_string ( ) ;
757756 let persist_update = update. update_id != LEGACY_CLOSED_CHANNEL_UPDATE_ID
758757 && update. update_id % self . maximum_pending_updates != 0 ;
759758 if persist_update {
760- let monitor_key = monitor_name. to_string ( ) ;
761759 let update_name = UpdateName :: from ( update. update_id ) ;
762760 match self . kv_store . write (
763761 CHANNEL_MONITOR_UPDATE_PERSISTENCE_PRIMARY_NAMESPACE ,
@@ -779,7 +777,6 @@ where
779777 } ,
780778 }
781779 } else {
782- let monitor_key = monitor_name. to_string ( ) ;
783780 // In case of channel-close monitor update, we need to read old monitor before persisting
784781 // the new one in order to determine the cleanup range.
785782 let maybe_old_monitor = match monitor. get_latest_update_id ( ) {
@@ -790,7 +787,7 @@ where
790787 } ;
791788
792789 // We could write this update, but it meets criteria of our design that calls for a full monitor write.
793- let monitor_update_status = self . persist_new_channel ( monitor) ;
790+ let monitor_update_status = self . persist_new_channel ( monitor_name , monitor) ;
794791
795792 if let chain:: ChannelMonitorUpdateStatus :: Completed = monitor_update_status {
796793 let channel_closed_legacy =
@@ -821,7 +818,7 @@ where
821818 }
822819 } else {
823820 // There is no update given, so we must persist a new monitor.
824- self . persist_new_channel ( monitor)
821+ self . persist_new_channel ( monitor_name , monitor)
825822 }
826823 }
827824
@@ -924,7 +921,7 @@ where
924921/// // Using MonitorName to generate a storage key
925922/// let storage_key = format!("channel_monitors/{}", monitor_name);
926923/// ```
927- #[ derive( Clone , Debug , Eq , Hash , PartialEq ) ]
924+ #[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
928925pub enum MonitorName {
929926 /// The outpoint of the channel's funding transaction.
930927 V1Channel ( OutPoint ) ,
@@ -1359,7 +1356,8 @@ mod tests {
13591356 broadcaster : node_cfgs[ 0 ] . tx_broadcaster ,
13601357 fee_estimator : node_cfgs[ 0 ] . fee_estimator ,
13611358 } ;
1362- match ro_persister. persist_new_channel ( & added_monitors[ 0 ] . 1 ) {
1359+ let monitor_name = added_monitors[ 0 ] . 1 . persistence_key ( ) ;
1360+ match ro_persister. persist_new_channel ( monitor_name, & added_monitors[ 0 ] . 1 ) {
13631361 ChannelMonitorUpdateStatus :: UnrecoverableError => {
13641362 // correct result
13651363 } ,
@@ -1370,7 +1368,11 @@ mod tests {
13701368 panic ! ( "Returned InProgress when shouldn't have" )
13711369 } ,
13721370 }
1373- match ro_persister. update_persisted_channel ( Some ( cmu) , & added_monitors[ 0 ] . 1 ) {
1371+ match ro_persister. update_persisted_channel (
1372+ monitor_name,
1373+ Some ( cmu) ,
1374+ & added_monitors[ 0 ] . 1 ,
1375+ ) {
13741376 ChannelMonitorUpdateStatus :: UnrecoverableError => {
13751377 // correct result
13761378 } ,
0 commit comments