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

feat(blockchain): introducing validator size cap size #2119

Open
wants to merge 15 commits into
base: fix-maximum-number-withdrawals
Choose a base branch
from

Conversation

abi87
Copy link
Collaborator

@abi87 abi87 commented Nov 1, 2024

This PR:

  • Introduces a cap on the validator set size
  • Schedule withdrawals of deposits for validators which would breach the validator set size cap

This PR currently fails e2e tests since it's based on #2110

@abi87 abi87 self-assigned this Nov 1, 2024
Copy link
Contributor

coderabbitai bot commented Nov 1, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@abi87 abi87 changed the base branch from main to fix-maximum-number-withdrawals November 1, 2024 09:51
Copy link

codecov bot commented Nov 1, 2024

Codecov Report

Attention: Patch coverage is 45.45455% with 18 lines in your changes missing coverage. Please review.

Project coverage is 26.58%. Comparing base (d8a267e) to head (32fbbbc).

Files with missing lines Patch % Lines
...ate-transition/pkg/core/state_processor_genesis.go 0.00% 6 Missing and 1 partial ⚠️
...ate-transition/pkg/core/state_processor_staking.go 73.68% 2 Missing and 3 partials ⚠️
mod/chain-spec/pkg/chain/chain_spec.go 0.00% 2 Missing ⚠️
mod/consensus-types/pkg/types/validator.go 0.00% 2 Missing ⚠️
mod/state-transition/pkg/core/state_processor.go 0.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@                        Coverage Diff                         @@
##           fix-maximum-number-withdrawals    #2119      +/-   ##
==================================================================
+ Coverage                           26.41%   26.58%   +0.16%     
==================================================================
  Files                                 357      357              
  Lines                               16075    16097      +22     
  Branches                               12       12              
==================================================================
+ Hits                                 4247     4280      +33     
+ Misses                              11560    11547      -13     
- Partials                              268      270       +2     
Files with missing lines Coverage Δ
mod/config/pkg/spec/testnet.go 100.00% <100.00%> (ø)
mod/chain-spec/pkg/chain/chain_spec.go 12.50% <0.00%> (-0.33%) ⬇️
mod/consensus-types/pkg/types/validator.go 94.06% <0.00%> (-1.63%) ⬇️
mod/state-transition/pkg/core/state_processor.go 29.82% <0.00%> (-1.51%) ⬇️
...ate-transition/pkg/core/state_processor_staking.go 60.10% <73.68%> (+7.85%) ⬆️
...ate-transition/pkg/core/state_processor_genesis.go 46.60% <0.00%> (-3.40%) ⬇️

... and 1 file with indirect coverage changes

@abi87 abi87 marked this pull request as ready for review November 1, 2024 11:26
@abi87 abi87 added the DO NOT MERGE just don't merge it (just yet) label Nov 1, 2024
Comment on lines +114 to +120
if uint32(len(deposits)) > sp.cs.GetValidatorsSetCapSize() {
return nil, fmt.Errorf("validator set cap %d, deposits count %d: %w",
sp.cs.GetValidatorsSetCapSize(),
len(deposits),
ErrHitValidatorsSetCap,
)
}
Copy link
Collaborator Author

@abi87 abi87 Nov 1, 2024

Choose a reason for hiding this comment

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

here I assume deposits in genesis maps one to one with genesis validators and we do not have two different updates for the same validator.
Is it a fair assumption @chuck-bear, @itsdevbear?

Copy link
Contributor

Choose a reason for hiding this comment

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

may be necessary to allow multiple deposits per genesis validator if each deposit is capped to some amount like 32

Comment on lines +216 to +218
if sp.cs.DepositEth1ChainID() == bArtioChainID {
return st.AddValidatorBartio(val)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

replicating here the fix from #2111 to avoid double counting Bartio Validators balances (done implicitly in AddValidatorBartio)

// TODO: This is a bug that lives on bArtio. Delete this eventually.
if sp.cs.DepositEth1ChainID() == bArtioChainID {
if err := st.AddValidatorBartio(val); err != nil {
if !sp.processingGenesis {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

minor optimization which we may drop for readability.
Currently I chose to fail node initialization if genesis has more validators than the validator set cap, so here I can skip the check.
However we may chose to allow genesis have more validators than cap and immediately mark the ready for eviction.
@itsdevbear @chuck-bear thoughts?

@abi87 abi87 added Ready for Review and removed DO NOT MERGE just don't merge it (just yet) labels Nov 4, 2024
@@ -183,6 +183,8 @@ type Spec[
// GetCometBFTConfigForSlot retrieves the CometBFT config for a specific
// slot.
GetCometBFTConfigForSlot(slot SlotT) CometBFTConfigT

GetValidatorsSetCapSize() uint32
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
GetValidatorsSetCapSize() uint32
// GetValidatorSetCap retrieves the maximum number of validators allowed in the active set.
GetValidatorSetCap() uint32

nit + comment

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems comment was changed, but function name still needs to be changed to GetValidatorSetCap

@abi87 abi87 requested a review from calbera November 4, 2024 23:17
// allowed in the active set.
func (c chainSpec[
DomainTypeT, EpochT, ExecutionAddressT, SlotT, CometBFTConfigT,
]) GetValidatorsSetCapSize() uint32 {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: GetValidatorSetCap

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

Successfully merging this pull request may close these issues.

3 participants