Skip to content

Commit

Permalink
Fork choice modifications and cleanup (#3962)
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit d2fefc4
Author: Paul Hauner <[email protected]>
Date:   Tue Mar 21 13:53:38 2023 +1100

    Tidy diff

commit 7cc1ab1
Author: Paul Hauner <[email protected]>
Date:   Tue Mar 21 12:55:44 2023 +1100

    Appease clippy

commit 9216bda
Author: Paul Hauner <[email protected]>
Date:   Tue Mar 21 12:22:28 2023 +1100

    Fix failing CLI test

commit 77a4970
Author: Paul Hauner <[email protected]>
Date:   Tue Mar 21 10:24:33 2023 +1100

    Add migration to drop balances cache

commit d47a3e4
Author: Paul Hauner <[email protected]>
Date:   Mon Mar 20 20:29:13 2023 +1100

    Fix test compilation issue

commit 5377ac6
Author: Paul Hauner <[email protected]>
Date:   Mon Mar 20 20:07:34 2023 +1100

    Censor slashed validators from JustifiedBalances

commit dd6109c
Author: Paul Hauner <[email protected]>
Date:   Mon Mar 20 19:00:28 2023 +1100

    Update equivocating indices in `process_state`

commit 43a8405
Author: Paul Hauner <[email protected]>
Date:   Mon Mar 20 18:19:31 2023 +1100

    Deprecate `count-unrealized` flag

commit 3f60f70
Author: Paul Hauner <[email protected]>
Date:   Mon Mar 20 17:40:33 2023 +1100

    Un-ignore skipped test files

commit 2dd0f6c
Author: Paul Hauner <[email protected]>
Date:   Mon Mar 20 17:40:11 2023 +1100

    Fix bug with `JustifiedBalances` slashed indices

commit 42a8f4f
Author: Paul Hauner <[email protected]>
Date:   Mon Mar 20 17:25:58 2023 +1100

    Remove `slashed_indices` field from `JustifiedBalances`

commit 913abc0
Author: Paul Hauner <[email protected]>
Date:   Mon Mar 20 15:23:36 2023 +1100

    Skip all FC tests with base/phase0

commit 023524b
Author: Paul Hauner <[email protected]>
Date:   Mon Mar 20 15:22:47 2023 +1100

    Skip specific phase0 FC tests

commit 558fe79
Author: Paul Hauner <[email protected]>
Date:   Mon Mar 20 15:14:09 2023 +1100

    Set tests to v1.3.0-rc.4

commit 7bbe895
Merge: d4a2b02 36e163c
Author: Paul Hauner <[email protected]>
Date:   Mon Mar 20 15:09:05 2023 +1100

    Merge branch 'unstable' into fc-pr-18

commit d4a2b02
Author: Paul Hauner <[email protected]>
Date:   Thu Mar 2 11:30:05 2023 +1100

    Remove some non-supplied tests

commit ff76ffa
Author: Paul Hauner <[email protected]>
Date:   Wed Mar 1 15:27:02 2023 +1100

    Switch to unified test format

commit d664cd8
Merge: 162e97c 17d9a62
Author: Paul Hauner <[email protected]>
Date:   Wed Mar 1 14:40:47 2023 +1100

    Merge branch 'unstable' into fc-pr-18

commit 162e97c
Author: Paul Hauner <[email protected]>
Date:   Thu Feb 16 10:15:47 2023 +1100

    Bump test version:

commit 2796606
Author: Paul Hauner <[email protected]>
Date:   Mon Feb 13 17:10:00 2023 +1100

    Add comment about running tests

commit dfe73a2
Author: Paul Hauner <[email protected]>
Date:   Mon Feb 13 17:09:01 2023 +1100

    Remove commented out cfg flag

commit dcb8427
Author: Paul Hauner <[email protected]>
Date:   Mon Feb 13 16:54:14 2023 +1100

    Fix compile error

commit e9835aa
Author: Paul Hauner <[email protected]>
Date:   Mon Feb 13 16:52:52 2023 +1100

    Skip fork choice tests

commit 6972850
Author: Paul Hauner <[email protected]>
Date:   Mon Feb 13 16:50:02 2023 +1100

    Use junk justified checkpoint

commit a3e0f3e
Author: Paul Hauner <[email protected]>
Date:   Mon Feb 13 14:12:02 2023 +1100

    Fix test compile error

commit 1b761d6
Author: Paul Hauner <[email protected]>
Date:   Fri Feb 10 14:58:28 2023 +1100

    Remove count-unrealized-full

commit 0183f6e
Merge: 6fbf9e4 5276dd0
Author: Paul Hauner <[email protected]>
Date:   Fri Feb 10 14:42:44 2023 +1100

    Merge branch 'unstable' into fc-pr-18

commit 6fbf9e4
Author: Paul Hauner <[email protected]>
Date:   Fri Feb 10 14:40:58 2023 +1100

    Remove best just checkpoint from EF tests

commit 2349e80
Author: Paul Hauner <[email protected]>
Date:   Fri Feb 10 14:37:02 2023 +1100

    Remove references to best justified checkpoint in FC tests

commit 0bd58ed
Author: Paul Hauner <[email protected]>
Date:   Fri Feb 10 14:33:46 2023 +1100

    Fix failing test

commit b175574
Author: Paul Hauner <[email protected]>
Date:   Fri Feb 10 10:28:26 2023 +1100

    Hide custom FC tests behind flag, disable standard tests

commit 0b56a73
Author: Paul Hauner <[email protected]>
Date:   Fri Feb 10 09:31:04 2023 +1100

    Tidy

commit 1b4cde8
Author: Paul Hauner <[email protected]>
Date:   Thu Feb 9 18:17:33 2023 +1100

    Refactor filter logic for tidiness

commit 529085c
Author: Paul Hauner <[email protected]>
Date:   Thu Feb 9 15:37:00 2023 +1100

    Remove .DSStore from git ignore

commit 13fbfed
Author: Paul Hauner <[email protected]>
Date:   Thu Feb 9 15:36:02 2023 +1100

    Fix after rebase

commit e7b26f1
Author: Paul Hauner <[email protected]>
Date:   Wed Feb 8 17:49:00 2023 +1100

    Fix test compile errors

commit fc1e17f
Author: Paul Hauner <[email protected]>
Date:   Wed Feb 8 15:27:49 2023 +1100

    Tidy

commit e6d95da
Author: Paul Hauner <[email protected]>
Date:   Wed Feb 8 11:38:27 2023 +1100

    Remove best justified checkpoint

commit 7065c49
Author: Paul Hauner <[email protected]>
Date:   Wed Feb 8 11:21:58 2023 +1100

    Tidy

commit 8ad941d
Author: Paul Hauner <[email protected]>
Date:   Tue Feb 7 18:37:12 2023 +1100

    Track slashed indices

commit 6af13e0
Author: Paul Hauner <[email protected]>
Date:   Tue Feb 7 18:04:48 2023 +1100

    Enable CountUnrealized

commit 9554274
Author: Paul Hauner <[email protected]>
Date:   Tue Feb 7 17:25:12 2023 +1100

    Add withholding tests

commit 0ee0328
Author: Paul Hauner <[email protected]>
Date:   Tue Feb 7 17:25:05 2023 +1100

    Update tests commit

commit b02753f
Author: Paul Hauner <[email protected]>
Date:   Tue Feb 7 17:15:33 2023 +1100

    Add more filter logic

commit 011d6a8
Author: Paul Hauner <[email protected]>
Date:   Tue Feb 7 16:52:33 2023 +1100

    Fix clippy lints from unused safe-slots functions

commit 0652e9b
Author: Paul Hauner <[email protected]>
Date:   Thu Feb 2 15:08:17 2023 +1100

    Sketch in new filter logic

commit 656f958
Author: Paul Hauner <[email protected]>
Date:   Thu Feb 2 14:31:32 2023 +1100

    Remove should_update_justified_checkpoint

commit db112c5
Author: Paul Hauner <[email protected]>
Date:   Wed Feb 1 15:48:19 2023 +1100

    Add re-org test

commit f35d44b
Author: Paul Hauner <[email protected]>
Date:   Wed Feb 1 15:45:00 2023 +1100

    Add some custom fc tests

commit 0261cda
Author: Paul Hauner <[email protected]>
Date:   Thu Feb 9 15:28:02 2023 +1100

    Fix comment

commit 788ecd6
Author: Paul Hauner <[email protected]>
Date:   Thu Feb 9 12:36:50 2023 +1100

    Fix todo

commit dfc223c
Author: Paul Hauner <[email protected]>
Date:   Thu Feb 9 12:30:17 2023 +1100

    Update fork_choice function name

commit 89d7fd3
Author: Paul Hauner <[email protected]>
Date:   Thu Feb 9 12:28:21 2023 +1100

    Update comments

commit e2312d2
Author: Paul Hauner <[email protected]>
Date:   Thu Feb 9 12:23:26 2023 +1100

    Improve loop-shortcutting method

commit 9572135
Author: Paul Hauner <[email protected]>
Date:   Thu Feb 9 12:07:07 2023 +1100

    Add shortcut method

commit b306f67
Author: Paul Hauner <[email protected]>
Date:   Thu Feb 9 12:06:58 2023 +1100

    Rename function, add test condition

commit c977fab
Author: Paul Hauner <[email protected]>
Date:   Fri Jan 27 17:57:36 2023 +0100

    Rename function

commit 6590da5
Author: Paul Hauner <[email protected]>
Date:   Fri Jan 27 17:54:25 2023 +0100

    Fix clippy lints

commit a119edc
Author: Paul Hauner <[email protected]>
Date:   Fri Jan 27 17:35:30 2023 +0100

    Add descriptive comment

commit bff9028
Author: Paul Hauner <[email protected]>
Date:   Fri Jan 27 16:20:23 2023 +0100

    Use new method

commit 791cf47
Author: Paul Hauner <[email protected]>
Date:   Fri Jan 27 16:07:37 2023 +0100

    Tidy

commit c82ef87
Author: Paul Hauner <[email protected]>
Date:   Fri Jan 27 16:05:11 2023 +0100

    Add test

commit 7d067a7
Author: Paul Hauner <[email protected]>
Date:   Fri Jan 27 14:54:08 2023 +0100

    Add new finalized checkpoint function
  • Loading branch information
paulhauner committed Mar 21, 2023
1 parent ba3cf36 commit c7120b0
Show file tree
Hide file tree
Showing 29 changed files with 216 additions and 413 deletions.
8 changes: 2 additions & 6 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ use itertools::process_results;
use itertools::Itertools;
use operation_pool::{AttestationRef, OperationPool, PersistedOperationPool, ReceivedPreCapella};
use parking_lot::{Mutex, RwLock};
use proto_array::{CountUnrealizedFull, DoNotReOrg, ProposerHeadError};
use proto_array::{DoNotReOrg, ProposerHeadError};
use safe_arith::SafeArith;
use slasher::Slasher;
use slog::{crit, debug, error, info, trace, warn, Logger};
Expand Down Expand Up @@ -479,7 +479,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
pub fn load_fork_choice(
store: BeaconStore<T>,
reset_payload_statuses: ResetPayloadStatuses,
count_unrealized_full: CountUnrealizedFull,
spec: &ChainSpec,
log: &Logger,
) -> Result<Option<BeaconForkChoice<T>>, Error> {
Expand All @@ -496,7 +495,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
persisted_fork_choice.fork_choice,
reset_payload_statuses,
fc_store,
count_unrealized_full,
spec,
log,
)?))
Expand Down Expand Up @@ -1900,7 +1898,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
self.slot()?,
verified.indexed_attestation(),
AttestationFromBlock::False,
&self.spec,
)
.map_err(Into::into)
}
Expand Down Expand Up @@ -2868,7 +2865,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
&state,
payload_verification_status,
&self.spec,
count_unrealized.and(self.config.count_unrealized.into()),
count_unrealized,
)
.map_err(|e| BlockError::BeaconChainError(e.into()))?;
}
Expand Down Expand Up @@ -2987,7 +2984,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
ResetPayloadStatuses::always_reset_conditionally(
self.config.always_reset_payload_statuses,
),
self.config.count_unrealized_full,
&self.store,
&self.spec,
&self.log,
Expand Down
21 changes: 9 additions & 12 deletions beacon_node/beacon_chain/src/beacon_fork_choice_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ use types::{
Hash256, Slot,
};

