33 api:: { self , ApiBlockChainState , BlockchainState , ChainId } ,
44 chain:: ethereum:: InstrumentedPythContract ,
55 command:: register_provider:: CommitmentMetadata ,
6- config:: { Commitment , Config , EthereumConfig , RunOptions } ,
6+ config:: { Commitment , Config , EthereumConfig , ProviderConfig , RunOptions } ,
77 eth_utils:: traced_client:: RpcMetrics ,
88 keeper:: { self , keeper_metrics:: KeeperMetrics } ,
99 state:: { HashChainState , PebbleHashChain } ,
@@ -104,36 +104,29 @@ pub async fn run(opts: &RunOptions) -> Result<()> {
104104 let chains = chains. clone ( ) ;
105105 let secret_copy = secret. clone ( ) ;
106106 let rpc_metrics = rpc_metrics. clone ( ) ;
107+ let provider_config = config. provider . clone ( ) ;
107108 spawn ( async move {
108- let state = setup_chain_state (
109- & config. provider . address ,
110- & secret_copy,
111- config. provider . chain_sample_interval ,
112- & chain_id,
113- & chain_config,
114- rpc_metrics. clone ( ) ,
115- )
116- . await ;
117- match state {
118- Ok ( state) => {
119- keeper_metrics. add_chain ( chain_id. clone ( ) , state. provider_address ) ;
120- chains. write ( ) . await . insert (
121- chain_id. clone ( ) ,
122- ApiBlockChainState :: Initialized ( state. clone ( ) ) ,
123- ) ;
124- if let Some ( keeper_private_key) = keeper_private_key_option {
125- spawn ( keeper:: run_keeper_threads (
126- keeper_private_key,
127- chain_config,
128- state,
129- keeper_metrics. clone ( ) ,
130- rpc_metrics. clone ( ) ,
131- ) ) ;
109+ loop {
110+ let setup_result = setup_chain (
111+ provider_config. clone ( ) ,
112+ & chain_id,
113+ chain_config. clone ( ) ,
114+ keeper_metrics. clone ( ) ,
115+ keeper_private_key_option. clone ( ) ,
116+ chains. clone ( ) ,
117+ & secret_copy,
118+ rpc_metrics. clone ( ) ,
119+ )
120+ . await ;
121+ match setup_result {
122+ Ok ( _) => {
123+ tracing:: info!( "Chain {} initialized successfully" , chain_id) ;
124+ break ;
125+ }
126+ Err ( e) => {
127+ tracing:: error!( "Failed to initialize chain {}: {}" , chain_id, e) ;
128+ tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 15 ) ) . await ;
132129 }
133- }
134- Err ( e) => {
135- tracing:: error!( "Failed to setup {} {}" , chain_id, e) ;
136- //TODO: Retry
137130 }
138131 }
139132 } ) ;
@@ -155,6 +148,44 @@ pub async fn run(opts: &RunOptions) -> Result<()> {
155148 Ok ( ( ) )
156149}
157150
151+ #[ allow( clippy:: too_many_arguments) ]
152+ async fn setup_chain (
153+ provider_config : ProviderConfig ,
154+ chain_id : & ChainId ,
155+ chain_config : EthereumConfig ,
156+ keeper_metrics : Arc < KeeperMetrics > ,
157+ keeper_private_key_option : Option < String > ,
158+ chains : Arc < RwLock < HashMap < ChainId , ApiBlockChainState > > > ,
159+ secret_copy : & str ,
160+ rpc_metrics : Arc < RpcMetrics > ,
161+ ) -> Result < ( ) > {
162+ let state = setup_chain_state (
163+ & provider_config. address ,
164+ secret_copy,
165+ provider_config. chain_sample_interval ,
166+ chain_id,
167+ & chain_config,
168+ rpc_metrics. clone ( ) ,
169+ )
170+ . await ?;
171+ keeper_metrics. add_chain ( chain_id. clone ( ) , state. provider_address ) ;
172+ chains. write ( ) . await . insert (
173+ chain_id. clone ( ) ,
174+ ApiBlockChainState :: Initialized ( state. clone ( ) ) ,
175+ ) ;
176+ if let Some ( keeper_private_key) = keeper_private_key_option {
177+ keeper:: run_keeper_threads (
178+ keeper_private_key,
179+ chain_config,
180+ state,
181+ keeper_metrics. clone ( ) ,
182+ rpc_metrics. clone ( ) ,
183+ )
184+ . await ?;
185+ }
186+ Ok ( ( ) )
187+ }
188+
158189async fn setup_chain_state (
159190 provider : & Address ,
160191 secret : & str ,
0 commit comments