Skip to content

Conversation

@twoeths
Copy link
Contributor

@twoeths twoeths commented Dec 2, 2020

resolves #1789

Goal

  • In case of a slow state transition, looping through validators inside TreeBacked structure takes a significant time
  • Create CachedValidatorsBeaconState that cache a regular validators array after the 1st loop, use it in lodestar-state-transition only. Note that when processing epoch, we always have to do the loop to prepare EpochProcess.
  • When update/add a validator, update to both the cache and TreeBacked<BeaconState>
  • When loop/read, use the cached validators if we have it

Trade off

  • We have to use setValidator, addValidator, getValidator api in state transition instead of accessing validators directly. I guess we can enforce it at compile time using Omit<BeaconState, "validators"> or something if we want to.

Performance gain with 100k validators as in Pyrmont/Medalla

  • Process 1st epoch: save 500ms - 600ms
  • From the 2nd epoch, it only takes around 1100ms per epoch (instead of >=2800ms)
  • When we have to process 16 validator exits as in the performance test, the time to process block is reduced from 6000ms to 1400ms
  • See more details in the performance tests of lodestar-beacon-state-transition

Test

  • Passed spec tests
  • Synced Pyrmont successfully

Memory

  • When we process a regular block it even does not create a cached validators
  • It short-live in state transition only then released

Although the performance is improved, I'd like to have everyone review to see if we have any potential issues with this approach. Thanks!

readonly previousShuffling?: IReadonlyEpochShuffling;
getBeaconProposer: (slot: Slot) => ValidatorIndex;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

main file to review

@twoeths twoeths marked this pull request as ready for review December 2, 2020 23:16
@twoeths twoeths force-pushed the tuyen/cached-validators-beacon-state branch from 2ee6ec0 to 6538e0c Compare December 9, 2020 09:28
@qlty-cloud-legacy
Copy link

Code Climate has analyzed commit 6538e0c and detected 0 issues on this pull request.

View more on Code Climate.

@twoeths
Copy link
Contributor Author

twoeths commented Jan 2, 2021

replaced by #1925

@twoeths twoeths closed this Jan 2, 2021
@wemeetagain wemeetagain deleted the tuyen/cached-validators-beacon-state branch June 12, 2021 16:48
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.

POC: Create a StateTransitionBeaconState

2 participants