/// Ensure this justified checkpoint has an epoch of 0 so that it is never
/// greater than the justified checkpoint and enshrined as the actual justified
/// checkpoint.
const JUNK_BEST_JUSTIFIED_CHECKPOINT: Checkpoint = Checkpoint {
epoch: Epoch::new(0),
root: Hash256::repeat_byte(0),
};

#[derive(Debug)]
pub enum Error {
UnableToReadSlot,
Expand Down Expand Up @@ -144,7 +152,6 @@ pub struct BeaconForkChoiceStore<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<
finalized_checkpoint: Checkpoint,
justified_checkpoint: Checkpoint,
justified_balances: JustifiedBalances,
best_justified_checkpoint: Checkpoint,
unrealized_justified_checkpoint: Checkpoint,
unrealized_finalized_checkpoint: Checkpoint,
proposer_boost_root: Hash256,
Expand Down Expand Up @@ -194,7 +201,6 @@ where
justified_checkpoint,
justified_balances,
finalized_checkpoint,
best_justified_checkpoint: justified_checkpoint,
unrealized_justified_checkpoint: justified_checkpoint,
unrealized_finalized_checkpoint: finalized_checkpoint,
proposer_boost_root: Hash256::zero(),
Expand All @@ -212,7 +218,7 @@ where
finalized_checkpoint: self.finalized_checkpoint,
justified_checkpoint: self.justified_checkpoint,
justified_balances: self.justified_balances.effective_balances.clone(),
best_justified_checkpoint: self.best_justified_checkpoint,
best_justified_checkpoint: JUNK_BEST_JUSTIFIED_CHECKPOINT,
unrealized_justified_checkpoint: self.unrealized_justified_checkpoint,
unrealized_finalized_checkpoint: self.unrealized_finalized_checkpoint,
proposer_boost_root: self.proposer_boost_root,
Expand All @@ -234,7 +240,6 @@ where
finalized_checkpoint: persisted.finalized_checkpoint,
justified_checkpoint: persisted.justified_checkpoint,
justified_balances,
best_justified_checkpoint: persisted.best_justified_checkpoint,
unrealized_justified_checkpoint: persisted.unrealized_justified_checkpoint,
unrealized_finalized_checkpoint: persisted.unrealized_finalized_checkpoint,
proposer_boost_root: persisted.proposer_boost_root,
Expand Down Expand Up @@ -277,10 +282,6 @@ where
&self.justified_balances
}

