Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Fork choice modifications and cleanup #3962

Closed
wants to merge 63 commits into from
Closed
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
7d067a7
Add new finalized checkpoint function
paulhauner Jan 27, 2023
c82ef87
Add test
paulhauner Jan 27, 2023
791cf47
Tidy
paulhauner Jan 27, 2023
bff9028
Use new method
paulhauner Jan 27, 2023
a119edc
Add descriptive comment
paulhauner Jan 27, 2023
6590da5
Fix clippy lints
paulhauner Jan 27, 2023
c977fab
Rename function
paulhauner Jan 27, 2023
b306f67
Rename function, add test condition
paulhauner Feb 9, 2023
9572135
Add shortcut method
paulhauner Feb 9, 2023
e2312d2
Improve loop-shortcutting method
paulhauner Feb 9, 2023
89d7fd3
Update comments
paulhauner Feb 9, 2023
dfc223c
Update fork_choice function name
paulhauner Feb 9, 2023
788ecd6
Fix todo
paulhauner Feb 9, 2023
0261cda
Fix comment
paulhauner Feb 9, 2023
f35d44b
Add some custom fc tests
paulhauner Feb 1, 2023
db112c5
Add re-org test
paulhauner Feb 1, 2023
656f958
Remove should_update_justified_checkpoint
paulhauner Feb 2, 2023
0652e9b
Sketch in new filter logic
paulhauner Feb 2, 2023
011d6a8
Fix clippy lints from unused safe-slots functions
paulhauner Feb 7, 2023
b02753f
Add more filter logic
paulhauner Feb 7, 2023
0ee0328
Update tests commit
paulhauner Feb 7, 2023
9554274
Add withholding tests
paulhauner Feb 7, 2023
6af13e0
Enable CountUnrealized
paulhauner Feb 7, 2023
8ad941d
Track slashed indices
paulhauner Feb 7, 2023
7065c49
Tidy
paulhauner Feb 8, 2023
e6d95da
Remove best justified checkpoint
paulhauner Feb 8, 2023
fc1e17f
Tidy
paulhauner Feb 8, 2023
e7b26f1
Fix test compile errors
paulhauner Feb 8, 2023
13fbfed
Fix after rebase
paulhauner Feb 9, 2023
529085c
Remove .DSStore from git ignore
paulhauner Feb 9, 2023
1b4cde8
Refactor filter logic for tidiness
paulhauner Feb 9, 2023
0b56a73
Tidy
paulhauner Feb 9, 2023
b175574
Hide custom FC tests behind flag, disable standard tests
paulhauner Feb 9, 2023
0bd58ed
Fix failing test
paulhauner Feb 10, 2023
2349e80
Remove references to best justified checkpoint in FC tests
paulhauner Feb 10, 2023
6fbf9e4
Remove best just checkpoint from EF tests
paulhauner Feb 10, 2023
0183f6e
Merge branch 'unstable' into fc-pr-18
paulhauner Feb 10, 2023
1b761d6
Remove count-unrealized-full
paulhauner Feb 10, 2023
a3e0f3e
Fix test compile error
paulhauner Feb 13, 2023
6972850
Use junk justified checkpoint
paulhauner Feb 13, 2023
e9835aa
Skip fork choice tests
paulhauner Feb 13, 2023
dcb8427
Fix compile error
paulhauner Feb 13, 2023
dfe73a2
Remove commented out cfg flag
paulhauner Feb 13, 2023
2796606
Add comment about running tests
paulhauner Feb 13, 2023
162e97c
Bump test version:
paulhauner Feb 15, 2023
d664cd8
Merge branch 'unstable' into fc-pr-18
paulhauner Mar 1, 2023
ff76ffa
Switch to unified test format
paulhauner Mar 1, 2023
d4a2b02
Remove some non-supplied tests
paulhauner Mar 2, 2023
7bbe895
Merge branch 'unstable' into fc-pr-18
paulhauner Mar 20, 2023
558fe79
Set tests to v1.3.0-rc.4
paulhauner Mar 20, 2023
023524b
Skip specific phase0 FC tests
paulhauner Mar 20, 2023
913abc0
Skip all FC tests with base/phase0
paulhauner Mar 20, 2023
42a8f4f
Remove `slashed_indices` field from `JustifiedBalances`
paulhauner Mar 20, 2023
2dd0f6c
Fix bug with `JustifiedBalances` slashed indices
paulhauner Mar 20, 2023
3f60f70
Un-ignore skipped test files
paulhauner Mar 20, 2023
43a8405
Deprecate `count-unrealized` flag
paulhauner Mar 20, 2023
dd6109c
Update equivocating indices in `process_state`
paulhauner Mar 20, 2023
5377ac6
Censor slashed validators from JustifiedBalances
paulhauner Mar 20, 2023
d47a3e4
Fix test compilation issue
paulhauner Mar 20, 2023
77a4970
Add migration to drop balances cache
paulhauner Mar 20, 2023
9216bda
Fix failing CLI test
paulhauner Mar 21, 2023
7cc1ab1
Appease clippy
paulhauner Mar 21, 2023
d2fefc4
Tidy diff
paulhauner Mar 21, 2023
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
6 changes: 1 addition & 5 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,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 @@ -477,7 +477,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 @@ -494,7 +493,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 @@ -1870,7 +1868,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
self.slot()?,
verified.indexed_attestation(),
AttestationFromBlock::False,
&self.spec,
)
.map_err(Into::into)
}
Expand Down Expand Up @@ -2957,7 +2954,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
28 changes: 15 additions & 13 deletions beacon_node/beacon_chain/src/beacon_fork_choice_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use proto_array::JustifiedBalances;
use safe_arith::ArithError;
use ssz_derive::{Decode, Encode};
use std::collections::BTreeSet;
use std::iter::FromIterator;
use std::marker::PhantomData;
use std::sync::Arc;
use store::{Error as StoreError, HotColdDB, ItemStore};
Expand All @@ -20,6 +21,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 +153,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 @@ -186,6 +194,8 @@ where
};
let finalized_checkpoint = justified_checkpoint;
let justified_balances = JustifiedBalances::from_justified_state(anchor_state)?;
let equivocating_indices =
BTreeSet::from_iter(justified_balances.slashed_indices.iter().copied());

