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

fix: improve processEffectiveBalanceUpdates #7043

Conversation

twoeths
Copy link
Contributor

@twoeths twoeths commented Aug 22, 2024

Motivation

@nflaig found that epoch transition is 10x slower as seen in altair processEpoch - mainnet_e81889 benchmark. This is because we broke the optimization in #2902

Description

  • cache validators in beforeProcessEpoch()
  • cache new compounding validators in processPendingConsolidations
  • update processEffectiveBalanceUpdates(): use the above to compute effectiveBalanceLimit to avoid unnecessary updates
  • also track it in numEffectiveBalanceUpdates metric

Copy link

codecov bot commented Aug 22, 2024

Codecov Report

Attention: Patch coverage is 6.89655% with 27 lines in your changes missing coverage. Please review.

Project coverage is 49.37%. Comparing base (499cf57) to head (275f82e).
Report is 1 commits behind head on electra-fork-rebasejul30.

Additional details and impacted files
@@                     Coverage Diff                      @@
##           electra-fork-rebasejul30    #7043      +/-   ##
============================================================
- Coverage                     49.39%   49.37%   -0.03%     
============================================================
  Files                           589      589              
  Lines                         39217    39233      +16     
  Branches                       2250     2243       -7     
============================================================
- Hits                          19372    19371       -1     
- Misses                        19804    19821      +17     
  Partials                         41       41              

@twoeths twoeths mentioned this pull request Aug 22, 2024
@ensi321
Copy link
Contributor

ensi321 commented Aug 22, 2024

Wonder why this isn't caught by the benchmark check.

This branch previously had a bad benchmark on processEffectiveBalanceUpdates but #7018 fixed it.

@twoeths
Copy link
Contributor Author

twoeths commented Aug 23, 2024

Wonder why this isn't caught by the benchmark check.

This branch previously had a bad benchmark on processEffectiveBalanceUpdates but #7018 fixed it.

@ensi321 the benchmark did not fail on processEffectiveBalanceUpdates(), instead it failed on processEpoch(), specifically on state.hashTreeRoot()

the current version of processEffectiveBalanceUpdates() introduced redundant updates on validator.effectiveBalance with the same value and it caused pressure on the state.hashTreeRoot(). This is fixed by (effectiveBalance < effectiveBalanceLimit && effectiveBalance + UPWARD_THRESHOLD < balance) condition

@twoeths twoeths marked this pull request as ready for review August 23, 2024 03:22
@twoeths twoeths requested a review from a team as a code owner August 23, 2024 03:22
@twoeths
Copy link
Contributor Author

twoeths commented Aug 23, 2024

spec tests passed, benchmark was confirmed in local env

this branch

 altair processEpoch - mainnet_e81889
    ✔ altair processEpoch - mainnet_e81889                                3.343826 ops/s    299.0586 ms/op        -         12 runs   4.24 s

which is 10x faster than electra branch

altair processEpoch - mainnet_e81889
    ✔ altair processEpoch - mainnet_e81889                               0.3105313 ops/s    3.220287  s/op        -         12 runs   41.8 s

e2e consistently failed but it's the common issue of electra branch, see #6986 (comment)

@twoeths twoeths force-pushed the te/improve_process_effective_balance_updates branch from 12296dc to 275f82e Compare August 24, 2024 07:57
Copy link
Member

@nflaig nflaig left a comment

Choose a reason for hiding this comment

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

LGTM

@wemeetagain wemeetagain merged commit df82482 into electra-fork-rebasejul30 Aug 27, 2024
17 checks passed
@wemeetagain wemeetagain deleted the te/improve_process_effective_balance_updates branch August 27, 2024 14:39
@wemeetagain
Copy link
Member

🎉 This PR is included in v1.22.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants