66 keeper:: keeper_metrics:: KeeperMetrics ,
77 keeper:: process_event:: process_event_with_backoff,
88 } ,
9- anyhow:: { anyhow, Result } ,
10- ethers:: {
11- providers:: { Middleware , Provider , Ws } ,
12- types:: U256 ,
13- } ,
14- futures:: StreamExt ,
9+ anyhow:: Result ,
10+ ethers:: types:: U256 ,
1511 std:: { collections:: HashSet , sync:: Arc } ,
1612 tokio:: {
1713 spawn,
@@ -176,15 +172,13 @@ pub async fn watch_blocks_wrapper(
176172 chain_state : BlockchainState ,
177173 latest_safe_block : BlockNumber ,
178174 tx : mpsc:: Sender < BlockRange > ,
179- geth_rpc_wss : Option < String > ,
180175) {
181176 let mut last_safe_block_processed = latest_safe_block;
182177 loop {
183178 if let Err ( e) = watch_blocks (
184179 chain_state. clone ( ) ,
185180 & mut last_safe_block_processed,
186181 tx. clone ( ) ,
187- geth_rpc_wss. clone ( ) ,
188182 )
189183 . in_current_span ( )
190184 . await
@@ -203,47 +197,11 @@ pub async fn watch_blocks(
203197 chain_state : BlockchainState ,
204198 last_safe_block_processed : & mut BlockNumber ,
205199 tx : mpsc:: Sender < BlockRange > ,
206- geth_rpc_wss : Option < String > ,
207200) -> Result < ( ) > {
208201 tracing:: info!( "Watching blocks to handle new events" ) ;
209202
210- let provider_option = match geth_rpc_wss {
211- Some ( wss) => Some ( match Provider :: < Ws > :: connect ( wss. clone ( ) ) . await {
212- Ok ( provider) => provider,
213- Err ( e) => {
214- tracing:: error!( "Error while connecting to wss: {}. error: {:?}" , wss, e) ;
215- return Err ( e. into ( ) ) ;
216- }
217- } ) ,
218- None => {
219- tracing:: info!( "No wss provided" ) ;
220- None
221- }
222- } ;
223-
224- let mut stream_option = match provider_option {
225- Some ( ref provider) => Some ( match provider. subscribe_blocks ( ) . await {
226- Ok ( client) => client,
227- Err ( e) => {
228- tracing:: error!( "Error while subscribing to blocks. error {:?}" , e) ;
229- return Err ( e. into ( ) ) ;
230- }
231- } ) ,
232- None => None ,
233- } ;
234-
235203 loop {
236- match stream_option {
237- Some ( ref mut stream) => {
238- if stream. next ( ) . await . is_none ( ) {
239- tracing:: error!( "Error blocks subscription stream ended" ) ;
240- return Err ( anyhow ! ( "Error blocks subscription stream ended" ) ) ;
241- }
242- }
243- None => {
244- time:: sleep ( POLL_INTERVAL ) . await ;
245- }
246- }
204+ time:: sleep ( POLL_INTERVAL ) . await ;
247205
248206 let latest_safe_block = get_latest_safe_block ( & chain_state) . in_current_span ( ) . await ;
249207 if latest_safe_block > * last_safe_block_processed {
0 commit comments