Skip to content
Closed
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
31 changes: 12 additions & 19 deletions beacon_node/network/src/sync/backfill_sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1098,12 +1098,7 @@ impl<T: BeaconChainTypes> BackFillSync<T> {
match self.batches.entry(batch_id) {
Entry::Occupied(_) => {
// this batch doesn't need downloading, let this same function decide the next batch
if batch_id
== self
.beacon_chain
.genesis_backfill_slot
.epoch(T::EthSpec::slots_per_epoch())
{
if self.would_complete(batch_id) {
self.last_batch_downloaded = true;
}

Expand All @@ -1114,12 +1109,7 @@ impl<T: BeaconChainTypes> BackFillSync<T> {
}
Entry::Vacant(entry) => {
entry.insert(BatchInfo::new(&batch_id, BACKFILL_EPOCHS_PER_BATCH));
if batch_id
== self
.beacon_chain
.genesis_backfill_slot
.epoch(T::EthSpec::slots_per_epoch())
{
if self.would_complete(batch_id) {
self.last_batch_downloaded = true;
}
self.to_be_downloaded = self
Expand Down Expand Up @@ -1151,14 +1141,8 @@ impl<T: BeaconChainTypes> BackFillSync<T> {

/// Checks with the beacon chain if backfill sync has completed.
fn check_completed(&mut self) -> bool {
if self.current_start
== self
.beacon_chain
.genesis_backfill_slot
.epoch(T::EthSpec::slots_per_epoch())
{
if self.would_complete(self.current_start) {
// Check that the beacon chain agrees

if let Some(anchor_info) = self.beacon_chain.store.get_anchor_info() {
// Conditions that we have completed a backfill sync
if anchor_info.block_backfill_complete(self.beacon_chain.genesis_backfill_slot) {
Expand All @@ -1171,6 +1155,15 @@ impl<T: BeaconChainTypes> BackFillSync<T> {
false
}

/// Checks if backfill would complete by syncing to `start_epoch`.
fn would_complete(&self, start_epoch: Epoch) -> bool {
start_epoch
<= self
.beacon_chain
.genesis_backfill_slot
.epoch(T::EthSpec::slots_per_epoch())
}

/// Updates the global network state indicating the current state of a backfill sync.
fn set_state(&self, state: BackFillState) {
*self.network_globals.backfill_state.write() = state;
Expand Down