Skip to content
Closed
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
9eb6f5b
Initial implementation of `ProgressiveTotalBalances` cache
jimmygchen Jun 1, 2023
c650a71
Use `ProgressiveTotalBalances` cache to process jutification and fina…
jimmygchen Jun 1, 2023
36ca37a
Add `ProgressiveTotalBalances` cache to `BeaconState` clone config
jimmygchen Jun 1, 2023
7e2212c
Revert incorrect change in per_epoch_processing and check progressive…
jimmygchen Jun 2, 2023
aeb086a
Initialize `ProgressiveTotalBalances` cache in `per_block_processing`
jimmygchen Jun 2, 2023
0703bcd
Passing fork choice tests \o/
jimmygchen Jun 2, 2023
d31b42e
Fix failing `per_block_processing` tests
jimmygchen Jun 2, 2023
f7cf5dd
Fix ef tests
jimmygchen Jun 2, 2023
787f67d
Fix progressive balances mismatch. Perform checks only in debug mode.…
jimmygchen Jun 6, 2023
4dbb04c
Rename to `progressive_balances_cache` and add some documentation.
jimmygchen Jun 7, 2023
17d7525
Add `--progressive-balances` flag and implement flag behaviour
jimmygchen Jun 7, 2023
33e6b70
Use `Balance` type in `ProgressiveBalancesCache` and remove balance c…
jimmygchen Jun 7, 2023
70f0fa1
Error handling cleanup. Use automatic error conversion.
jimmygchen Jun 7, 2023
3044a94
Merge branch 'unstable' into unrealized-ffg-progressive
jimmygchen Jun 13, 2023
21642f4
Add more logging to progressive cache mismatch
jimmygchen Jun 13, 2023
ec6f8fb
Add failing test for cached balances mismatch when previous epoch tar…
jimmygchen Jun 13, 2023
7dceb0c
Fix cached attester balances mismatch when previous epoch target atte…
jimmygchen Jun 13, 2023
3628c6d
Add failing test for cached balances mismatch when current epoch targ…
jimmygchen Jun 14, 2023
ecaa5ce
Fix cached balances mismatch when a current epoch target attester is …
jimmygchen Jun 15, 2023
a7c15bc
Merge branch 'unstable' into unrealized-ffg-progressive
jimmygchen Jun 16, 2023
cd57aac
Move progressive cache update logic to a separate file and add progre…
jimmygchen Jun 16, 2023
a9b151c
Add another progressive balacnes cache test for proposer slashing sce…
jimmygchen Jun 16, 2023
9bc83e5
Allow the default `ProgressiveBalancesCache::Checked` mode to fallbac…
jimmygchen Jun 16, 2023
0643a26
Merge branch 'unstable' into unrealized-ffg-progressive
jimmygchen Jun 16, 2023
0bddc9e
Add error logging when there is a balance mismatch in `Checked` mode
jimmygchen Jun 16, 2023
f31de13
Clean up: remove ProgressiveBalancesMode checks from Capella tests
jimmygchen Jun 16, 2023
5fcc4f2
Update help text.
jimmygchen Jun 16, 2023
132bf84
Fix tests compilation
jimmygchen Jun 16, 2023
9e29adf
Fix failing EF tests
jimmygchen Jun 16, 2023
93da1ed
Apply suggestions from code review
jimmygchen Jun 26, 2023
5fb3d09
Update `fork_choice.on_block` parameters order and remove some unnece…
jimmygchen Jun 26, 2023
2350ca3
Merge branch 'unstable' into unrealized-ffg-progressive
jimmygchen Jun 26, 2023
617bd3a
Fix compilation errors in tests
jimmygchen Jun 26, 2023
1da56b6
Rename `build_all_caches` as we're now only building 3/5 caches on `B…
jimmygchen Jun 26, 2023
2c9519e
Use "strict" progressive balances mode in EF tests so we start failin…
jimmygchen Jun 29, 2023
964f0bd
Update progressive balances cache metrics at the end of `per_block_pr…
jimmygchen Jun 29, 2023
72935e1
Falls back to the non-optimized unrealized FFG processing method if `…
jimmygchen Jun 29, 2023
f49daa0
Add missing checks when updating progressive balances metrics.
jimmygchen Jun 29, 2023
b12c091
Update `num_caches` to `5` in test.
jimmygchen Jun 29, 2023
90acdc7
Always fallback to the un-optimized processing method unless we're in…
jimmygchen Jun 30, 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2896,6 +2896,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
&state,
payload_verification_status,
&self.spec,
self.config.progressive_balances_mode,
&self.log,
)
.map_err(|e| BlockError::BeaconChainError(e.into()))?;
}
Expand Down
2 changes: 2 additions & 0 deletions beacon_node/beacon_chain/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@ where
store.clone(),
Some(current_slot),
&self.spec,
self.chain_config.progressive_balances_mode,
&log,
)?;
}

