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

fix(torii): fallback invalid events & flag indexing pending blocks #1897

Merged
merged 4 commits into from
Apr 30, 2024
Merged
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
5 changes: 5 additions & 0 deletions bin/torii/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@
/// Chunk size of the events page when indexing using events
#[arg(long, default_value = "1000")]
events_chunk_size: u64,

/// Enable indexing pending blocks
#[arg(long)]
index_pending: bool,

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

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L115

Added line #L115 was not covered by tests
}

#[tokio::main]
Expand Down Expand Up @@ -179,6 +183,7 @@
EngineConfig {
start_block: args.start_block,
events_chunk_size: args.events_chunk_size,
index_pending: args.index_pending,

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

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L186

Added line #L186 was not covered by tests
..Default::default()
},
shutdown_tx.clone(),
Expand Down
27 changes: 24 additions & 3 deletions crates/torii/core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,17 @@
pub block_time: Duration,
pub start_block: u64,
pub events_chunk_size: u64,
pub index_pending: bool,
}

impl Default for EngineConfig {
fn default() -> Self {
Self { block_time: Duration::from_secs(1), start_block: 0, events_chunk_size: 1000 }
Self {
block_time: Duration::from_secs(1),
start_block: 0,
events_chunk_size: 1000,
index_pending: false,
}
}
}

Expand Down Expand Up @@ -123,7 +129,7 @@
// if `from` == 0, then the block may or may not be processed yet.
let from = if from == 0 { from } else { from + 1 };
pending_block_tx = self.sync_range(from, latest_block_number, pending_block_tx).await?;
} else {
} else if self.config.index_pending {

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L132 was not covered by tests
pending_block_tx = self.sync_pending(latest_block_number + 1, pending_block_tx).await?;
}

Expand Down Expand Up @@ -235,7 +241,22 @@
for event in &events_page.events {
let block_number = match event.block_number {
Some(block_number) => block_number,
None => return Err(anyhow::anyhow!("Event without block number.")),
// If the block number is not present, try to fetch it from the transaction
// receipt Should not/rarely happen. Thus the additional
// fetch is acceptable.
None => {
match self.provider.get_transaction_receipt(event.transaction_hash).await? {

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L248 was not covered by tests
MaybePendingTransactionReceipt::Receipt(
TransactionReceipt::Invoke(receipt),
) => receipt.block_number,

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

View check run for this annotation

Codecov / codecov/patch

crates/torii/core/src/engine.rs#L250-L251

Added lines #L250 - L251 were not covered by tests
MaybePendingTransactionReceipt::Receipt(
TransactionReceipt::L1Handler(receipt),
) => receipt.block_number,

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

View check run for this annotation

Codecov / codecov/patch

crates/torii/core/src/engine.rs#L253-L254

Added lines #L253 - L254 were not covered by tests
// If it's a pending transaction, we assume the block number is the
// latest + 1
_ => to + 1,

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L257 was not covered by tests
}
}
};

// Keep track of last block number and fetch block timestamp
Expand Down
Loading