Skip to content

Commit

Permalink
feat: use latest finalized block
Browse files Browse the repository at this point in the history
  • Loading branch information
crisog committed Aug 2, 2024
1 parent ce2ae85 commit ddb20f7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ghost-crab/src/latest_block_manager.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit ddb20f7

Please sign in to comment.