fn best_justified_checkpoint(&self) -> &Checkpoint {
&self.best_justified_checkpoint
}

fn finalized_checkpoint(&self) -> &Checkpoint {
&self.finalized_checkpoint
}
Expand Down Expand Up @@ -333,10 +334,6 @@ where
Ok(())
}

fn set_best_justified_checkpoint(&mut self, checkpoint: Checkpoint) {
self.best_justified_checkpoint = checkpoint
}

fn set_unrealized_justified_checkpoint(&mut self, checkpoint: Checkpoint) {
self.unrealized_justified_checkpoint = checkpoint;
}
Expand Down
1 change: 0 additions & 1 deletion beacon_node/beacon_chain/src/block_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,6 @@ impl<T: BeaconChainTypes> ExecutionPendingBlock<T> {
current_slot,
indexed_attestation,
AttestationFromBlock::True,
&chain.spec,
) {
Ok(()) => Ok(()),
// Ignore invalid attestations whilst importing attestations from a block. The
Expand Down
8 changes: 2 additions & 6 deletions beacon_node/beacon_chain/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
};
use eth1::Config as Eth1Config;
use execution_layer::ExecutionLayer;
use fork_choice::{ForkChoice, ResetPayloadStatuses};
use fork_choice::{CountUnrealized, ForkChoice, ResetPayloadStatuses};
use futures::channel::mpsc::Sender;
use operation_pool::{OperationPool, PersistedOperationPool};
use parking_lot::RwLock;
Expand Down Expand Up @@ -265,7 +265,6 @@ where
ResetPayloadStatuses::always_reset_conditionally(
self.chain_config.always_reset_payload_statuses,
),
self.chain_config.count_unrealized_full,
&self.spec,
log,
)
Expand Down Expand Up @@ -384,7 +383,6 @@ where
&genesis.beacon_block,
&genesis.beacon_state,
current_slot,
self.chain_config.count_unrealized_full,
&self.spec,
)
.map_err(|e| format!("Unable to initialize ForkChoice: {:?}", e))?;
Expand Down Expand Up @@ -503,7 +501,6 @@ where
&snapshot.beacon_block,
&snapshot.beacon_state,
current_slot,
self.chain_config.count_unrealized_full,
&self.spec,
)
.map_err(|e| format!("Unable to initialize ForkChoice: {:?}", e))?;
Expand Down Expand Up @@ -681,8 +678,7 @@ where
store.clone(),
Some(current_slot),
&self.spec,
self.chain_config.count_unrealized.into(),
self.chain_config.count_unrealized_full,
CountUnrealized::True,
)?;
}