Ok(Self {
store,
Expand All @@ -194,11 +204,10 @@ 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(),
equivocating_indices: BTreeSet::new(),
equivocating_indices,
_phantom: PhantomData,
})
}
Expand All @@ -212,7 +221,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 +243,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 +285,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 @@ -328,15 +332,13 @@ where
.ok_or_else(|| Error::MissingState(justified_block.state_root()))?;

self.justified_balances = JustifiedBalances::from_justified_state(&state)?;
self.equivocating_indices
.extend(self.justified_balances.slashed_indices.iter().copied());
}

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
4 changes: 0 additions & 4 deletions beacon_node/beacon_chain/src/builder.rs
Original file line number Diff line number Diff line change
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 @@ -682,7 +679,6 @@ where
Some(current_slot),
&self.spec,
self.chain_config.count_unrealized.into(),
self.chain_config.count_unrealized_full,
)?;
}

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
5 changes: 1 addition & 4 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 @@ -56,8 +56,6 @@ pub struct ChainConfig {
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 @@ -92,7 +90,6 @@ impl Default for ChainConfig {
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 @@ -56,7 +56,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
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
2 changes: 1 addition & 1 deletion beacon_node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
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
10 changes: 8 additions & 2 deletions beacon_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,14 @@ pub fn get_config<E: EthSpec>(

client_config.chain.count_unrealized =
clap_utils::parse_required(cli_args, "count-unrealized")?;
client_config.chain.count_unrealized_full =
clap_utils::parse_required::<bool>(cli_args, "count-unrealized-full")?.into();

if clap_utils::parse_required::<bool>(cli_args, "count-unrealized-full")? {
warn!(
log,
"The flag --count-unrealized-full is deprecated and will be removed";
"info" => "setting it to `true` has no effect"
);
}

client_config.chain.always_reset_payload_statuses =
cli_args.is_present("reset-payload-statuses");
Expand Down
Loading