From 8d0b39ffbd8edb1fc1e111bb3ef17dd0fa8162b9 Mon Sep 17 00:00:00 2001 From: glihm Date: Wed, 11 Dec 2024 14:09:30 -0600 Subject: [PATCH] feat: add the world block to start syncing Currently this commit will break the indexing of tokens since they need to start from block 0. --- bin/torii/src/main.rs | 1 + crates/torii/cli/src/options.rs | 18 ++++++++++++++++++ crates/torii/core/src/engine.rs | 4 +++- crates/torii/grpc/src/server/mod.rs | 2 +- eternum.toml | 3 ++- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/bin/torii/src/main.rs b/bin/torii/src/main.rs index f10f6ca3c6..4eafafbe26 100644 --- a/bin/torii/src/main.rs +++ b/bin/torii/src/main.rs @@ -164,6 +164,7 @@ async fn main() -> anyhow::Result<()> { historical_events: args.events.historical.into_iter().collect(), namespaces: args.indexing.namespaces.into_iter().collect(), }, + world_block: args.indexing.world_block, }, shutdown_tx.clone(), Some(block_tx), diff --git a/crates/torii/cli/src/options.rs b/crates/torii/cli/src/options.rs index eaffd58b2d..9a824beb09 100644 --- a/crates/torii/cli/src/options.rs +++ b/crates/torii/cli/src/options.rs @@ -157,6 +157,19 @@ pub struct IndexingOptions { )] #[serde(default)] pub namespaces: Vec, + + /// The block number to start indexing the world from. + /// + /// Warning: In the current implementation, this will break the indexing of tokens, if any. + /// Since the tokens require the chain to be indexed from the beginning, to ensure correct + /// balance updates. + #[arg( + long = "indexing.world_block", + help = "The block number to start indexing from.", + default_value_t = 0 + )] + #[serde(default)] + pub world_block: u64, } impl Default for IndexingOptions { @@ -170,6 +183,7 @@ impl Default for IndexingOptions { polling_interval: DEFAULT_POLLING_INTERVAL, max_concurrent_tasks: DEFAULT_MAX_CONCURRENT_TASKS, namespaces: vec![], + world_block: 0, } } } @@ -208,6 +222,10 @@ impl IndexingOptions { if self.namespaces.is_empty() { self.namespaces = other.namespaces.clone(); } + + if self.world_block == 0 { + self.world_block = other.world_block; + } } } } diff --git a/crates/torii/core/src/engine.rs b/crates/torii/core/src/engine.rs index 73689996b8..f4279e6a5d 100644 --- a/crates/torii/core/src/engine.rs +++ b/crates/torii/core/src/engine.rs @@ -148,6 +148,7 @@ pub struct EngineConfig { pub max_concurrent_tasks: usize, pub flags: IndexingFlags, pub event_processor_config: EventProcessorConfig, + pub world_block: u64, } impl Default for EngineConfig { @@ -159,6 +160,7 @@ impl Default for EngineConfig { max_concurrent_tasks: 100, flags: IndexingFlags::empty(), event_processor_config: EventProcessorConfig::default(), + world_block: 0, } } } @@ -323,7 +325,7 @@ impl Engine

{ pub async fn fetch_data(&mut self, cursors: &Cursors) -> Result { let latest_block = self.provider.block_hash_and_number().await?; - let from = cursors.head.unwrap_or(948000); + let from = cursors.head.unwrap_or(self.config.world_block); let total_remaining_blocks = latest_block.block_number - from; let blocks_to_process = total_remaining_blocks.min(self.config.blocks_chunk_size); let to = from + blocks_to_process; diff --git a/crates/torii/grpc/src/server/mod.rs b/crates/torii/grpc/src/server/mod.rs index dde279a378..113832b1e8 100644 --- a/crates/torii/grpc/src/server/mod.rs +++ b/crates/torii/grpc/src/server/mod.rs @@ -332,7 +332,7 @@ impl DojoWorld { None, )?; - let rows = sqlx::query(&entity_query).bind(&models_str).fetch_all(&mut *tx).await?; + let rows = sqlx::query(&entity_query).bind(models_str).fetch_all(&mut *tx).await?; let schemas = Arc::new(schemas); let group_entities: Result, Error> = rows diff --git a/eternum.toml b/eternum.toml index 1890615158..3d44a4c9d6 100644 --- a/eternum.toml +++ b/eternum.toml @@ -3,6 +3,7 @@ rpc = "https://api.cartridge.gg/x/starknet/mainnet" explorer = false [indexing] +world_block = 948000 events_chunk_size = 1024 blocks_chunk_size = 1024000 pending = true @@ -10,4 +11,4 @@ polling_interval = 500 max_concurrent_tasks = 100 transactions = false contracts = ["ERC721:0x57675b9c0bd62b096a2e15502a37b290fa766ead21c33eda42993e48a714b80", "ERC721:0x7ae27a31bb6526e3de9cf02f081f6ce0615ac12a6d7b85ee58b8ad7947a2809", "ERC20:0x124aeb495b947201f5fac96fd1138e326ad86195b98df6dec9009158a533b49"] -namespaces = [] \ No newline at end of file +namespaces = []