@@ -23,6 +23,7 @@ use bp_header_chain::{FinalityProof, FindEquivocations as FindEquivocationsT};
2323use finality_relay:: FinalityProofsBuf ;
2424use futures:: future:: { BoxFuture , FutureExt } ;
2525use num_traits:: Saturating ;
26+ use std:: time:: Duration ;
2627
2728/// First step in the block checking state machine.
2829///
@@ -217,6 +218,35 @@ impl<P: EquivocationDetectionPipeline> BlockChecker<P> {
217218 Self :: ReadSyncedHeaders ( ReadSyncedHeaders { target_block_num } )
218219 }
219220
221+ pub async fn run_with_retry < ' a , SC : SourceClient < P > , TC : TargetClient < P > > (
222+ self ,
223+ source_client : & ' a mut SC ,
224+ target_client : & ' a mut TC ,
225+ finality_proofs_buf : & ' a mut FinalityProofsBuf < P > ,
226+ reporter : & ' a mut EquivocationsReporter < ' _ , P , SC > ,
227+ retry_params : ( u32 , u64 ) ,
228+ ) -> BoxFuture < ' a , Result < ( ) , Self > > {
229+ let ( retry_count, sleep_secs) = retry_params;
230+ async move {
231+ let mut block_checker = self ;
232+ for _ in 0 ..retry_count {
233+ match block_checker
234+ . run ( source_client, target_client, finality_proofs_buf, reporter)
235+ . await
236+ {
237+ Ok ( _) => return Ok ( ( ) ) ,
238+ Err ( err) => {
239+ async_std:: task:: sleep ( Duration :: from_secs ( sleep_secs) ) . await ;
240+ block_checker = err
241+ } ,
242+ }
243+ }
244+
245+ Err ( block_checker)
246+ }
247+ . boxed ( )
248+ }
249+
220250 pub fn run < ' a , SC : SourceClient < P > , TC : TargetClient < P > > (
221251 self ,
222252 source_client : & ' a mut SC ,
0 commit comments