Expand Down
15 changes: 4 additions & 11 deletions beacon_node/beacon_chain/src/canonical_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ use crate::{
};
use eth2::types::{EventKind, SseChainReorg, SseFinalizedCheckpoint, SseHead, SseLateHead};
use fork_choice::{
CountUnrealizedFull, ExecutionStatus, ForkChoiceView, ForkchoiceUpdateParameters, ProtoBlock,
ResetPayloadStatuses,
ExecutionStatus, ForkChoiceView, ForkchoiceUpdateParameters, ProtoBlock, ResetPayloadStatuses,
};
use itertools::process_results;
use parking_lot::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard};
Expand Down Expand Up @@ -285,19 +284,13 @@ impl<T: BeaconChainTypes> CanonicalHead<T> {
// defensive programming.
mut fork_choice_write_lock: RwLockWriteGuard<BeaconForkChoice<T>>,
reset_payload_statuses: ResetPayloadStatuses,
count_unrealized_full: CountUnrealizedFull,
store: &BeaconStore<T>,
spec: &ChainSpec,
log: &Logger,
) -> Result<(), Error> {
let fork_choice = <BeaconChain<T>>::load_fork_choice(
store.clone(),
reset_payload_statuses,
count_unrealized_full,
spec,
log,
)?
.ok_or(Error::MissingPersistedForkChoice)?;
let fork_choice =
<BeaconChain<T>>::load_fork_choice(store.clone(), reset_payload_statuses, spec, log)?
.ok_or(Error::MissingPersistedForkChoice)?;
let fork_choice_view = fork_choice.cached_fork_choice_view();
let beacon_block_root = fork_choice_view.head_block_root;
let beacon_block = store
Expand Down
9 changes: 1 addition & 8 deletions beacon_node/beacon_chain/src/chain_config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use proto_array::{CountUnrealizedFull, ReOrgThreshold};
pub use proto_array::ReOrgThreshold;
use serde_derive::{Deserialize, Serialize};
use std::time::Duration;
use types::{Checkpoint, Epoch};
Expand Down Expand Up @@ -48,16 +48,11 @@ pub struct ChainConfig {
pub builder_fallback_epochs_since_finalization: usize,
/// Whether any chain health checks should be considered when deciding whether to use the builder API.
pub builder_fallback_disable_checks: bool,
/// When set to `true`, weigh the "unrealized" FFG progression when choosing a head in fork
/// choice.
pub count_unrealized: bool,
/// When set to `true`, forget any valid/invalid/optimistic statuses in fork choice during start
/// up.
pub always_reset_payload_statuses: bool,
/// Whether to apply paranoid checks to blocks proposed by this beacon node.
pub paranoid_block_proposal: bool,
/// Whether to strictly count unrealized justified votes.
pub count_unrealized_full: CountUnrealizedFull,
/// Optionally set timeout for calls to checkpoint sync endpoint.
pub checkpoint_sync_url_timeout: u64,
/// The offset before the start of a proposal slot at which payload attributes should be sent.
Expand Down Expand Up @@ -91,10 +86,8 @@ impl Default for ChainConfig {
builder_fallback_skips_per_epoch: 8,
builder_fallback_epochs_since_finalization: 3,
builder_fallback_disable_checks: false,
count_unrealized: true,
always_reset_payload_statuses: false,
paranoid_block_proposal: false,
count_unrealized_full: CountUnrealizedFull::default(),
checkpoint_sync_url_timeout: 60,
prepare_payload_lookahead: Duration::from_secs(4),
// This value isn't actually read except in tests.
Expand Down
3 changes: 0 additions & 3 deletions beacon_node/beacon_chain/src/fork_revert.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{BeaconForkChoiceStore, BeaconSnapshot};
use fork_choice::{CountUnrealized, ForkChoice, PayloadVerificationStatus};
use itertools::process_results;
use proto_array::CountUnrealizedFull;
use slog::{info, warn, Logger};
use state_processing::state_advance::complete_state_advance;
use state_processing::{
Expand Down Expand Up @@ -102,7 +101,6 @@ pub fn reset_fork_choice_to_finalization<E: EthSpec, Hot: ItemStore<E>, Cold: It
current_slot: Option<Slot>,
spec: &ChainSpec,
count_unrealized_config: CountUnrealized,
count_unrealized_full_config: CountUnrealizedFull,
) -> Result<ForkChoice<BeaconForkChoiceStore<E, Hot, Cold>, E>, String> {
// Fetch finalized block.
let finalized_checkpoint = head_state.finalized_checkpoint();
Expand Down Expand Up @@ -156,7 +154,6 @@ pub fn reset_fork_choice_to_finalization<E: EthSpec, Hot: ItemStore<E>, Cold: It
&finalized_snapshot.beacon_block,
&finalized_snapshot.beacon_state,
current_slot,
count_unrealized_full_config,
spec,
)
.map_err(|e| format!("Unable to reset fork choice for revert: {:?}", e))?;
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub use self::beacon_chain::{
INVALID_JUSTIFIED_PAYLOAD_SHUTDOWN_REASON, MAXIMUM_GOSSIP_CLOCK_DISPARITY,
};
pub use self::beacon_snapshot::BeaconSnapshot;
pub use self::chain_config::{ChainConfig, CountUnrealizedFull};
pub use self::chain_config::ChainConfig;
pub use self::errors::{BeaconChainError, BlockProductionError};
pub use self::historical_blocks::HistoricalBlockError;
pub use attestation_verification::Error as AttestationError;
Expand Down
9 changes: 9 additions & 0 deletions beacon_node/beacon_chain/src/schema_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod migration_schema_v12;
mod migration_schema_v13;
mod migration_schema_v14;
mod migration_schema_v15;
mod migration_schema_v16;

use crate::beacon_chain::{BeaconChainTypes, ETH1_CACHE_DB_KEY};
use crate::eth1_chain::SszEth1;
Expand Down Expand Up @@ -132,6 +133,14 @@ pub fn migrate_schema<T: BeaconChainTypes>(
let ops = migration_schema_v15::downgrade_from_v15::<T>(db.clone(), log)?;
db.store_schema_version_atomically(to, ops)
}
(SchemaVersion(15), SchemaVersion(16)) => {
let ops = migration_schema_v16::upgrade_to_v16::<T>(db.clone(), log)?;
db.store_schema_version_atomically(to, ops)
}
(SchemaVersion(16), SchemaVersion(15)) => {
let ops = migration_schema_v16::downgrade_from_v16::<T>(db.clone(), log)?;
db.store_schema_version_atomically(to, ops)
}
// Anything else is an error.
(_, _) => Err(HotColdDBError::UnsupportedSchemaVersion {
target_version: to,
Expand Down
46 changes: 46 additions & 0 deletions beacon_node/beacon_chain/src/schema_change/migration_schema_v16.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use crate::beacon_chain::{BeaconChainTypes, FORK_CHOICE_DB_KEY};
use crate::persisted_fork_choice::PersistedForkChoiceV11;
use slog::{debug, Logger};
use std::sync::Arc;
use store::{Error, HotColdDB, KeyValueStoreOp, StoreItem};

pub fn upgrade_to_v16<T: BeaconChainTypes>(
db: Arc<HotColdDB<T::EthSpec, T::HotStore, T::ColdStore>>,
log: Logger,
) -> Result<Vec<KeyValueStoreOp>, Error> {
drop_balances_cache::<T>(db, log)
}

pub fn downgrade_from_v16<T: BeaconChainTypes>(
db: Arc<HotColdDB<T::EthSpec, T::HotStore, T::ColdStore>>,
log: Logger,
) -> Result<Vec<KeyValueStoreOp>, Error> {
drop_balances_cache::<T>(db, log)
}

/// Drop the balances cache from the fork choice store.
///
/// There aren't any type-level changes in this schema migration, however the
/// way that we compute the `JustifiedBalances` has changed due to:
/// https://github.com/sigp/lighthouse/pull/3962
pub fn drop_balances_cache<T: BeaconChainTypes>(
db: Arc<HotColdDB<T::EthSpec, T::HotStore, T::ColdStore>>,
log: Logger,
) -> Result<Vec<KeyValueStoreOp>, Error> {
let mut persisted_fork_choice = db
.get_item::<PersistedForkChoiceV11>(&FORK_CHOICE_DB_KEY)?
.ok_or_else(|| Error::SchemaMigrationError("fork choice missing from database".into()))?;

debug!(
log,
"Dropping fork choice balances cache";
"item_count" => persisted_fork_choice.fork_choice_store.balances_cache.items.len()
);

// Drop all items in the balances cache.
persisted_fork_choice.fork_choice_store.balances_cache = <_>::default();

let kv_op = persisted_fork_choice.as_kv_store_op(FORK_CHOICE_DB_KEY);

Ok(vec![kv_op])
}
4 changes: 2 additions & 2 deletions beacon_node/beacon_chain/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ async fn unaggregated_attestations_added_to_fork_choice_some_none() {
// Move forward a slot so all queued attestations can be processed.
harness.advance_slot();
fork_choice
.update_time(harness.chain.slot().unwrap(), &harness.chain.spec)
.update_time(harness.chain.slot().unwrap())
.unwrap();

let validator_slots: Vec<(usize, Slot)> = (0..VALIDATOR_COUNT)
Expand Down Expand Up @@ -614,7 +614,7 @@ async fn unaggregated_attestations_added_to_fork_choice_all_updated() {
// Move forward a slot so all queued attestations can be processed.
harness.advance_slot();
fork_choice
.update_time(harness.chain.slot().unwrap(), &harness.chain.spec)
.update_time(harness.chain.slot().unwrap())
.unwrap();

let validators: Vec<usize> = (0..VALIDATOR_COUNT).collect();
Expand Down
5 changes: 2 additions & 3 deletions beacon_node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,16 +966,15 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
Arg::with_name("count-unrealized")
.long("count-unrealized")
.hidden(true)
.help("Enables an alternative, potentially more performant FFG \
vote tracking method.")
.help("This flag is deprecated and has no effect.")
.takes_value(true)
.default_value("true")
)
.arg(
Arg::with_name("count-unrealized-full")
.long("count-unrealized-full")
.hidden(true)
.help("Stricter version of `count-unrealized`.")
.help("This flag is deprecated and has no effect.")
.takes_value(true)
.default_value("false")
)
Expand Down
Loading

0 comments on commit c7120b0

Please sign in to comment.