Skip to content

Commit

Permalink
feat: add the world block to start syncing
Browse files Browse the repository at this point in the history
Currently this commit will break the indexing of tokens
since they need to start from block 0.
  • Loading branch information
glihm committed Dec 11, 2024
1 parent 02778a1 commit 6420e12
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions bin/torii/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Check warning on line 167 in bin/torii/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L167

Added line #L167 was not covered by tests
},
shutdown_tx.clone(),
Some(block_tx),
Expand Down
18 changes: 18 additions & 0 deletions crates/torii/cli/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,19 @@ pub struct IndexingOptions {
)]
#[serde(default)]
pub namespaces: Vec<String>,

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

Check warning on line 172 in crates/torii/cli/src/options.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/cli/src/options.rs#L172

Added line #L172 was not covered by tests
}

impl Default for IndexingOptions {
Expand All @@ -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,

Check warning on line 186 in crates/torii/cli/src/options.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/cli/src/options.rs#L186

Added line #L186 was not covered by tests
}
}
}
Expand Down Expand Up @@ -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;
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/torii/core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -159,6 +160,7 @@ impl Default for EngineConfig {
max_concurrent_tasks: 100,
flags: IndexingFlags::empty(),
event_processor_config: EventProcessorConfig::default(),
world_block: 0,
}
}
}
Expand Down Expand Up @@ -323,7 +325,7 @@ impl<P: Provider + Send + Sync + std::fmt::Debug + 'static> Engine<P> {
pub async fn fetch_data(&mut self, cursors: &Cursors) -> Result<FetchDataResult> {
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);

Check warning on line 328 in crates/torii/core/src/engine.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/core/src/engine.rs#L328

Added line #L328 was not covered by tests
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;
Expand Down
2 changes: 1 addition & 1 deletion crates/torii/grpc/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<_>, Error> = rows
Expand Down
3 changes: 2 additions & 1 deletion eternum.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ rpc = "https://api.cartridge.gg/x/starknet/mainnet"
explorer = false

[indexing]
world_block = 948000
events_chunk_size = 1024
blocks_chunk_size = 1024000
pending = true
polling_interval = 500
max_concurrent_tasks = 100
transactions = false
contracts = ["ERC721:0x57675b9c0bd62b096a2e15502a37b290fa766ead21c33eda42993e48a714b80", "ERC721:0x7ae27a31bb6526e3de9cf02f081f6ce0615ac12a6d7b85ee58b8ad7947a2809", "ERC20:0x124aeb495b947201f5fac96fd1138e326ad86195b98df6dec9009158a533b49"]
namespaces = []
namespaces = []

0 comments on commit 6420e12

Please sign in to comment.