Skip to content

Commit

Permalink
Merge pull request #135 from worldcoin/osiris/reorg-awareness
Browse files Browse the repository at this point in the history
feat: lag block scanner stream behind finality
  • Loading branch information
0xOsiris authored Nov 6, 2024
2 parents 41c4246 + e7e5a62 commit 38adfec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ pub async fn monitor_tasks(

#[cfg(test)]
mod test {
use super::*;
use std::time::Instant;

use tokio::time::sleep;

use super::*;

#[tokio::test]
async fn test_monitor_tasks() {
let shutdown_delay = Duration::from_millis(100);
Expand Down
17 changes: 14 additions & 3 deletions src/tree/block_scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,27 @@ where
// Update the latest block number only if required
if try_to > latest {
let provider = self.provider.clone();
latest = retry(
let finalized = retry(
Duration::from_millis(100),
Some(Duration::from_secs(60)),
move || {
let provider = provider.clone();
async move { provider.get_block_number().await }
async move {
provider
.get_block_by_number(
BlockNumberOrTag::Finalized,
false,
)
.await
}
},
)
.await
.expect("failed to fetch latest block after retry");
.expect("failed to fetch latest block after retry")
.expect("no finalized block found");

latest = finalized.header.number;

if latest < next_block {
tokio::time::sleep(Duration::from_secs(
BLOCK_SCANNER_SLEEP_TIME,
Expand Down
4 changes: 2 additions & 2 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use world_tree::tree::WorldTreeProvider;
macro_rules! attempt_async {
($e:expr) => {
{
const MAX_ATTEMPTS: usize = 10;
const SLEEP_DURATION: Duration = Duration::from_secs(5);
const MAX_ATTEMPTS: usize = 20;
const SLEEP_DURATION: Duration = Duration::from_secs(12);
let mut attempt = 0;

loop {
Expand Down

0 comments on commit 38adfec

Please sign in to comment.