@@ -19,8 +19,6 @@ use core::str::FromStr;
1919use crate :: prelude:: * ;
2020use crate :: { io, log_error} ;
2121
22- use crate :: sync:: { Arc } ;
23- use crate :: chain;
2422use crate :: chain:: chaininterface:: { BroadcasterInterface , FeeEstimator } ;
2523use crate :: chain:: chainmonitor:: Persist ;
2624use crate :: chain:: channelmonitor:: { ChannelMonitor , ChannelMonitorUpdate } ;
@@ -30,6 +28,7 @@ use crate::ln::types::ChannelId;
3028use crate :: routing:: gossip:: NetworkGraph ;
3129use crate :: routing:: scoring:: WriteableScore ;
3230use crate :: sign:: { ecdsa:: EcdsaChannelSigner , EntropySource , SignerProvider } ;
31+ use crate :: sync:: Arc ;
3332use crate :: util:: logger:: Logger ;
3433use crate :: util:: ser:: { Readable , ReadableArgs , Writeable } ;
3534
@@ -262,7 +261,7 @@ where
262261 }
263262}
264263
265- impl < ChannelSigner : EcdsaChannelSigner + Send , K : KVStore + ?Sized + Sync + Send + ' static >
264+ impl < ChannelSigner : EcdsaChannelSigner , K : KVStore + ?Sized + Sync + Send + ' static >
266265 Persist < ChannelSigner > for Arc < K >
267266{
268267 // TODO: We really need a way for the persister to inform the user that its time to crash/shut
@@ -277,13 +276,14 @@ impl<ChannelSigner: EcdsaChannelSigner + Send, K: KVStore + ?Sized + Sync + Send
277276 let kv_store = self . clone ( ) ;
278277
279278 Box :: pin ( async move {
280- kv_store. write_async (
281- CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE ,
282- CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE ,
283- & monitor_name. to_string ( ) ,
284- & encoded,
285- )
286- . await
279+ kv_store
280+ . write_async (
281+ CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE ,
282+ CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE ,
283+ & monitor_name. to_string ( ) ,
284+ & encoded,
285+ )
286+ . await
287287 } )
288288 }
289289
@@ -295,13 +295,14 @@ impl<ChannelSigner: EcdsaChannelSigner + Send, K: KVStore + ?Sized + Sync + Send
295295 let kv_store = self . clone ( ) ;
296296
297297 Box :: pin ( async move {
298- kv_store. write_async (
299- CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE ,
300- CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE ,
301- & monitor_name. to_string ( ) ,
302- & encoded,
303- )
304- . await
298+ kv_store
299+ . write_async (
300+ CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE ,
301+ CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE ,
302+ & monitor_name. to_string ( ) ,
303+ & encoded,
304+ )
305+ . await
305306 } )
306307 }
307308
@@ -492,7 +493,6 @@ where
492493 fee_estimator : FE ,
493494}
494495
495-
496496#[ allow( dead_code) ]
497497impl < K : Deref , L : Deref , ES : Deref , SP : Deref , BI : Deref , FE : Deref >
498498 MonitorUpdatingPersisterState < K , L , ES , SP , BI , FE >
@@ -728,7 +728,7 @@ where
728728 K :: Target : KVStore + Sync ,
729729 L :: Target : Logger ,
730730 ES :: Target : EntropySource + Sized ,
731- SP :: Target : SignerProvider + Send + Sync + Sized ,
731+ SP :: Target : SignerProvider + Sync + Sized ,
732732 BI :: Target : BroadcasterInterface ,
733733 FE :: Target : FeeEstimator ,
734734{
@@ -741,9 +741,7 @@ where
741741
742742 let encoded_monitor = Self :: encode_monitor ( monitor) ;
743743
744- Box :: pin ( async move {
745- state. persist_new_channel ( monitor_name, & encoded_monitor) . await
746- } )
744+ Box :: pin ( async move { state. persist_new_channel ( monitor_name, & encoded_monitor) . await } )
747745 }
748746
749747 /// Persists a channel update, writing only the update to the parameterized [`KVStore`] if possible.
@@ -766,7 +764,14 @@ where
766764 let monitor_latest_update_id = monitor. get_latest_update_id ( ) ;
767765
768766 Box :: pin ( async move {
769- state. update_persisted_channel ( monitor_name, encoded_update, & encoded_monitor, monitor_latest_update_id) . await
767+ state
768+ . update_persisted_channel (
769+ monitor_name,
770+ encoded_update,
771+ & encoded_monitor,
772+ monitor_latest_update_id,
773+ )
774+ . await
770775 } )
771776 }
772777
@@ -775,7 +780,6 @@ where
775780 }
776781}
777782
778-
779783impl <
780784 K : Deref + Send + Sync + ' static ,
781785 L : Deref + Send + Sync + ' static ,
@@ -793,18 +797,18 @@ where
793797 FE :: Target : FeeEstimator ,
794798{
795799 fn encode_monitor < ChannelSigner : EcdsaChannelSigner + Send + Sync > (
796- monitor : & ChannelMonitor < ChannelSigner > ,
797- ) -> Vec < u8 > {
798- // Serialize and write the new monitor
799- let mut monitor_bytes = Vec :: with_capacity (
800- MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL . len ( ) + monitor. serialized_length ( ) ,
801- ) ;
802- monitor_bytes. extend_from_slice ( MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL ) ;
803- monitor. write ( & mut monitor_bytes) . unwrap ( ) ;
800+ monitor : & ChannelMonitor < ChannelSigner > ,
801+ ) -> Vec < u8 > {
802+ // Serialize and write the new monitor
803+ let mut monitor_bytes = Vec :: with_capacity (
804+ MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL . len ( ) + monitor. serialized_length ( ) ,
805+ ) ;
806+ monitor_bytes. extend_from_slice ( MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL ) ;
807+ monitor. write ( & mut monitor_bytes) . unwrap ( ) ;
804808
805- monitor_bytes
806- }
809+ monitor_bytes
807810 }
811+ }
808812
809813impl <
810814 K : Deref + Send + Sync + ' static ,
@@ -831,12 +835,14 @@ where
831835 let monitor_key = monitor_name. to_string ( ) ;
832836
833837 // Serialize and write the new monitor
834- self . kv_store . write_async (
835- CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE ,
836- CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE ,
837- monitor_key. as_str ( ) ,
838- & monitor_bytes,
839- ) . await
838+ self . kv_store
839+ . write_async (
840+ CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE ,
841+ CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE ,
842+ monitor_key. as_str ( ) ,
843+ & monitor_bytes,
844+ )
845+ . await
840846 }
841847
842848 /// Persists a channel update, writing only the update to the parameterized [`KVStore`] if possible.
@@ -849,8 +855,8 @@ where
849855 /// `update` is `None`.
850856 /// - The update is at [`u64::MAX`], indicating an update generated by pre-0.1 LDK.
851857 async fn update_persisted_channel (
852- self : Arc < Self > , monitor_name : MonitorName , update : Option < ( u64 , Vec < u8 > ) > ,
853- monitor : & [ u8 ] , monitor_latest_update_id : u64 ,
858+ self : Arc < Self > , monitor_name : MonitorName , update : Option < ( u64 , Vec < u8 > ) > , monitor : & [ u8 ] ,
859+ monitor_latest_update_id : u64 ,
854860 ) -> Result < ( ) , ( ) > {
855861 const LEGACY_CLOSED_CHANNEL_UPDATE_ID : u64 = u64:: MAX ;
856862 if let Some ( ( update_id, update) ) = update {
@@ -859,12 +865,14 @@ where
859865 if persist_update {
860866 let monitor_key = monitor_name. to_string ( ) ;
861867 let update_name = UpdateName :: from ( update_id) ;
862- self . kv_store . write_async (
863- CHANNEL_MONITOR_UPDATE_PERSISTENCE_PRIMARY_NAMESPACE ,
864- monitor_key. as_str ( ) ,
865- update_name. as_str ( ) ,
866- & update,
867- ) . await
868+ self . kv_store
869+ . write_async (
870+ CHANNEL_MONITOR_UPDATE_PERSISTENCE_PRIMARY_NAMESPACE ,
871+ monitor_key. as_str ( ) ,
872+ update_name. as_str ( ) ,
873+ & update,
874+ )
875+ . await
868876 } else {
869877 // In case of channel-close monitor update, we need to read old monitor before persisting
870878 // the new one in order to determine the cleanup range.
@@ -877,7 +885,8 @@ where
877885 } ;
878886
879887 // We could write this update, but it meets criteria of our design that calls for a full monitor write.
880- let monitor_update_status = self . clone ( ) . persist_new_channel ( monitor_name, & monitor) . await ;
888+ let monitor_update_status =
889+ self . clone ( ) . persist_new_channel ( monitor_name, & monitor) . await ;
881890
882891 if monitor_update_status. is_ok ( ) {
883892 let channel_closed_legacy =
@@ -936,7 +945,6 @@ where
936945 }
937946}
938947
939-
940948impl < K : Deref , L : Deref , ES : Deref , SP : Deref , BI : Deref , FE : Deref >
941949 MonitorUpdatingPersisterState < K , L , ES , SP , BI , FE >
942950where
0 commit comments