Skip to content

Commit

Permalink
fix(indexer): skip historical sync if we have reached or surpassed th…
Browse files Browse the repository at this point in the history
…e Dencun fork
  • Loading branch information
PJColombo committed Mar 10, 2024
1 parent 0d974fc commit 82a95cb
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/indexer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::thread;
use std::{cmp, thread};

use anyhow::{anyhow, Context as AnyhowContext};

Expand Down Expand Up @@ -79,9 +79,9 @@ impl Indexer {
Some(block_id) => block_id,
None => match &sync_state {
Some(state) => match state.last_lower_synced_slot {
Some(slot) => BlockId::Slot(slot - 1),
Some(slot) => BlockId::Slot(self._get_current_lower_slot(slot)),
None => match state.last_upper_synced_slot {
Some(slot) => BlockId::Slot(slot - 1),
Some(slot) => BlockId::Slot(self._get_current_lower_slot(slot)),
None => BlockId::Head,
},
},
Expand Down Expand Up @@ -135,6 +135,17 @@ impl Indexer {
let target_lowest_slot = self.dencun_fork_slot;

tokio::spawn(async move {
if let BlockId::Slot(slot) = start_block_id {
if slot <= target_lowest_slot {
debug!(
target = "indexer:historical_sync",
"Skip sync. Dencun fork slot reached"
);

return Ok(());
}
}

let result = synchronizer
.run(&start_block_id, &BlockId::Slot(target_lowest_slot))
.await;
Expand Down Expand Up @@ -314,4 +325,8 @@ impl Indexer {

synchronizer_builder.build(self.context.clone())
}

fn _get_current_lower_slot(&self, last_synced_slot: u32) -> u32 {
cmp::max(last_synced_slot, self.dencun_fork_slot)
}
}

0 comments on commit 82a95cb

Please sign in to comment.