Skip to content

Commit

Permalink
feat(torii): read only torii
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Dec 11, 2024
1 parent bcd581e commit aa3755a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
54 changes: 31 additions & 23 deletions bin/torii/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -149,26 +146,32 @@ async fn main() -> anyhow::Result<()> {
flags.insert(IndexingFlags::PENDING_BLOCKS);
}

let mut engine: Engine<Arc<JsonRpcClient<HttpTransport>>> = 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<Engine<Arc<JsonRpcClient<HttpTransport>>>> = 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(
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions crates/torii/cli/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
Expand Down

0 comments on commit aa3755a

Please sign in to comment.