From c5803ad3a9657c2ae032fb615e76fb404238d65f Mon Sep 17 00:00:00 2001 From: 0xOsiris Date: Thu, 31 Oct 2024 13:30:27 -0700 Subject: [PATCH 1/3] feat: lag block scanner stream behind finality --- src/tree/block_scanner.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/tree/block_scanner.rs b/src/tree/block_scanner.rs index 5b65f9b..ac2f2ce 100644 --- a/src/tree/block_scanner.rs +++ b/src/tree/block_scanner.rs @@ -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, From bf0372e48beda6bde8d99ba5df9c7d09e199ead8 Mon Sep 17 00:00:00 2001 From: 0xOsiris Date: Thu, 31 Oct 2024 13:42:53 -0700 Subject: [PATCH 2/3] chore: fmt --- src/tasks/mod.rs | 4 +++- src/tree/block_scanner.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tasks/mod.rs b/src/tasks/mod.rs index 01875e6..aa2db6f 100644 --- a/src/tasks/mod.rs +++ b/src/tasks/mod.rs @@ -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); diff --git a/src/tree/block_scanner.rs b/src/tree/block_scanner.rs index ac2f2ce..4e393c2 100644 --- a/src/tree/block_scanner.rs +++ b/src/tree/block_scanner.rs @@ -90,7 +90,7 @@ where .expect("no finalized block found"); latest = finalized.header.number; - + if latest < next_block { tokio::time::sleep(Duration::from_secs( BLOCK_SCANNER_SLEEP_TIME, From e7e5a625d4cf84dbe3986c279b83100ebe7cce54 Mon Sep 17 00:00:00 2001 From: 0xOsiris Date: Thu, 31 Oct 2024 13:58:35 -0700 Subject: [PATCH 3/3] increase attempt_async! timeout --- tests/common/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 5efbc63..ec5123c 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -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 {