Skip to content

Commit

Permalink
fix: skipping
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Apr 9, 2024
1 parent bfdbfc1 commit dd77e94
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions crates/torii/core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,16 @@ impl<P: Provider + Sync> Engine<P> {

// Skip transactions that have been processed already
// Our cursor is the last processed transaction
let transactions = block
.transactions
.iter()
.skip_while(|tx| {
if let Some(pending_block_tx) = pending_block_tx {
*tx.transaction_hash() != pending_block_tx
} else {
false
for transaction in block.transactions {
if let Some(tx) = pending_block_tx {
if transaction.transaction_hash() != &tx {
continue;
}
})
.skip(1)
.collect::<Vec<_>>();

for transaction in transactions {
pending_block_tx = None;
continue;
}

self.process_transaction_and_receipt(
*transaction.transaction_hash(),
&transaction,
Expand All @@ -189,7 +185,7 @@ impl<P: Provider + Sync> Engine<P> {
&mut self,
from: u64,
to: u64,
pending_block_tx: Option<FieldElement>,
mut pending_block_tx: Option<FieldElement>,
) -> Result<Option<FieldElement>> {
// Process all blocks from current to latest.
let get_events = |token: Option<String>| {
Expand Down Expand Up @@ -233,13 +229,15 @@ impl<P: Provider + Sync> Engine<P> {
last_block = block_number;
}

if let Some(pending_block_tx) = pending_block_tx {
// Then we skip all transactions until we reach the last pending processed
// transaction (if any)
if event.transaction_hash != pending_block_tx {
// Then we skip all transactions until we reach the last pending processed
// transaction (if any)
if let Some(tx) = pending_block_tx {
if event.transaction_hash != tx {
continue;
}

// Then we skip that processed transaction
pending_block_tx = None;
continue;
}

Expand Down Expand Up @@ -276,11 +274,11 @@ impl<P: Provider + Sync> Engine<P> {
.await?;
}

self.db.set_head(to, None);
self.db.set_head(to, pending_block_tx);

self.db.execute().await?;

Ok(None)
Ok(pending_block_tx)
}

async fn get_block_timestamp(&self, block_number: u64) -> Result<u64> {
Expand Down

0 comments on commit dd77e94

Please sign in to comment.