Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(torii): read only torii #2795

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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,
Comment on lines +93 to +95
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we want this to be disabled? For replicates syncing from a single indexing Torii?

Comment on lines +93 to +95
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// If indexing should be enabled
#[arg(long, default_value_t = true, help = "If indexing should be enabled.")]
pub enabled: bool,
/// If indexing should be enabled
#[arg(long, default_value_t = true, help = "If indexing should be enabled.")]
#[serde(default)]
pub enabled: bool,

Add serde default to ensure it's not required to be given in configuration files.


/// 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
Loading