@@ -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 ,
@@ -706,10 +705,9 @@ where
706705 /// Persists a new channel. This means writing the entire monitor to the
707706 /// parametrized [`KVStore`].
708707 fn persist_new_channel (
709- & self , monitor : & ChannelMonitor < ChannelSigner > ,
708+ & self , monitor_name : MonitorName , monitor : & ChannelMonitor < ChannelSigner > ,
710709 ) -> chain:: ChannelMonitorUpdateStatus {
711710 // Determine the proper key for this monitor
712- let monitor_name = monitor. persistence_key ( ) ;
713711 let monitor_key = monitor_name. to_string ( ) ;
714712 // Serialize and write the new monitor
715713 let mut monitor_bytes = Vec :: with_capacity (
@@ -748,15 +746,15 @@ where
748746 /// `update` is `None`.
749747 /// - The update is at [`u64::MAX`], indicating an update generated by pre-0.1 LDK.
750748 fn update_persisted_channel (
751- & self , update : Option < & ChannelMonitorUpdate > , monitor : & ChannelMonitor < ChannelSigner > ,
749+ & self , monitor_name : MonitorName , update : Option < & ChannelMonitorUpdate > ,
750+ monitor : & ChannelMonitor < ChannelSigner > ,
752751 ) -> chain:: ChannelMonitorUpdateStatus {
753752 const LEGACY_CLOSED_CHANNEL_UPDATE_ID : u64 = u64:: MAX ;
754753 if let Some ( update) = update {
755- let monitor_name = monitor . persistence_key ( ) ;
754+ let monitor_key = monitor_name . to_string ( ) ;
756755 let persist_update = update. update_id != LEGACY_CLOSED_CHANNEL_UPDATE_ID
757756 && update. update_id % self . maximum_pending_updates != 0 ;
758757 if persist_update {
759- let monitor_key = monitor_name. to_string ( ) ;
760758 let update_name = UpdateName :: from ( update. update_id ) ;
761759 match self . kv_store . write (
762760 CHANNEL_MONITOR_UPDATE_PERSISTENCE_PRIMARY_NAMESPACE ,
@@ -778,7 +776,6 @@ where
778776 } ,
779777 }
780778 } else {
781- let monitor_key = monitor_name. to_string ( ) ;
782779 // In case of channel-close monitor update, we need to read old monitor before persisting
783780 // the new one in order to determine the cleanup range.
784781 let maybe_old_monitor = match monitor. get_latest_update_id ( ) {
@@ -789,7 +786,7 @@ where
789786 } ;
790787
791788 // We could write this update, but it meets criteria of our design that calls for a full monitor write.
792- let monitor_update_status = self . persist_new_channel ( monitor) ;
789+ let monitor_update_status = self . persist_new_channel ( monitor_name , monitor) ;
793790
794791 if let chain:: ChannelMonitorUpdateStatus :: Completed = monitor_update_status {
795792 let channel_closed_legacy =
@@ -820,7 +817,7 @@ where
820817 }
821818 } else {
822819 // There is no update given, so we must persist a new monitor.
823- self . persist_new_channel ( monitor)
820+ self . persist_new_channel ( monitor_name , monitor)
824821 }
825822 }
826823
@@ -923,7 +920,7 @@ where
923920/// // Using MonitorName to generate a storage key
924921/// let storage_key = format!("channel_monitors/{}", monitor_name);
925922/// ```
926- #[ derive( Clone , Debug , Eq , Hash , PartialEq ) ]
923+ #[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
927924pub enum MonitorName {
928925 /// The outpoint of the channel's funding transaction.
929926 V1Channel ( OutPoint ) ,
@@ -1358,7 +1355,8 @@ mod tests {
13581355 broadcaster : node_cfgs[ 0 ] . tx_broadcaster ,
13591356 fee_estimator : node_cfgs[ 0 ] . fee_estimator ,
13601357 } ;
1361- match ro_persister. persist_new_channel ( & added_monitors[ 0 ] . 1 ) {
1358+ let monitor_name = added_monitors[ 0 ] . 1 . persistence_key ( ) ;
1359+ match ro_persister. persist_new_channel ( monitor_name, & added_monitors[ 0 ] . 1 ) {
13621360 ChannelMonitorUpdateStatus :: UnrecoverableError => {
13631361 // correct result
13641362 } ,
@@ -1369,7 +1367,11 @@ mod tests {
13691367 panic ! ( "Returned InProgress when shouldn't have" )
13701368 } ,
13711369 }
1372- match ro_persister. update_persisted_channel ( Some ( cmu) , & added_monitors[ 0 ] . 1 ) {
1370+ match ro_persister. update_persisted_channel (
1371+ monitor_name,
1372+ Some ( cmu) ,
1373+ & added_monitors[ 0 ] . 1 ,
1374+ ) {
13731375 ChannelMonitorUpdateStatus :: UnrecoverableError => {
13741376 // correct result
13751377 } ,
0 commit comments