Expand Down
5 changes: 4 additions & 1 deletion beacon_node/beacon_chain/src/chain_config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub use proto_array::{DisallowedReOrgOffsets, ReOrgThreshold};
use serde_derive::{Deserialize, Serialize};
use std::time::Duration;
use types::{Checkpoint, Epoch};
use types::{Checkpoint, Epoch, ProgressiveBalancesMode};

pub const DEFAULT_RE_ORG_THRESHOLD: ReOrgThreshold = ReOrgThreshold(20);
pub const DEFAULT_RE_ORG_MAX_EPOCHS_SINCE_FINALIZATION: Epoch = Epoch::new(2);
Expand Down Expand Up @@ -82,6 +82,8 @@ pub struct ChainConfig {
pub always_prepare_payload: bool,
/// Whether backfill sync processing should be rate-limited.
pub enable_backfill_rate_limiting: bool,
/// Whether to use `ProgressiveBalancesCache` in unrealized FFG progression calculation.
pub progressive_balances_mode: ProgressiveBalancesMode,
}

impl Default for ChainConfig {
Expand Down Expand Up @@ -112,6 +114,7 @@ impl Default for ChainConfig {
genesis_backfill: false,
always_prepare_payload: false,
enable_backfill_rate_limiting: true,
progressive_balances_mode: ProgressiveBalancesMode::Checked,
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion beacon_node/beacon_chain/src/fork_revert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use state_processing::{
use std::sync::Arc;
use std::time::Duration;
use store::{iter::ParentRootBlockIterator, HotColdDB, ItemStore};
use types::{BeaconState, ChainSpec, EthSpec, ForkName, Hash256, SignedBeaconBlock, Slot};
use types::{
BeaconState, ChainSpec, EthSpec, ForkName, Hash256, ProgressiveBalancesMode, SignedBeaconBlock,
Slot,
};

const CORRUPT_DB_MESSAGE: &str = "The database could be corrupt. Check its file permissions or \
consider deleting it by running with the --purge-db flag.";
Expand Down Expand Up @@ -100,6 +103,8 @@ pub fn reset_fork_choice_to_finalization<E: EthSpec, Hot: ItemStore<E>, Cold: It
store: Arc<HotColdDB<E, Hot, Cold>>,
current_slot: Option<Slot>,
spec: &ChainSpec,
progressive_balances_mode: ProgressiveBalancesMode,
log: &Logger,
) -> Result<ForkChoice<BeaconForkChoiceStore<E, Hot, Cold>, E>, String> {
// Fetch finalized block.
let finalized_checkpoint = head_state.finalized_checkpoint();
Expand Down Expand Up @@ -198,6 +203,8 @@ pub fn reset_fork_choice_to_finalization<E: EthSpec, Hot: ItemStore<E>, Cold: It
&state,
payload_verification_status,
spec,
progressive_balances_mode,
log,
)
.map_err(|e| format!("Error applying replayed block to fork choice: {:?}", e))?;
}
Expand Down
30 changes: 30 additions & 0 deletions beacon_node/beacon_chain/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,36 @@ where
.sign(sk, &fork, genesis_validators_root, &self.chain.spec)
}

pub fn add_proposer_slashing(&self, validator_index: u64) -> Result<(), String> {
let propposer_slashing = self.make_proposer_slashing(validator_index);
if let ObservationOutcome::New(verified_proposer_slashing) = self
.chain
.verify_proposer_slashing_for_gossip(propposer_slashing)
.expect("should verify proposer slashing for gossip")
{
self.chain
.import_proposer_slashing(verified_proposer_slashing);
Ok(())
} else {
Err("should observe new proposer slashing".to_string())
}
}

