Skip to content

Commit 9f7ddb9

Browse files
committed
Implement retry in bridges equivocation loop
1 parent 1acb17a commit 9f7ddb9

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

bridges/relays/equivocation/src/block_checker.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use bp_header_chain::{FinalityProof, FindEquivocations as FindEquivocationsT};
2323
use finality_relay::FinalityProofsBuf;
2424
use futures::future::{BoxFuture, FutureExt};
2525
use 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,

bridges/relays/equivocation/src/equivocation_loop.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,12 @@ impl<P: EquivocationDetectionPipeline, SC: SourceClient<P>, TC: TargetClient<P>>
109109
self.finality_proofs_buf.fill(&mut self.finality_proofs_stream);
110110
let block_checker = BlockChecker::new(current_block_number);
111111
let _ = block_checker
112-
.run(
112+
.run_with_retry(
113113
&mut self.source_client,
114114
&mut self.target_client,
115115
&mut self.finality_proofs_buf,
116116
&mut self.reporter,
117+
(3, 5),
117118
)
118119
.await;
119120
current_block_number = current_block_number.saturating_add(1.into());

0 commit comments

Comments
 (0)