Skip to content

Commit

Permalink
more verbose error handling & get rid of bit masking task id
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Jan 15, 2025
1 parent 312befa commit 2ad2772
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 17 deletions.
4 changes: 2 additions & 2 deletions crates/torii/indexer/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,14 +890,14 @@ impl<P: Provider + Send + Sync + std::fmt::Debug + 'static> Engine<P> {
"ModelRegistered" | "EventRegistered" => {
let mut hasher = DefaultHasher::new();
event.keys.iter().for_each(|k| k.hash(&mut hasher));
let hash = hasher.finish() & 0x00FFFFFFFFFFFFFF;
let hash = hasher.finish();
(0usize, hash) // Priority 0 (highest) for model/event registration
}
"StoreSetRecord" | "StoreUpdateRecord" | "StoreUpdateMember" | "StoreDelRecord" => {
let mut hasher = DefaultHasher::new();
event.keys[1].hash(&mut hasher);
event.keys[2].hash(&mut hasher);
let hash = hasher.finish() & 0x00FFFFFFFFFFFFFF;
let hash = hasher.finish();
(2usize, hash) // Priority 2 (lower) for store operations
}
_ => (0, 0) // No parallelization for other events
Expand Down
12 changes: 9 additions & 3 deletions crates/torii/indexer/src/processors/store_del_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ where
block_timestamp: u64,
event_id: &str,
event: &Event,
_config: &EventProcessorConfig,
config: &EventProcessorConfig,
) -> Result<(), Error> {
// Torii version is coupled to the world version, so we can expect the event to be well
// formed.
Expand All @@ -55,15 +55,21 @@ where
// This can happen if only specific namespaces are indexed.
let model = match db.model(event.selector).await {
Ok(m) => m,
Err(e) if e.to_string().contains("no rows") => {
Err(e) if e.to_string().contains("no rows") && !config.namespaces.is_empty() => {
debug!(
target: LOG_TARGET,
selector = %event.selector,
"Model does not exist, skipping."
);
return Ok(());
}
Err(e) => return Err(e),
Err(e) => {
return Err(anyhow::anyhow!(
"Failed to retrieve model with selector {:#x}: {}",
event.selector,
e
))
}
};

info!(
Expand Down
12 changes: 9 additions & 3 deletions crates/torii/indexer/src/processors/store_set_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where
block_timestamp: u64,
event_id: &str,
event: &Event,
_config: &EventProcessorConfig,
config: &EventProcessorConfig,
) -> Result<(), Error> {
// Torii version is coupled to the world version, so we can expect the event to be well
// formed.
Expand All @@ -56,15 +56,21 @@ where
// This can happen if only specific namespaces are indexed.
let model = match db.model(event.selector).await {
Ok(m) => m,
Err(e) if e.to_string().contains("no rows") => {
Err(e) if e.to_string().contains("no rows") && !config.namespaces.is_empty() => {
debug!(
target: LOG_TARGET,
selector = %event.selector,
"Model does not exist, skipping."
);
return Ok(());
}
Err(e) => return Err(e),
Err(e) => {
return Err(anyhow::anyhow!(
"Failed to retrieve model with selector {:#x}: {}",
event.selector,
e
))
}
};

info!(
Expand Down
21 changes: 15 additions & 6 deletions crates/torii/indexer/src/processors/store_update_member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use starknet::core::types::Event;
use starknet::core::utils::get_selector_from_name;
use starknet::providers::Provider;
use torii_sqlite::Sql;
use tracing::info;
use tracing::{debug, info};

use super::{EventProcessor, EventProcessorConfig};

Expand Down Expand Up @@ -37,7 +37,7 @@ where
block_timestamp: u64,
event_id: &str,
event: &Event,
_config: &EventProcessorConfig,
config: &EventProcessorConfig,
) -> Result<(), Error> {
// Torii version is coupled to the world version, so we can expect the event to be well
// formed.
Expand All @@ -61,11 +61,20 @@ where
// This can happen if only specific namespaces are indexed.
let model = match db.model(model_selector).await {
Ok(m) => m,
Err(e) if e.to_string().contains("no rows") && !config.namespaces.is_empty() => {
debug!(
target: LOG_TARGET,
selector = %model_selector,
"Model does not exist, skipping."
);
return Ok(());
}
Err(e) => {
if e.to_string().contains("no rows") {
return Ok(());
}
return Err(e);
return Err(anyhow::anyhow!(
"Failed to retrieve model with selector {:#x}: {}",
event.selector,
e
))
}
};

Expand Down
12 changes: 9 additions & 3 deletions crates/torii/indexer/src/processors/store_update_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where
block_timestamp: u64,
event_id: &str,
event: &Event,
_config: &EventProcessorConfig,
config: &EventProcessorConfig,
) -> Result<(), Error> {
// Torii version is coupled to the world version, so we can expect the event to be well
// formed.
Expand All @@ -59,15 +59,21 @@ where
// This can happen if only specific namespaces are indexed.
let model = match db.model(event.selector).await {
Ok(m) => m,
Err(e) if e.to_string().contains("no rows") => {
Err(e) if e.to_string().contains("no rows") && !config.namespaces.is_empty() => {
debug!(
target: LOG_TARGET,
selector = %event.selector,
"Model does not exist, skipping."
);
return Ok(());
}
Err(e) => return Err(e),
Err(e) => {
return Err(anyhow::anyhow!(
"Failed to retrieve model with selector {:#x}: {}",
event.selector,
e
))
}
};

info!(
Expand Down

0 comments on commit 2ad2772

Please sign in to comment.