pub fn add_attester_slashing(&self, validator_indices: Vec<u64>) -> Result<(), String> {
let attester_slashing = self.make_attester_slashing(validator_indices);
if let ObservationOutcome::New(verified_attester_slashing) = self
.chain
.verify_attester_slashing_for_gossip(attester_slashing)
.expect("should verify attester slashing for gossip")
{
self.chain
.import_attester_slashing(verified_attester_slashing);
Ok(())
} else {
Err("should observe new attester slashing".to_string())
}
}

pub fn add_bls_to_execution_change(
&self,
validator_index: u64,
Expand Down
18 changes: 4 additions & 14 deletions beacon_node/beacon_chain/tests/capella.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,8 @@ async fn base_altair_merge_capella() {
for _ in (merge_fork_slot.as_u64() + 3)..capella_fork_slot.as_u64() {
harness.extend_slots(1).await;
let block = &harness.chain.head_snapshot().beacon_block;
let full_payload: FullPayload<E> = block
.message()
.body()
.execution_payload()
.unwrap()
.clone()
.into();
let full_payload: FullPayload<E> =
block.message().body().execution_payload().unwrap().into();
// pre-capella shouldn't have withdrawals
assert!(full_payload.withdrawals_root().is_err());
execution_payloads.push(full_payload);
Expand All @@ -151,13 +146,8 @@ async fn base_altair_merge_capella() {
for _ in 0..16 {
harness.extend_slots(1).await;
let block = &harness.chain.head_snapshot().beacon_block;
let full_payload: FullPayload<E> = block
.message()
.body()
.execution_payload()
.unwrap()
.clone()
.into();
let full_payload: FullPayload<E> =
block.message().body().execution_payload().unwrap().into();
// post-capella should have withdrawals
assert!(full_payload.withdrawals_root().is_ok());
execution_payloads.push(full_payload);
Expand Down
3 changes: 2 additions & 1 deletion beacon_node/beacon_chain/tests/payload_invalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,8 @@ async fn invalid_parent() {
&state,
PayloadVerificationStatus::Optimistic,
&rig.harness.chain.spec,

rig.harness.chain.config.progressive_balances_mode,
rig.harness.logger()
),
Err(ForkChoiceError::ProtoArrayStringError(message))
if message.contains(&format!(
Expand Down
14 changes: 14 additions & 0 deletions beacon_node/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clap::{App, Arg};
use strum::VariantNames;
use types::ProgressiveBalancesMode;

pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new("beacon_node")
Expand Down Expand Up @@ -1117,4 +1118,17 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
developers. This directory is not pruned, users should be careful to avoid \
filling up their disks.")
)
.arg(
Arg::with_name("progressive-balances")
.long("progressive-balances")
.value_name("MODE")
.help("Options to enable or disable the progressive balances cache for \
unrealized FFG progression calculation. The default `checked` mode compares \
the progressive balances from the cache against results from the existing \
method. If there is a mismatch, it falls back to the existing method. The \
optimized mode (`fast`) is faster but is still experimental, and is \
not recommended for mainnet usage at this time.")
.takes_value(true)
.possible_values(ProgressiveBalancesMode::VARIANTS)
)
}
6 changes: 6 additions & 0 deletions beacon_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,12 @@ pub fn get_config<E: EthSpec>(
client_config.network.invalid_block_storage = Some(path);
}

if let Some(progressive_balances_mode) =
clap_utils::parse_optional(cli_args, "progressive-balances")?
{
client_config.chain.progressive_balances_mode = progressive_balances_mode;
}

Ok(client_config)
}

Expand Down
1 change: 1 addition & 0 deletions beacon_node/store/src/partial_beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ macro_rules! impl_try_into_beacon_state {

// Caching
total_active_balance: <_>::default(),
progressive_balances_cache: <_>::default(),
committee_caches: <_>::default(),
pubkey_cache: <_>::default(),
exit_cache: <_>::default(),
Expand Down
Loading