Skip to content

fix: cached balances in epoch transition - #7018

Merged
ensi321 merged 2 commits into
electra-fork-rebasejul30from
te/cached_balances
Aug 13, 2024
Merged

fix: cached balances in epoch transition#7018
ensi321 merged 2 commits into
electra-fork-rebasejul30from
te/cached_balances

Conversation

@twoeths

@twoeths twoeths commented Aug 13, 2024

Copy link
Copy Markdown
Member

Motivation

  • Use cached balances in processEffectiveBalanceUpdates
  • Use state.validators.getReadonly() if possible

Description

  • Update cached balances in processPendingBalanceDeposits and processPendingConsolidations
  • Use it in processEffectiveBalanceUpdates

@ensi321

ensi321 commented Aug 13, 2024

Copy link
Copy Markdown
Member

I was looking into this issue as well.

If I understand correctly, the reason why EpochTransitionCache.balances is not correct because it wasn't updated in processPendingConsolidations and processPendingBalanceDeposits?

Comment thread packages/state-transition/src/epoch/processEffectiveBalanceUpdates.ts Outdated
@twoeths

twoeths commented Aug 13, 2024

Copy link
Copy Markdown
Member Author

I was looking into this issue as well.

If I understand correctly, the reason why EpochTransitionCache.balances is not correct because it wasn't updated in processPendingConsolidations and processPendingBalanceDeposits?

@ensi321 yes it is, but I wasn't able to confirm through spec test

@codecov

codecov Bot commented Aug 13, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 10.71429% with 25 lines in your changes missing coverage. Please review.

Project coverage is 49.36%. Comparing base (bbc2301) to head (3a80edd).

Additional details and impacted files
@@                     Coverage Diff                      @@
##           electra-fork-rebasejul30    #7018      +/-   ##
============================================================
- Coverage                     49.37%   49.36%   -0.02%     
============================================================
  Files                           589      589              
  Lines                         39137    39151      +14     
  Branches                       2235     2238       +3     
============================================================
+ Hits                          19325    19327       +2     
- Misses                        19771    19783      +12     
  Partials                         41       41              

@ensi321

ensi321 commented Aug 13, 2024

Copy link
Copy Markdown
Member

Looks like spec test is still passing when introducing back cache.balances in processEffectiveBalanceUpdates.

benchmark is not ran in this PR since the target branch is not unstable.

I ran processEffectiveBalanceUpdates.test.ts with unstable, electra-fork-rebasejul30 and te/cached_balances to compare the result.

unstable:

  phase0 processEffectiveBalanceUpdates
    ✔ phase0 processEffectiveBalanceUpdates - 250000 normalcase           521.4966 ops/s    1.917558 ms/op        -        234 runs   2.02 s
    ✔ phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5        544.3978 ops/s    1.836892 ms/op        -        273 runs   2.01 s

electra-fork-rebasejul30:

  phase0 processEffectiveBalanceUpdates
    ✔ phase0 processEffectiveBalanceUpdates - 250000 normalcase           197.5429 ops/s    5.062191 ms/op        -        103 runs   1.66 s
    ✔ phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5        206.3787 ops/s    4.845461 ms/op        -         70 runs   1.42 s

te/cached_balances

  phase0 processEffectiveBalanceUpdates
    ✔ phase0 processEffectiveBalanceUpdates - 250000 normalcase           557.8163 ops/s    1.792705 ms/op        -        175 runs   1.80 s
    ✔ phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5        562.7605 ops/s    1.776955 ms/op        -        488 runs   2.65 s

Suffice to say in this PR processEffectiveBalanceUpdates passes both perf test and spec test so this fix is effective.

@twoeths
twoeths marked this pull request as ready for review August 13, 2024 11:22
@twoeths
twoeths requested a review from a team as a code owner August 13, 2024 11:22

@ensi321 ensi321 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@ensi321
ensi321 merged commit fb492e5 into electra-fork-rebasejul30 Aug 13, 2024
@ensi321
ensi321 deleted the te/cached_balances branch August 13, 2024 12:35
g11tech pushed a commit that referenced this pull request Aug 23, 2024
* fix: update cached balances in epoch transition

* fix: more comments in processEffectiveBalanceUpdates()
g11tech pushed a commit that referenced this pull request Aug 27, 2024
* fix: update cached balances in epoch transition

* fix: more comments in processEffectiveBalanceUpdates()
philknows pushed a commit that referenced this pull request Sep 3, 2024
* fix: update cached balances in epoch transition

* fix: more comments in processEffectiveBalanceUpdates()
@wemeetagain

Copy link
Copy Markdown
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.

3 participants