Correct checks for backfill completeness (#4465)
## Issue Addressed #4331 ## Proposed Changes - Use comparison rather than strict equality between the earliest epoch we know about and the backfill target (which will be the most recent WSP by default or genesis) - Add helper function `BackFillSync<T>::would_complete` to achieve this in one location ## Additional Info - There's an ad hoc test for this in #4461 Co-authored-by: Age Manning <Age@AgeManning.com>
This commit is contained in:
parent
dfcb3363c7
commit
a6d5c7d7e0
@ -1098,12 +1098,7 @@ impl<T: BeaconChainTypes> BackFillSync<T> {
|
|||||||
match self.batches.entry(batch_id) {
|
match self.batches.entry(batch_id) {
|
||||||
Entry::Occupied(_) => {
|
Entry::Occupied(_) => {
|
||||||
// this batch doesn't need downloading, let this same function decide the next batch
|
// this batch doesn't need downloading, let this same function decide the next batch
|
||||||
if batch_id
|
if self.would_complete(batch_id) {
|
||||||
== self
|
|
||||||
.beacon_chain
|
|
||||||
.genesis_backfill_slot
|
|
||||||
.epoch(T::EthSpec::slots_per_epoch())
|
|
||||||
{
|
|
||||||
self.last_batch_downloaded = true;
|
self.last_batch_downloaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1114,12 +1109,7 @@ impl<T: BeaconChainTypes> BackFillSync<T> {
|
|||||||
}
|
}
|
||||||
Entry::Vacant(entry) => {
|
Entry::Vacant(entry) => {
|
||||||
entry.insert(BatchInfo::new(&batch_id, BACKFILL_EPOCHS_PER_BATCH));
|
entry.insert(BatchInfo::new(&batch_id, BACKFILL_EPOCHS_PER_BATCH));
|
||||||
if batch_id
|
if self.would_complete(batch_id) {
|
||||||
== self
|
|
||||||
.beacon_chain
|
|
||||||
.genesis_backfill_slot
|
|
||||||
.epoch(T::EthSpec::slots_per_epoch())
|
|
||||||
{
|
|
||||||
self.last_batch_downloaded = true;
|
self.last_batch_downloaded = true;
|
||||||
}
|
}
|
||||||
self.to_be_downloaded = self
|
self.to_be_downloaded = self
|
||||||
@ -1151,14 +1141,8 @@ impl<T: BeaconChainTypes> BackFillSync<T> {
|
|||||||
|
|
||||||
/// Checks with the beacon chain if backfill sync has completed.
|
/// Checks with the beacon chain if backfill sync has completed.
|
||||||
fn check_completed(&mut self) -> bool {
|
fn check_completed(&mut self) -> bool {
|
||||||
if self.current_start
|
if self.would_complete(self.current_start) {
|
||||||
== self
|
|
||||||
.beacon_chain
|
|
||||||
.genesis_backfill_slot
|
|
||||||
.epoch(T::EthSpec::slots_per_epoch())
|
|
||||||
{
|
|
||||||
// Check that the beacon chain agrees
|
// Check that the beacon chain agrees
|
||||||
|
|
||||||
if let Some(anchor_info) = self.beacon_chain.store.get_anchor_info() {
|
if let Some(anchor_info) = self.beacon_chain.store.get_anchor_info() {
|
||||||
// Conditions that we have completed a backfill sync
|
// Conditions that we have completed a backfill sync
|
||||||
if anchor_info.block_backfill_complete(self.beacon_chain.genesis_backfill_slot) {
|
if anchor_info.block_backfill_complete(self.beacon_chain.genesis_backfill_slot) {
|
||||||
@ -1171,6 +1155,15 @@ impl<T: BeaconChainTypes> BackFillSync<T> {
|
|||||||
false
|
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.
|
/// Updates the global network state indicating the current state of a backfill sync.
|
||||||
fn set_state(&self, state: BackFillState) {
|
fn set_state(&self, state: BackFillState) {
|
||||||
*self.network_globals.backfill_state.write() = state;
|
*self.network_globals.backfill_state.write() = state;
|
||||||
|
Loading…
Reference in New Issue
Block a user