diff --git a/bin/torii/src/main.rs b/bin/torii/src/main.rs index f10f6ca3c6..c8dbce5475 100644 --- a/bin/torii/src/main.rs +++ b/bin/torii/src/main.rs @@ -115,9 +115,6 @@ async fn main() -> anyhow::Result<()> { let provider: Arc<_> = JsonRpcClient::new(HttpTransport::new(args.rpc)).into(); - // Get world address - let world = WorldContractReader::new(world_address, provider.clone()); - let (mut executor, sender) = Executor::new( pool.clone(), shutdown_tx.clone(), @@ -149,26 +146,32 @@ async fn main() -> anyhow::Result<()> { flags.insert(IndexingFlags::PENDING_BLOCKS); } - let mut engine: Engine>> = Engine::new( - world, - db.clone(), - provider.clone(), - processors, - EngineConfig { - max_concurrent_tasks: args.indexing.max_concurrent_tasks, - blocks_chunk_size: args.indexing.blocks_chunk_size, - events_chunk_size: args.indexing.events_chunk_size, - polling_interval: Duration::from_millis(args.indexing.polling_interval), - flags, - event_processor_config: EventProcessorConfig { - historical_events: args.events.historical.into_iter().collect(), - namespaces: args.indexing.namespaces.into_iter().collect(), + // Get world address + let world = WorldContractReader::new(world_address, provider.clone()); + let mut engine: Option>>> = if args.indexing.enabled { + Some(Engine::new( + world, + db.clone(), + provider.clone(), + processors, + EngineConfig { + max_concurrent_tasks: args.indexing.max_concurrent_tasks, + blocks_chunk_size: args.indexing.blocks_chunk_size, + events_chunk_size: args.indexing.events_chunk_size, + polling_interval: Duration::from_millis(args.indexing.polling_interval), + flags, + event_processor_config: EventProcessorConfig { + historical_events: args.events.historical.into_iter().collect(), + namespaces: args.indexing.namespaces.into_iter().collect(), + }, }, - }, - shutdown_tx.clone(), - Some(block_tx), - &args.indexing.contracts, - ); + shutdown_tx.clone(), + Some(block_tx), + &args.indexing.contracts, + )) + } else { + None + }; let shutdown_rx = shutdown_tx.subscribe(); let (grpc_addr, grpc_server) = torii_grpc::server::new( @@ -247,7 +250,12 @@ async fn main() -> anyhow::Result<()> { tokio::spawn(server.start(addr)); } - let engine_handle = tokio::spawn(async move { engine.start().await }); + let engine_handle = tokio::spawn(async move { + if let Some(engine) = &mut engine { + return engine.start().await; + } + Ok(()) + }); let proxy_server_handle = tokio::spawn(async move { proxy_server.start(shutdown_tx.subscribe()).await }); let graphql_server_handle = tokio::spawn(graphql_server); diff --git a/crates/torii/cli/src/options.rs b/crates/torii/cli/src/options.rs index eaffd58b2d..b7a25b03c5 100644 --- a/crates/torii/cli/src/options.rs +++ b/crates/torii/cli/src/options.rs @@ -90,6 +90,10 @@ impl Default for RelayOptions { #[derive(Debug, clap::Args, Clone, Serialize, Deserialize, PartialEq)] #[command(next_help_heading = "Indexing options")] pub struct IndexingOptions { + /// If indexing should be enabled + #[arg(long, default_value_t = true, help = "If indexing should be enabled.")] + pub enabled: bool, + /// Chunk size of the events page when indexing using events #[arg(long = "indexing.events_chunk_size", default_value_t = DEFAULT_EVENTS_CHUNK_SIZE, help = "Chunk size of the events page to fetch from the sequencer.")] #[serde(default = "default_events_chunk_size")] @@ -162,6 +166,7 @@ pub struct IndexingOptions { impl Default for IndexingOptions { fn default() -> Self { Self { + enabled: true, events_chunk_size: DEFAULT_EVENTS_CHUNK_SIZE, blocks_chunk_size: DEFAULT_BLOCKS_CHUNK_SIZE, pending: true, @@ -177,6 +182,10 @@ impl Default for IndexingOptions { impl IndexingOptions { pub fn merge(&mut self, other: Option<&Self>) { if let Some(other) = other { + if self.enabled { + self.enabled = other.enabled; + } + if self.events_chunk_size == DEFAULT_EVENTS_CHUNK_SIZE { self.events_chunk_size = other.events_chunk_size; }