Skip to content

Commit

Permalink
fix(torii): improve log messages (#2463)
Browse files Browse the repository at this point in the history
commit-id:88796bb8
  • Loading branch information
lambda-0x authored Sep 24, 2024
1 parent dd8b160 commit 78250fa
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/torii/core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use tokio::sync::broadcast::Sender;
use tokio::sync::mpsc::Sender as BoundedSender;
use tokio::sync::Semaphore;
use tokio::task::JoinSet;
use tokio::time::sleep;
use tokio::time::{sleep, Instant};
use tracing::{debug, error, info, trace, warn};

use crate::processors::event_message::EventMessageProcessor;
Expand Down Expand Up @@ -171,6 +171,7 @@ impl<P: Provider + Send + Sync + std::fmt::Debug + 'static> Engine<P> {
res = self.fetch_data(head, last_pending_block_world_tx, last_pending_block_tx) => {
match res {
Ok(fetch_result) => {
let instant = Instant::now();
if erroring_out {
erroring_out = false;
backoff_delay = Duration::from_secs(1);
Expand All @@ -188,6 +189,7 @@ impl<P: Provider + Send + Sync + std::fmt::Debug + 'static> Engine<P> {
}
}
}
debug!(target: LOG_TARGET, duration = ?instant.elapsed(), "Processed fetched data.");
}
Err(e) => {
erroring_out = true;
Expand All @@ -210,16 +212,18 @@ impl<P: Provider + Send + Sync + std::fmt::Debug + 'static> Engine<P> {
last_pending_block_world_tx: Option<Felt>,
last_pending_block_tx: Option<Felt>,
) -> Result<FetchDataResult> {
let instant = Instant::now();
let latest_block_number = self.provider.block_hash_and_number().await?.block_number;

let result = if from < latest_block_number {
let from = if from == 0 { from } else { from + 1 };
debug!(target: LOG_TARGET, from = %from, to = %latest_block_number, "Fetching data for range.");
let data =
self.fetch_range(from, latest_block_number, last_pending_block_world_tx).await?;
debug!(target: LOG_TARGET, duration = ?instant.elapsed(), from = %from, to = %latest_block_number, "Fetched data for range.");
FetchDataResult::Range(data)
} else if self.config.index_pending {
let data = self.fetch_pending(latest_block_number + 1, last_pending_block_tx).await?;
debug!(target: LOG_TARGET, duration = ?instant.elapsed(), latest_block_number = %latest_block_number, "Fetched pending data.");
if let Some(data) = data {
FetchDataResult::Pending(data)
} else {
Expand Down

0 comments on commit 78250fa

Please sign in to comment.