From ddb20f7f1ffede3a905337ff67c7acfbbb466d86 Mon Sep 17 00:00:00 2001 From: crisog Date: Fri, 2 Aug 2024 16:38:18 -0400 Subject: [PATCH] feat: use latest finalized block --- ghost-crab/src/latest_block_manager.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ghost-crab/src/latest_block_manager.rs b/ghost-crab/src/latest_block_manager.rs index 7e716b5..c8aa1ba 100644 --- a/ghost-crab/src/latest_block_manager.rs +++ b/ghost-crab/src/latest_block_manager.rs @@ -1,5 +1,5 @@ -use alloy::providers::Provider as AlloyProvider; use alloy::transports::TransportError; +use alloy::{eips::BlockNumberOrTag, providers::Provider as AlloyProvider}; use std::time::{Duration, Instant}; use crate::indexer::rpc_manager::Provider; @@ -23,7 +23,15 @@ impl LatestBlockManager { } } - let block_number = self.provider.get_block_number().await?; + let latest_finalized_block = self + .provider + .get_block_by_number(BlockNumberOrTag::Finalized, false) + .await? + .ok_or_else(|| TransportError::local_usage_str("Block not found".into()))?; + + let block_number = latest_finalized_block.header.number.ok_or_else(|| { + TransportError::local_usage_str("Block number not available in block header".into()) + })?; self.block_number = Some(block_number); self.last_fetch = Instant::now();