@@ -84,6 +84,8 @@ use std::time::Instant;
8484
8585#[ cfg( not( feature = "std" ) ) ]
8686use alloc:: boxed:: Box ;
87+ #[ cfg( not( feature = "std" ) ) ]
88+ use alloc:: string:: ToString ;
8789
8890/// `BackgroundProcessor` takes care of tasks that (1) need to happen periodically to keep
8991/// 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 {
415417 if $channel_manager. get_cm( ) . get_and_clear_needs_persistence( ) {
416418 log_trace!( $logger, "Persisting ChannelManager..." ) ;
417419 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( ) ,
422424 ) ) ?;
423425 log_trace!( $logger, "Done persisting ChannelManager." ) ;
424426 }
@@ -481,10 +483,10 @@ macro_rules! define_run_body {
481483 }
482484
483485 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( ) ,
488490 ) ) {
489491 log_error!( $logger, "Error: Failed to persist network graph, check your disk and permissions {}" , e)
490492 }
@@ -514,10 +516,10 @@ macro_rules! define_run_body {
514516 log_trace!( $logger, "Persisting scorer" ) ;
515517 }
516518 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( ) ,
521523 ) ) {
522524 log_error!( $logger, "Error: Failed to persist scorer, check your disk and permissions {}" , e)
523525 }
@@ -542,29 +544,29 @@ macro_rules! define_run_body {
542544 // some races where users quit while channel updates were in-flight, with
543545 // ChannelMonitor update(s) persisted without a corresponding ChannelManager update.
544546 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( ) ,
549551 ) ) ?;
550552
551553 // Persist Scorer on exit
552554 if let Some ( ref scorer) = $scorer {
553555 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( ) ,
558560 ) ) ?;
559561 }
560562
561563 // Persist NetworkGraph on exit
562564 if let Some ( network_graph) = $gossip_sync. network_graph( ) {
563565 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( ) ,
568570 ) ) ?;
569571 }
570572
@@ -725,17 +727,17 @@ use futures_util::{dummy_waker, OptionalSelector, Selector, SelectorOutput};
725727/// # }
726728/// # struct StoreSync {}
727729/// # 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()) }
732734/// # }
733735/// # struct Store {}
734736/// # 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!() }
739741/// # }
740742/// # use core::time::Duration;
741743/// # struct DefaultTimeProvider;
@@ -927,10 +929,10 @@ where
927929 log_trace ! ( logger, "Persisting scorer after update" ) ;
928930 if let Err ( e) = kv_store
929931 . 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 ( ) ,
934936 )
935937 . await
936938 {
@@ -1206,10 +1208,10 @@ impl BackgroundProcessor {
12061208 if update_scorer ( scorer, & event, duration_since_epoch) {
12071209 log_trace ! ( logger, "Persisting scorer after update" ) ;
12081210 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 ( ) ,
12131215 ) {
12141216 log_error ! ( logger, "Error: Failed to persist scorer, check your disk and permissions {}" , e)
12151217 }
@@ -1618,13 +1620,14 @@ mod tests {
16181620
16191621 impl KVStoreSync for Persister {
16201622 fn read (
1621- & self , primary_namespace : & str , secondary_namespace : & str , key : & str ,
1623+ & self , primary_namespace : String , secondary_namespace : String , key : String ,
16221624 ) -> lightning:: io:: Result < Vec < u8 > > {
16231625 self . kv_store . read ( primary_namespace, secondary_namespace, key)
16241626 }
16251627
16261628 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 > ,
16281631 ) -> lightning:: io:: Result < ( ) > {
16291632 if primary_namespace == CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE
16301633 && secondary_namespace == CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE
@@ -1666,13 +1669,13 @@ mod tests {
16661669 }
16671670
16681671 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 ,
16701673 ) -> lightning:: io:: Result < ( ) > {
16711674 self . kv_store . remove ( primary_namespace, secondary_namespace, key, lazy)
16721675 }
16731676
16741677 fn list (
1675- & self , primary_namespace : & str , secondary_namespace : & str ,
1678+ & self , primary_namespace : String , secondary_namespace : String ,
16761679 ) -> lightning:: io:: Result < Vec < String > > {
16771680 self . kv_store . list ( primary_namespace, secondary_namespace)
16781681 }
0 commit comments