@@ -33,6 +33,7 @@ use std::{
3333
3434use mempool:: tx_accumulator:: PackingStrategy ;
3535use read:: ReadOnlyController ;
36+ use sync:: InSync ;
3637use synced_controller:: SyncedController ;
3738use utils:: tap_error_log:: LogError ;
3839
@@ -89,6 +90,8 @@ pub enum ControllerError<T: NodeInterface> {
8990 StakingRunning ,
9091 #[ error( "End-to-end encryption error: {0}" ) ]
9192 EndToEndEncryptionError ( #[ from] crypto:: ephemeral_e2e:: error:: Error ) ,
93+ #[ error( "The node is not in sync yet" ) ]
94+ NodeNotInSyncYet ,
9295}
9396
9497#[ derive( Clone , Copy ) ]
@@ -136,7 +139,7 @@ impl<T: NodeInterface + Clone + Send + Sync + 'static, W: WalletEvents> Controll
136139 } ;
137140
138141 log:: info!( "Syncing the wallet..." ) ;
139- controller. sync_once ( ) . await ?;
142+ controller. try_sync_once ( ) . await ?;
140143
141144 Ok ( controller)
142145 }
@@ -527,13 +530,29 @@ impl<T: NodeInterface + Clone + Send + Sync + 'static, W: WalletEvents> Controll
527530
528531 /// Synchronize the wallet to the current node tip height and return
529532 pub async fn sync_once ( & mut self ) -> Result < ( ) , ControllerError < T > > {
533+ let res = sync:: sync_once (
534+ & self . chain_config ,
535+ & self . rpc_client ,
536+ & mut self . wallet ,
537+ & self . wallet_events ,
538+ )
539+ . await ?;
540+
541+ match res {
542+ InSync :: Synced => Ok ( ( ) ) ,
543+ InSync :: NodeOutOfSync => Err ( ControllerError :: NodeNotInSyncYet ) ,
544+ }
545+ }
546+
547+ pub async fn try_sync_once ( & mut self ) -> Result < ( ) , ControllerError < T > > {
530548 sync:: sync_once (
531549 & self . chain_config ,
532550 & self . rpc_client ,
533551 & mut self . wallet ,
534552 & self . wallet_events ,
535553 )
536554 . await ?;
555+
537556 Ok ( ( ) )
538557 }
539558
0 commit comments