@@ -19,8 +19,6 @@ use core::str::FromStr;
19
19
use crate :: prelude:: * ;
20
20
use crate :: { io, log_error} ;
21
21
22
- use crate :: sync:: { Arc } ;
23
- use crate :: chain;
24
22
use crate :: chain:: chaininterface:: { BroadcasterInterface , FeeEstimator } ;
25
23
use crate :: chain:: chainmonitor:: Persist ;
26
24
use crate :: chain:: channelmonitor:: { ChannelMonitor , ChannelMonitorUpdate } ;
@@ -30,6 +28,7 @@ use crate::ln::types::ChannelId;
30
28
use crate :: routing:: gossip:: NetworkGraph ;
31
29
use crate :: routing:: scoring:: WriteableScore ;
32
30
use crate :: sign:: { ecdsa:: EcdsaChannelSigner , EntropySource , SignerProvider } ;
31
+ use crate :: sync:: Arc ;
33
32
use crate :: util:: logger:: Logger ;
34
33
use crate :: util:: ser:: { Readable , ReadableArgs , Writeable } ;
35
34
@@ -262,7 +261,7 @@ where
262
261
}
263
262
}
264
263
265
- impl < ChannelSigner : EcdsaChannelSigner + Send , K : KVStore + ?Sized + Sync + Send + ' static >
264
+ impl < ChannelSigner : EcdsaChannelSigner , K : KVStore + ?Sized + Sync + Send + ' static >
266
265
Persist < ChannelSigner > for Arc < K >
267
266
{
268
267
// 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
277
276
let kv_store = self . clone ( ) ;
278
277
279
278
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
287
287
} )
288
288
}
289
289
@@ -295,13 +295,14 @@ impl<ChannelSigner: EcdsaChannelSigner + Send, K: KVStore + ?Sized + Sync + Send
295
295
let kv_store = self . clone ( ) ;
296
296
297
297
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
305
306
} )
306
307
}
307
308
@@ -492,7 +493,6 @@ where
492
493
fee_estimator : FE ,
493
494
}
494
495
495
-
496
496
#[ allow( dead_code) ]
497
497
impl < K : Deref , L : Deref , ES : Deref , SP : Deref , BI : Deref , FE : Deref >
498
498
MonitorUpdatingPersisterState < K , L , ES , SP , BI , FE >
@@ -728,7 +728,7 @@ where
728
728
K :: Target : KVStore + Sync ,
729
729
L :: Target : Logger ,
730
730
ES :: Target : EntropySource + Sized ,
731
- SP :: Target : SignerProvider + Send + Sync + Sized ,
731
+ SP :: Target : SignerProvider + Sync + Sized ,
732
732
BI :: Target : BroadcasterInterface ,
733
733
FE :: Target : FeeEstimator ,
734
734
{
@@ -741,9 +741,7 @@ where
741
741
742
742
let encoded_monitor = Self :: encode_monitor ( monitor) ;
743
743
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 } )
747
745
}
748
746
749
747
/// Persists a channel update, writing only the update to the parameterized [`KVStore`] if possible.
@@ -766,7 +764,14 @@ where
766
764
let monitor_latest_update_id = monitor. get_latest_update_id ( ) ;
767
765
768
766
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
770
775
} )
771
776
}
772
777
@@ -775,7 +780,6 @@ where
775
780
}
776
781
}
777
782
778
-
779
783
impl <
780
784
K : Deref + Send + Sync + ' static ,
781
785
L : Deref + Send + Sync + ' static ,
@@ -793,18 +797,18 @@ where
793
797
FE :: Target : FeeEstimator ,
794
798
{
795
799
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 ( ) ;
804
808
805
- monitor_bytes
806
- }
809
+ monitor_bytes
807
810
}
811
+ }
808
812
809
813
impl <
810
814
K : Deref + Send + Sync + ' static ,
@@ -831,12 +835,14 @@ where
831
835
let monitor_key = monitor_name. to_string ( ) ;
832
836
833
837
// 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
840
846
}
841
847
842
848
/// Persists a channel update, writing only the update to the parameterized [`KVStore`] if possible.
@@ -849,8 +855,8 @@ where
849
855
/// `update` is `None`.
850
856
/// - The update is at [`u64::MAX`], indicating an update generated by pre-0.1 LDK.
851
857
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 ,
854
860
) -> Result < ( ) , ( ) > {
855
861
const LEGACY_CLOSED_CHANNEL_UPDATE_ID : u64 = u64:: MAX ;
856
862
if let Some ( ( update_id, update) ) = update {
@@ -859,12 +865,14 @@ where
859
865
if persist_update {
860
866
let monitor_key = monitor_name. to_string ( ) ;
861
867
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
868
876
} else {
869
877
// In case of channel-close monitor update, we need to read old monitor before persisting
870
878
// the new one in order to determine the cleanup range.
@@ -877,7 +885,8 @@ where
877
885
} ;
878
886
879
887
// 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 ;
881
890
882
891
if monitor_update_status. is_ok ( ) {
883
892
let channel_closed_legacy =
@@ -936,7 +945,6 @@ where
936
945
}
937
946
}
938
947
939
-
940
948
impl < K : Deref , L : Deref , ES : Deref , SP : Deref , BI : Deref , FE : Deref >
941
949
MonitorUpdatingPersisterState < K , L , ES , SP , BI , FE >
942
950
where
0 commit comments