-
Notifications
You must be signed in to change notification settings - Fork 992
[Merged by Bors] - Cache target attester balances for unrealized FFG progression calculation #4362
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
Closed
Closed
Changes from 10 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
9eb6f5b
Initial implementation of `ProgressiveTotalBalances` cache
jimmygchen c650a71
Use `ProgressiveTotalBalances` cache to process jutification and fina…
jimmygchen 36ca37a
Add `ProgressiveTotalBalances` cache to `BeaconState` clone config
jimmygchen 7e2212c
Revert incorrect change in per_epoch_processing and check progressive…
jimmygchen aeb086a
Initialize `ProgressiveTotalBalances` cache in `per_block_processing`
jimmygchen 0703bcd
Passing fork choice tests \o/
jimmygchen d31b42e
Fix failing `per_block_processing` tests
jimmygchen f7cf5dd
Fix ef tests
jimmygchen 787f67d
Fix progressive balances mismatch. Perform checks only in debug mode.…
jimmygchen 4dbb04c
Rename to `progressive_balances_cache` and add some documentation.
jimmygchen 17d7525
Add `--progressive-balances` flag and implement flag behaviour
jimmygchen 33e6b70
Use `Balance` type in `ProgressiveBalancesCache` and remove balance c…
jimmygchen 70f0fa1
Error handling cleanup. Use automatic error conversion.
jimmygchen 3044a94
Merge branch 'unstable' into unrealized-ffg-progressive
jimmygchen 21642f4
Add more logging to progressive cache mismatch
jimmygchen ec6f8fb
Add failing test for cached balances mismatch when previous epoch tar…
jimmygchen 7dceb0c
Fix cached attester balances mismatch when previous epoch target atte…
jimmygchen 3628c6d
Add failing test for cached balances mismatch when current epoch targ…
jimmygchen ecaa5ce
Fix cached balances mismatch when a current epoch target attester is …
jimmygchen a7c15bc
Merge branch 'unstable' into unrealized-ffg-progressive
jimmygchen cd57aac
Move progressive cache update logic to a separate file and add progre…
jimmygchen a9b151c
Add another progressive balacnes cache test for proposer slashing sce…
jimmygchen 9bc83e5
Allow the default `ProgressiveBalancesCache::Checked` mode to fallbac…
jimmygchen 0643a26
Merge branch 'unstable' into unrealized-ffg-progressive
jimmygchen 0bddc9e
Add error logging when there is a balance mismatch in `Checked` mode
jimmygchen f31de13
Clean up: remove ProgressiveBalancesMode checks from Capella tests
jimmygchen 5fcc4f2
Update help text.
jimmygchen 132bf84
Fix tests compilation
jimmygchen 9e29adf
Fix failing EF tests
jimmygchen 93da1ed
Apply suggestions from code review
jimmygchen 5fb3d09
Update `fork_choice.on_block` parameters order and remove some unnece…
jimmygchen 2350ca3
Merge branch 'unstable' into unrealized-ffg-progressive
jimmygchen 617bd3a
Fix compilation errors in tests
jimmygchen 1da56b6
Rename `build_all_caches` as we're now only building 3/5 caches on `B…
jimmygchen 2c9519e
Use "strict" progressive balances mode in EF tests so we start failin…
jimmygchen 964f0bd
Update progressive balances cache metrics at the end of `per_block_pr…
jimmygchen 72935e1
Falls back to the non-optimized unrealized FFG processing method if `…
jimmygchen f49daa0
Add missing checks when updating progressive balances metrics.
jimmygchen b12c091
Update `num_caches` to `5` in test.
jimmygchen 90acdc7
Always fallback to the un-optimized processing method unless we're in…
jimmygchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
consensus/state_processing/src/common/initialize_progressive_balances_cache.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| use crate::per_epoch_processing::altair::ParticipationCache; | ||
| use std::borrow::Cow; | ||
| use types::{BeaconState, BeaconStateError, ChainSpec, EthSpec}; | ||
|
|
||
| /// Initializes the `ProgressiveBalancesCache` cache using balance values from the | ||
| /// `ParticipationCache`. If the optional `&ParticipationCache` is not supplied, it will be computed | ||
| /// from the `BeaconState`. | ||
| pub fn initialize_progressive_balances_cache<E: EthSpec>( | ||
| state: &mut BeaconState<E>, | ||
| maybe_participation_cache: Option<&ParticipationCache>, | ||
| spec: &ChainSpec, | ||
| ) -> Result<(), BeaconStateError> { | ||
| if !is_progressive_balances_enabled(state) | ||
| || state.progressive_balances_cache().is_initialized() | ||
| { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| let participation_cache = match maybe_participation_cache { | ||
| Some(cache) => Cow::Borrowed(cache), | ||
| None => Cow::Owned(ParticipationCache::new(state, spec)?), | ||
| }; | ||
|
|
||
| // FIXME[JC]: Converts value to 0 if it is the same as `EFFECTIVE_BALANCE_INCREMENT`. | ||
| // `ParticipationCache` methods return `EFFECTIVE_BALANCE_INCREMENT` (1,000,000,000) | ||
| // when the balance is 0, and this breaks our calculation. | ||
| let handle_zero_effective_balance = |val| { | ||
| if val == spec.effective_balance_increment { | ||
| 0 | ||
| } else { | ||
| val | ||
| } | ||
| }; | ||
|
|
||
| let previous_epoch_target_attesting_balance = participation_cache | ||
| .previous_epoch_target_attesting_balance() | ||
| .map(handle_zero_effective_balance) | ||
| .map_err(|e| BeaconStateError::ParticipationCacheError(format!("{:?}", e)))?; | ||
|
|
||
| let current_epoch_target_attesting_balance = participation_cache | ||
| .current_epoch_target_attesting_balance() | ||
| .map(handle_zero_effective_balance) | ||
| .map_err(|e| BeaconStateError::ParticipationCacheError(format!("{:?}", e)))?; | ||
|
|
||
| let current_epoch = state.current_epoch(); | ||
| state.progressive_balances_cache_mut().initialize( | ||
| current_epoch, | ||
| previous_epoch_target_attesting_balance, | ||
| current_epoch_target_attesting_balance, | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// `ProgressiveBalancesCache` is only enabled from `Altair` as it requires `ParticipationCache`. | ||
| fn is_progressive_balances_enabled<E: EthSpec>(state: &BeaconState<E>) -> bool { | ||
| match state { | ||
| BeaconState::Base(_) => false, | ||
| BeaconState::Altair(_) | BeaconState::Merge(_) | BeaconState::Capella(_) => true, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.