Skip to content

Commit

Permalink
fix(torii): improve log messages
Browse files Browse the repository at this point in the history
commit-id:88796bb8
  • Loading branch information
lambda-0x committed Sep 22, 2024
1 parent 86dbd44 commit 880661d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 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> {
}
}
}
info!(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();

Check warning on line 215 in crates/torii/core/src/engine.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/core/src/engine.rs#L215

Added line #L215 was not covered by tests
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?;
info!(target: LOG_TARGET, duration = ?instant.elapsed(), from = %from, to = %latest_block_number, "Fetched data for range.");

Check warning on line 222 in crates/torii/core/src/engine.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/core/src/engine.rs#L222

Added line #L222 was not covered by tests
FetchDataResult::Range(data)
} else if self.config.index_pending {
let data = self.fetch_pending(latest_block_number + 1, last_pending_block_tx).await?;
info!(target: LOG_TARGET, duration = ?instant.elapsed(), latest_block_number = %latest_block_number, "Fetched pending data.");

Check warning on line 226 in crates/torii/core/src/engine.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/core/src/engine.rs#L226

Added line #L226 was not covered by tests
if let Some(data) = data {
FetchDataResult::Pending(data)
} else {
Expand Down
4 changes: 2 additions & 2 deletions crates/torii/core/src/processors/store_del_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use async_trait::async_trait;
use dojo_world::contracts::world::WorldContractReader;
use starknet::core::types::Event;
use starknet::providers::Provider;
use tracing::info;
use tracing::{debug, info};

use super::EventProcessor;
use crate::processors::{ENTITY_ID_INDEX, MODEL_INDEX};
Expand Down Expand Up @@ -49,7 +49,7 @@ where

let model = db.model(selector).await?;

info!(
debug!(
target: LOG_TARGET,
name = %model.name,
"Store delete record."
Expand Down
4 changes: 2 additions & 2 deletions crates/torii/core/src/processors/store_set_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use dojo_world::contracts::world::WorldContractReader;
use num_traits::ToPrimitive;
use starknet::core::types::Event;
use starknet::providers::Provider;
use tracing::info;
use tracing::{debug, info};

use super::EventProcessor;
use crate::processors::{ENTITY_ID_INDEX, MODEL_INDEX, NUM_KEYS_INDEX};
Expand Down Expand Up @@ -50,7 +50,7 @@ where

let model = db.model(model_id).await?;

info!(
debug!(
target: LOG_TARGET,
name = %model.name,
"Store set record.",
Expand Down
4 changes: 2 additions & 2 deletions crates/torii/core/src/processors/store_update_member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use num_traits::ToPrimitive;
use starknet::core::types::Event;
use starknet::core::utils::get_selector_from_name;
use starknet::providers::Provider;
use tracing::{info, warn};
use tracing::{debug, info, warn};

use super::EventProcessor;
use crate::processors::{ENTITY_ID_INDEX, MODEL_INDEX};
Expand Down Expand Up @@ -70,7 +70,7 @@ where
.context("member not found")?
.clone();

info!(
debug!(

Check warning on line 73 in crates/torii/core/src/processors/store_update_member.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/core/src/processors/store_update_member.rs#L73

Added line #L73 was not covered by tests
target: LOG_TARGET,
name = %model.name,
entity_id = format!("{:#x}", entity_id),
Expand Down
4 changes: 2 additions & 2 deletions crates/torii/core/src/processors/store_update_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use dojo_world::contracts::world::WorldContractReader;
use num_traits::ToPrimitive;
use starknet::core::types::Event;
use starknet::providers::Provider;
use tracing::info;
use tracing::{debug, info};

use super::EventProcessor;
use crate::processors::{ENTITY_ID_INDEX, MODEL_INDEX};
Expand Down Expand Up @@ -52,7 +52,7 @@ where

let model = db.model(model_id).await?;

info!(
debug!(
target: LOG_TARGET,
name = %model.name,
entity_id = format!("{:#x}", entity_id),
Expand Down

0 comments on commit 880661d

Please sign in to comment.