-
Notifications
You must be signed in to change notification settings - Fork 805
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] - Cache target attester balances for unrealized FFG progression calculation #4362
Conversation
…lization if balances are available.
… balances cache in fork choice.
d3e25db
to
e84d432
Compare
6dd579d
to
fef3e16
Compare
fef3e16
to
787f67d
Compare
consensus/state_processing/src/common/initialize_progressive_balances_cache.rs
Outdated
Show resolved
Hide resolved
Renamed to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking really good! There's quite a few edge-cases in here that have been covered well (e.g., slashings, balance updates at the end of an epoch).
I just have a few very minor suggestions/comments!
consensus/state_processing/src/common/update_progressive_balances_cache.rs
Outdated
Show resolved
Hide resolved
// Load cached balances | ||
let progressive_balances_cache: &ProgressiveBalancesCache = state.progressive_balances_cache(); | ||
let previous_target_balance = | ||
progressive_balances_cache.previous_epoch_target_attesting_balance()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice that we're expecting to have an initialized progressive_balances_cache
and that we're going to error-out on on_block
if we don't.
I understand that we are expecting an initialized cache since it's always called at the start of per_block_processing
. This seems like a reasonable assumption to me, since I don't see any reason why we'd be processing a state
in on_block
that didn't just have a state applied to it.
Perhaps it would be more in the spirit of Checked
mode for us just to default back to the non-optimized method if we happen to discover an uninitialized progressive_balances_cache
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it would be more in the spirit of Checked mode for us just to default back to the non-optimized method if we happen to discover an uninitialized progressive_balances_cache?
This is a great point! Checked
mode should just always fallback to the non-optimized method if there's anything wrong with the progressive_balances_cache
. I've re-arranged the code a bit so that it falls back to the original method if this function failed for whatever reason in Checked
mode.
Updated in 72935e1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, missed a check in the previous commit and broke some tests. Fixed in f49daa0.
…g tests if there's a mismatch.
…ocessing` rather than per attestation / slashing.
…progressive_balances_cache` isn't initialized.
6ba7e45
to
f49daa0
Compare
if progressive_balances_mode == ProgressiveBalancesMode::Checked { | ||
error!( | ||
log, | ||
"Processing with progressive balances cache failed in checked mode"; | ||
"info" => "falling back to the non-optimized processing method", | ||
"error" => ?e, | ||
); | ||
per_epoch_processing::altair::process_justification_and_finalization( | ||
state, | ||
maybe_participation_cache.as_ref().ok_or(Error::ParticipationCacheMissing)?, | ||
).map_err(Error::from) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if progressive_balances_mode == ProgressiveBalancesMode::Checked { | |
error!( | |
log, | |
"Processing with progressive balances cache failed in checked mode"; | |
"info" => "falling back to the non-optimized processing method", | |
"error" => ?e, | |
); | |
per_epoch_processing::altair::process_justification_and_finalization( | |
state, | |
maybe_participation_cache.as_ref().ok_or(Error::ParticipationCacheMissing)?, | |
).map_err(Error::from) | |
if progressive_balances_mode != ProgressiveBalancesMode::Strict { | |
error!( | |
log, | |
"Processing with progressive balances cache failed in checked mode"; | |
"info" => "falling back to the non-optimized processing method", | |
"error" => ?e, | |
); | |
let participation_cache = maybe_participation_cache | |
.map(Result::Ok) | |
.unwrap_or_else(|| ParticipationCache::new(state, spec)) | |
.map_err(Error::ParticipationCacheBuild)?; | |
per_epoch_processing::altair::process_justification_and_finalization( | |
state, | |
&participation_cache, | |
).map_err(Error::from) |
We could be a little bit more paranoid here and always fall back to the old method if the new method fails (unless we're in Strict
mode)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, being paranoid is good for us - I need more of this actually, it's a bit of a mindset shift to what I have been used to for a while!
This is definitely much better error handling! (and the unwrap_or_else
fallback), will update to the suggested approach and remove the unnecessary ParticipationCacheMissing
error variant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 90acdc7. Thanks 🙏
… strict mode. Improved error handling from review suggestions. Co-authored-by: Paul Hauner <6660660+paulhauner@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! I have full confidence that the new implementation is correct, and it doesn't even matter if it's not! 🎉
bors r+ |
…tion (#4362) ## Issue Addressed #4118 ## Proposed Changes This PR introduces a "progressive balances" cache on the `BeaconState`, which keeps track of the accumulated target attestation balance for the current & previous epochs. The cached values are utilised by fork choice to calculate unrealized justification and finalization (instead of converting epoch participation arrays to balances for each block we receive). This optimization will be rolled out gradually to allow for more testing. A new `--progressive-balances disabled|checked|strict|fast` flag is introduced to support this: - `checked`: enabled with checks against participation cache, and falls back to the existing epoch processing calculation if there is a total target attester balance mismatch. There is no performance gain from this as the participation cache still needs to be computed. **This is the default mode for now.** - `strict`: enabled with checks against participation cache, returns error if there is a mismatch. **Used for testing only**. - `fast`: enabled with no comparative checks and without computing the participation cache. This mode gives us the performance gains from the optimization. This is still experimental and not currently recommended for production usage, but will become the default mode in a future release. - `disabled`: disable the usage of progressive cache, and use the existing method for FFG progression calculation. This mode may be useful if we find a bug and want to stop the frequent error logs. ### Tasks - [x] Initial cache implementation in `BeaconState` - [x] Perform checks in fork choice to compare the progressive balances cache against results from `ParticipationCache` - [x] Add CLI flag, and disable the optimization by default - [x] Testing on Goerli & Benchmarking - [x] Move caching logic from state processing to the `ProgressiveBalancesCache` (see [this comment](#4362 (comment))) - [x] Add attesting balance metrics Co-authored-by: Jimmy Chen <jimmy@sigmaprime.io>
Pull request successfully merged into unstable. Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page.
|
…tion (sigp#4362) ## Issue Addressed sigp#4118 ## Proposed Changes This PR introduces a "progressive balances" cache on the `BeaconState`, which keeps track of the accumulated target attestation balance for the current & previous epochs. The cached values are utilised by fork choice to calculate unrealized justification and finalization (instead of converting epoch participation arrays to balances for each block we receive). This optimization will be rolled out gradually to allow for more testing. A new `--progressive-balances disabled|checked|strict|fast` flag is introduced to support this: - `checked`: enabled with checks against participation cache, and falls back to the existing epoch processing calculation if there is a total target attester balance mismatch. There is no performance gain from this as the participation cache still needs to be computed. **This is the default mode for now.** - `strict`: enabled with checks against participation cache, returns error if there is a mismatch. **Used for testing only**. - `fast`: enabled with no comparative checks and without computing the participation cache. This mode gives us the performance gains from the optimization. This is still experimental and not currently recommended for production usage, but will become the default mode in a future release. - `disabled`: disable the usage of progressive cache, and use the existing method for FFG progression calculation. This mode may be useful if we find a bug and want to stop the frequent error logs. ### Tasks - [x] Initial cache implementation in `BeaconState` - [x] Perform checks in fork choice to compare the progressive balances cache against results from `ParticipationCache` - [x] Add CLI flag, and disable the optimization by default - [x] Testing on Goerli & Benchmarking - [x] Move caching logic from state processing to the `ProgressiveBalancesCache` (see [this comment](sigp#4362 (comment))) - [x] Add attesting balance metrics Co-authored-by: Jimmy Chen <jimmy@sigmaprime.io>
…tion (sigp#4362) This PR introduces a "progressive balances" cache on the `BeaconState`, which keeps track of the accumulated target attestation balance for the current & previous epochs. The cached values are utilised by fork choice to calculate unrealized justification and finalization (instead of converting epoch participation arrays to balances for each block we receive). This optimization will be rolled out gradually to allow for more testing. A new `--progressive-balances disabled|checked|strict|fast` flag is introduced to support this: - `checked`: enabled with checks against participation cache, and falls back to the existing epoch processing calculation if there is a total target attester balance mismatch. There is no performance gain from this as the participation cache still needs to be computed. **This is the default mode for now.** - `strict`: enabled with checks against participation cache, returns error if there is a mismatch. **Used for testing only**. - `fast`: enabled with no comparative checks and without computing the participation cache. This mode gives us the performance gains from the optimization. This is still experimental and not currently recommended for production usage, but will become the default mode in a future release. - `disabled`: disable the usage of progressive cache, and use the existing method for FFG progression calculation. This mode may be useful if we find a bug and want to stop the frequent error logs. - [x] Initial cache implementation in `BeaconState` - [x] Perform checks in fork choice to compare the progressive balances cache against results from `ParticipationCache` - [x] Add CLI flag, and disable the optimization by default - [x] Testing on Goerli & Benchmarking - [x] Move caching logic from state processing to the `ProgressiveBalancesCache` (see [this comment](sigp#4362 (comment))) - [x] Add attesting balance metrics Co-authored-by: Jimmy Chen <jimmy@sigmaprime.io>
…tion (sigp#4362) This PR introduces a "progressive balances" cache on the `BeaconState`, which keeps track of the accumulated target attestation balance for the current & previous epochs. The cached values are utilised by fork choice to calculate unrealized justification and finalization (instead of converting epoch participation arrays to balances for each block we receive). This optimization will be rolled out gradually to allow for more testing. A new `--progressive-balances disabled|checked|strict|fast` flag is introduced to support this: - `checked`: enabled with checks against participation cache, and falls back to the existing epoch processing calculation if there is a total target attester balance mismatch. There is no performance gain from this as the participation cache still needs to be computed. **This is the default mode for now.** - `strict`: enabled with checks against participation cache, returns error if there is a mismatch. **Used for testing only**. - `fast`: enabled with no comparative checks and without computing the participation cache. This mode gives us the performance gains from the optimization. This is still experimental and not currently recommended for production usage, but will become the default mode in a future release. - `disabled`: disable the usage of progressive cache, and use the existing method for FFG progression calculation. This mode may be useful if we find a bug and want to stop the frequent error logs. - [x] Initial cache implementation in `BeaconState` - [x] Perform checks in fork choice to compare the progressive balances cache against results from `ParticipationCache` - [x] Add CLI flag, and disable the optimization by default - [x] Testing on Goerli & Benchmarking - [x] Move caching logic from state processing to the `ProgressiveBalancesCache` (see [this comment](sigp#4362 (comment))) - [x] Add attesting balance metrics Co-authored-by: Jimmy Chen <jimmy@sigmaprime.io>
Issue Addressed
#4118
Proposed Changes
This PR introduces a "progressive balances" cache on the
BeaconState
, which keeps track of the accumulated target attestation balance for the current & previous epochs. The cached values are utilised by fork choice to calculate unrealized justification and finalization (instead of converting epoch participation arrays to balances for each block we receive).This optimization will be rolled out gradually to allow for more testing. A new
--progressive-balances disabled|checked|strict|fast
flag is introduced to support this:checked
: enabled with checks against participation cache, and falls back to the existing epoch processing calculation if there is a total target attester balance mismatch. There is no performance gain from this as the participation cache still needs to be computed. This is the default mode for now.strict
: enabled with checks against participation cache, returns error if there is a mismatch. Used for testing only.fast
: enabled with no comparative checks and without computing the participation cache. This mode gives us the performance gains from the optimization. This is still experimental and not currently recommended for production usage, but will become the default mode in a future release.disabled
: disable the usage of progressive cache, and use the existing method for FFG progression calculation. This mode may be useful if we find a bug and want to stop the frequent error logs.Tasks
BeaconState
ParticipationCache
ProgressiveBalancesCache
(see this comment)