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] - Optimise balances cache in case of skipped slots #2849

Closed

Conversation

michaelsproul
Copy link
Member

Proposed Changes

Remove the is_first_block_in_epoch logic from the balances cache update logic, as it was incorrect in the case of skipped slots. The updated code is simpler because regardless of whether the block is the first in the epoch we can check if an entry for the epoch boundary root already exists in the cache, and update the cache accordingly.

Additionally, to assist with flip-flopping justified epochs, move to cloning the balance cache rather than moving it. This should still be very fast in practice because the balances cache is a ~1.6MB Vec, and this operation is expected to only occur infrequently.

@michaelsproul
Copy link
Member Author

I've implemented a schema migration for this change to address the issue described here: https://hackmd.io/@sproul/HyUjTaSFY

The migration is here: michaelsproul@f1496b9

I'll push it to this branch once #2822 is merged

@michaelsproul michaelsproul added blocked and removed work-in-progress PR is a work-in-progress labels Dec 3, 2021
@michaelsproul
Copy link
Member Author

michaelsproul commented Dec 12, 2021

Rebased on #2822. The two unique commits from this PR are:

Copy link
Member

@paulhauner paulhauner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! Thanks for fixing this, these are my bugs from before I had a grip on caching things like this 🙏

The cache works much nicer now!

@michaelsproul michaelsproul added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Dec 13, 2021
@michaelsproul
Copy link
Member Author

Going to try an optimistic merge!

bors r+

bors bot pushed a commit that referenced this pull request Dec 13, 2021
## Proposed Changes

Remove the `is_first_block_in_epoch` logic from the balances cache update logic, as it was incorrect in the case of skipped slots. The updated code is simpler because regardless of whether the block is the first in the epoch we can check if an entry for the epoch boundary root already exists in the cache, and update the cache accordingly.

Additionally, to assist with flip-flopping justified epochs, move to cloning the balance cache rather than moving it. This should still be very fast in practice because the balances cache is a ~1.6MB `Vec`, and this operation is expected to only occur infrequently.
@bors bors bot changed the title Optimise balances cache in case of skipped slots [Merged by Bors] - Optimise balances cache in case of skipped slots Dec 14, 2021
@bors bors bot closed this Dec 14, 2021
@michaelsproul michaelsproul deleted the balances-cache-skip branch December 14, 2021 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge This PR is ready to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants