@@ -84,6 +84,8 @@ use std::time::Instant;
84
84
85
85
#[ cfg( not( feature = "std" ) ) ]
86
86
use alloc:: boxed:: Box ;
87
+ #[ cfg( not( feature = "std" ) ) ]
88
+ use alloc:: string:: ToString ;
87
89
88
90
/// `BackgroundProcessor` takes care of tasks that (1) need to happen periodically to keep
89
91
/// Rust-Lightning running properly, and (2) either can or should be run in the background. Its
@@ -415,10 +417,10 @@ macro_rules! define_run_body {
415
417
if $channel_manager. get_cm( ) . get_and_clear_needs_persistence( ) {
416
418
log_trace!( $logger, "Persisting ChannelManager..." ) ;
417
419
maybe_await!( $async_persist, $kv_store. write(
418
- CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE ,
419
- CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE ,
420
- CHANNEL_MANAGER_PERSISTENCE_KEY ,
421
- & $channel_manager. get_cm( ) . encode( ) ,
420
+ CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE . to_string ( ) ,
421
+ CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE . to_string ( ) ,
422
+ CHANNEL_MANAGER_PERSISTENCE_KEY . to_string ( ) ,
423
+ $channel_manager. get_cm( ) . encode( ) ,
422
424
) ) ?;
423
425
log_trace!( $logger, "Done persisting ChannelManager." ) ;
424
426
}
@@ -481,10 +483,10 @@ macro_rules! define_run_body {
481
483
}
482
484
483
485
if let Err ( e) = maybe_await!( $async_persist, $kv_store. write(
484
- NETWORK_GRAPH_PERSISTENCE_PRIMARY_NAMESPACE ,
485
- NETWORK_GRAPH_PERSISTENCE_SECONDARY_NAMESPACE ,
486
- NETWORK_GRAPH_PERSISTENCE_KEY ,
487
- & network_graph. encode( ) ,
486
+ NETWORK_GRAPH_PERSISTENCE_PRIMARY_NAMESPACE . to_string ( ) ,
487
+ NETWORK_GRAPH_PERSISTENCE_SECONDARY_NAMESPACE . to_string ( ) ,
488
+ NETWORK_GRAPH_PERSISTENCE_KEY . to_string ( ) ,
489
+ network_graph. encode( ) ,
488
490
) ) {
489
491
log_error!( $logger, "Error: Failed to persist network graph, check your disk and permissions {}" , e)
490
492
}
@@ -514,10 +516,10 @@ macro_rules! define_run_body {
514
516
log_trace!( $logger, "Persisting scorer" ) ;
515
517
}
516
518
if let Err ( e) = maybe_await!( $async_persist, $kv_store. write(
517
- SCORER_PERSISTENCE_PRIMARY_NAMESPACE ,
518
- SCORER_PERSISTENCE_SECONDARY_NAMESPACE ,
519
- SCORER_PERSISTENCE_KEY ,
520
- & scorer. encode( ) ,
519
+ SCORER_PERSISTENCE_PRIMARY_NAMESPACE . to_string ( ) ,
520
+ SCORER_PERSISTENCE_SECONDARY_NAMESPACE . to_string ( ) ,
521
+ SCORER_PERSISTENCE_KEY . to_string ( ) ,
522
+ scorer. encode( ) ,
521
523
) ) {
522
524
log_error!( $logger, "Error: Failed to persist scorer, check your disk and permissions {}" , e)
523
525
}
@@ -542,29 +544,29 @@ macro_rules! define_run_body {
542
544
// some races where users quit while channel updates were in-flight, with
543
545
// ChannelMonitor update(s) persisted without a corresponding ChannelManager update.
544
546
maybe_await!( $async_persist, $kv_store. write(
545
- CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE ,
546
- CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE ,
547
- CHANNEL_MANAGER_PERSISTENCE_KEY ,
548
- & $channel_manager. get_cm( ) . encode( ) ,
547
+ CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE . to_string ( ) ,
548
+ CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE . to_string ( ) ,
549
+ CHANNEL_MANAGER_PERSISTENCE_KEY . to_string ( ) ,
550
+ $channel_manager. get_cm( ) . encode( ) ,
549
551
) ) ?;
550
552
551
553
// Persist Scorer on exit
552
554
if let Some ( ref scorer) = $scorer {
553
555
maybe_await!( $async_persist, $kv_store. write(
554
- SCORER_PERSISTENCE_PRIMARY_NAMESPACE ,
555
- SCORER_PERSISTENCE_SECONDARY_NAMESPACE ,
556
- SCORER_PERSISTENCE_KEY ,
557
- & scorer. encode( ) ,
556
+ SCORER_PERSISTENCE_PRIMARY_NAMESPACE . to_string ( ) ,
557
+ SCORER_PERSISTENCE_SECONDARY_NAMESPACE . to_string ( ) ,
558
+ SCORER_PERSISTENCE_KEY . to_string ( ) ,
559
+ scorer. encode( ) ,
558
560
) ) ?;
559
561
}
560
562
561
563
// Persist NetworkGraph on exit
562
564
if let Some ( network_graph) = $gossip_sync. network_graph( ) {
563
565
maybe_await!( $async_persist, $kv_store. write(
564
- NETWORK_GRAPH_PERSISTENCE_PRIMARY_NAMESPACE ,
565
- NETWORK_GRAPH_PERSISTENCE_SECONDARY_NAMESPACE ,
566
- NETWORK_GRAPH_PERSISTENCE_KEY ,
567
- & network_graph. encode( ) ,
566
+ NETWORK_GRAPH_PERSISTENCE_PRIMARY_NAMESPACE . to_string ( ) ,
567
+ NETWORK_GRAPH_PERSISTENCE_SECONDARY_NAMESPACE . to_string ( ) ,
568
+ NETWORK_GRAPH_PERSISTENCE_KEY . to_string ( ) ,
569
+ network_graph. encode( ) ,
568
570
) ) ?;
569
571
}
570
572
@@ -725,17 +727,17 @@ use futures_util::{dummy_waker, OptionalSelector, Selector, SelectorOutput};
725
727
/// # }
726
728
/// # struct StoreSync {}
727
729
/// # impl lightning::util::persist::KVStoreSync for StoreSync {
728
- /// # fn read(&self, primary_namespace: &str , secondary_namespace: &str , key: &str ) -> io::Result<Vec<u8>> { Ok(Vec::new()) }
729
- /// # fn write(&self, primary_namespace: &str , secondary_namespace: &str , key: &str , buf: &[u8] ) -> io::Result<()> { Ok(()) }
730
- /// # fn remove(&self, primary_namespace: &str , secondary_namespace: &str , key: &str , lazy: bool) -> io::Result<()> { Ok(()) }
731
- /// # fn list(&self, primary_namespace: &str , secondary_namespace: &str ) -> io::Result<Vec<String>> { Ok(Vec::new()) }
730
+ /// # fn read(&self, primary_namespace: String , secondary_namespace: String , key: String ) -> io::Result<Vec<u8>> { Ok(Vec::new()) }
731
+ /// # fn write(&self, primary_namespace: String , secondary_namespace: String , key: String , buf: Vec<u8> ) -> io::Result<()> { Ok(()) }
732
+ /// # fn remove(&self, primary_namespace: String , secondary_namespace: String , key: String , lazy: bool) -> io::Result<()> { Ok(()) }
733
+ /// # fn list(&self, primary_namespace: String , secondary_namespace: String ) -> io::Result<Vec<String>> { Ok(Vec::new()) }
732
734
/// # }
733
735
/// # struct Store {}
734
736
/// # impl lightning::util::persist::KVStore for Store {
735
- /// # fn read(&self, primary_namespace: &str , secondary_namespace: &str , key: &str ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, io::Error>> + 'static + Send>> { todo!() }
736
- /// # fn write(&self, primary_namespace: &str , secondary_namespace: &str , key: &str , buf: &[u8] ) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + 'static + Send>> { todo!() }
737
- /// # fn remove(&self, primary_namespace: &str , secondary_namespace: &str , key: &str , lazy: bool) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + 'static + Send>> { todo!() }
738
- /// # fn list(&self, primary_namespace: &str , secondary_namespace: &str ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, io::Error>> + 'static + Send>> { todo!() }
737
+ /// # fn read(&self, primary_namespace: String , secondary_namespace: String , key: String ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, io::Error>> + 'static + Send>> { todo!() }
738
+ /// # fn write(&self, primary_namespace: String , secondary_namespace: String , key: String , buf: Vec<u8> ) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + 'static + Send>> { todo!() }
739
+ /// # fn remove(&self, primary_namespace: String , secondary_namespace: String , key: String , lazy: bool) -> Pin<Box<dyn Future<Output = Result<(), io::Error>> + 'static + Send>> { todo!() }
740
+ /// # fn list(&self, primary_namespace: String , secondary_namespace: String ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, io::Error>> + 'static + Send>> { todo!() }
739
741
/// # }
740
742
/// # use core::time::Duration;
741
743
/// # struct DefaultTimeProvider;
@@ -927,10 +929,10 @@ where
927
929
log_trace ! ( logger, "Persisting scorer after update" ) ;
928
930
if let Err ( e) = kv_store
929
931
. write (
930
- SCORER_PERSISTENCE_PRIMARY_NAMESPACE ,
931
- SCORER_PERSISTENCE_SECONDARY_NAMESPACE ,
932
- SCORER_PERSISTENCE_KEY ,
933
- & scorer. encode ( ) ,
932
+ SCORER_PERSISTENCE_PRIMARY_NAMESPACE . to_string ( ) ,
933
+ SCORER_PERSISTENCE_SECONDARY_NAMESPACE . to_string ( ) ,
934
+ SCORER_PERSISTENCE_KEY . to_string ( ) ,
935
+ scorer. encode ( ) ,
934
936
)
935
937
. await
936
938
{
@@ -1206,10 +1208,10 @@ impl BackgroundProcessor {
1206
1208
if update_scorer ( scorer, & event, duration_since_epoch) {
1207
1209
log_trace ! ( logger, "Persisting scorer after update" ) ;
1208
1210
if let Err ( e) = kv_store. write (
1209
- SCORER_PERSISTENCE_PRIMARY_NAMESPACE ,
1210
- SCORER_PERSISTENCE_SECONDARY_NAMESPACE ,
1211
- SCORER_PERSISTENCE_KEY ,
1212
- & scorer. encode ( ) ,
1211
+ SCORER_PERSISTENCE_PRIMARY_NAMESPACE . to_string ( ) ,
1212
+ SCORER_PERSISTENCE_SECONDARY_NAMESPACE . to_string ( ) ,
1213
+ SCORER_PERSISTENCE_KEY . to_string ( ) ,
1214
+ scorer. encode ( ) ,
1213
1215
) {
1214
1216
log_error ! ( logger, "Error: Failed to persist scorer, check your disk and permissions {}" , e)
1215
1217
}
@@ -1618,13 +1620,14 @@ mod tests {
1618
1620
1619
1621
impl KVStoreSync for Persister {
1620
1622
fn read (
1621
- & self , primary_namespace : & str , secondary_namespace : & str , key : & str ,
1623
+ & self , primary_namespace : String , secondary_namespace : String , key : String ,
1622
1624
) -> lightning:: io:: Result < Vec < u8 > > {
1623
1625
self . kv_store . read ( primary_namespace, secondary_namespace, key)
1624
1626
}
1625
1627
1626
1628
fn write (
1627
- & self , primary_namespace : & str , secondary_namespace : & str , key : & str , buf : & [ u8 ] ,
1629
+ & self , primary_namespace : String , secondary_namespace : String , key : String ,
1630
+ buf : Vec < u8 > ,
1628
1631
) -> lightning:: io:: Result < ( ) > {
1629
1632
if primary_namespace == CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE
1630
1633
&& secondary_namespace == CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE
@@ -1666,13 +1669,13 @@ mod tests {
1666
1669
}
1667
1670
1668
1671
fn remove (
1669
- & self , primary_namespace : & str , secondary_namespace : & str , key : & str , lazy : bool ,
1672
+ & self , primary_namespace : String , secondary_namespace : String , key : String , lazy : bool ,
1670
1673
) -> lightning:: io:: Result < ( ) > {
1671
1674
self . kv_store . remove ( primary_namespace, secondary_namespace, key, lazy)
1672
1675
}
1673
1676
1674
1677
fn list (
1675
- & self , primary_namespace : & str , secondary_namespace : & str ,
1678
+ & self , primary_namespace : String , secondary_namespace : String ,
1676
1679
) -> lightning:: io:: Result < Vec < String > > {
1677
1680
self . kv_store . list ( primary_namespace, secondary_namespace)
1678
1681
}
0 commit comments