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(staking): limit valset by config #1886

Merged
merged 3 commits into from
Aug 12, 2024
Merged

Conversation

ocnc
Copy link
Contributor

@ocnc ocnc commented Aug 12, 2024

no longer uses the giga library bc idk if i can iter w index but code cleaner?

will implement forced withdrawals in next PR + will do some statedb updates there as well

Summary by CodeRabbit

  • New Features

    • Introduced a new field, MaxCommitteeSize, in the BeraChainSpec for enhanced configuration options.
    • Added a helper function for handling forced withdrawals in state processing.
  • Bug Fixes

    • Improved error handling and control flow in the state transition processing, ensuring better error management.
  • Documentation

    • Enhanced clarity of comments in the BeraChainSpec struct for better understanding.
  • Refactor

    • Refined the processSyncCommitteeUpdates function to enhance readability and maintainability.

@ocnc ocnc requested a review from itsdevbear as a code owner August 12, 2024 19:05
Copy link
Contributor

coderabbitai bot commented Aug 12, 2024

Walkthrough

The recent changes enhance the berad module by streamlining dependencies, improving struct definitions, and refining state processing logic. Notable additions include the MaxCommitteeSize field in BeraChainSpec and a new helper function for forced withdrawals. Error handling has been strengthened, promoting better control flow and maintainability throughout the state transition processes.

Changes

Files Change Summary
examples/berad/go.mod Removed dependency on github.com/sourcegraph/conc, reducing module complexity.
examples/berad/pkg/chain-spec/berachain.go Added MaxCommitteeSize field to BeraChainSpec and clarified the comment for BGTContractAddress.
examples/berad/pkg/state-transition/state_processor.go Enhanced error handling in processStateTransition, ensuring immediate error returns and improved clarity.
examples/berad/pkg/state-transition/state_processor_committee.go Changed processSyncCommitteeUpdates to an imperative approach for better readability and error handling.
examples/berad/pkg/state-transition/state_processor_staking.go Introduced processForcedWithdrawals function for handling forced withdrawals; updated import section.

Sequence Diagram(s)

sequenceDiagram
    participant SP as StateProcessor
    participant ST as State
    participant V as Validator
    SP->>ST: processStateTransition()
    alt Error Handling
        ST-->>SP: return error
    else Successful Processing
        SP->>V: processSyncCommitteeUpdates()
        V-->>SP: return updates
    end
    SP->>ST: processForcedWithdrawals()
Loading

🐇 In a land where the code hops and plays,
New fields and functions brighten our days.
With each little change, the logic grows clear,
Improving our state, we’ve nothing to fear!
So let’s cheer for the work, let’s give it a whirl,
For our module’s now better, let’s give it a twirl! 🥕✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between fcf588a and a5b1fa9.

Files ignored due to path filters (1)
  • examples/berad/go.sum is excluded by !**/*.sum
Files selected for processing (5)
  • examples/berad/go.mod (1 hunks)
  • examples/berad/pkg/chain-spec/berachain.go (1 hunks)
  • examples/berad/pkg/state-transition/state_processor.go (1 hunks)
  • examples/berad/pkg/state-transition/state_processor_committee.go (2 hunks)
  • examples/berad/pkg/state-transition/state_processor_staking.go (2 hunks)
Additional comments not posted (2)
examples/berad/pkg/chain-spec/berachain.go (1)

34-37: LGTM!

The addition of the MaxCommitteeSize field and the improved comment for BGTContractAddress enhance the clarity and functionality of the BeraChainSpec struct.

examples/berad/pkg/state-transition/state_processor_committee.go (1)

38-57: Refactor approved!

The refactoring of processSyncCommitteeUpdates to use an imperative approach enhances readability and maintainability. The logic for handling validators based on MaxCommitteeSize is clear and well-structured.

Consider verifying that the function's behavior aligns with the intended logic throughout the codebase.

Verification successful

To ensure the function processSyncCommitteeUpdates aligns with the intended logic throughout the codebase, let's examine how its output is used in the calling functions. This will help verify that the handling of validators based on MaxCommitteeSize is consistent.


Function Behavior Verified

The usage of processSyncCommitteeUpdates across the codebase consistently handles the logic for validators based on MaxCommitteeSize. The refactored function's behavior aligns with the intended logic, ensuring correct handling of validator updates.

  • Files Verified:
    • state_processor.go
    • state_processor_genesis.go
    • state_processor_committee.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `processSyncCommitteeUpdates` to ensure it aligns with the intended logic.

# Test: Search for the function usage. Expect: Consistent handling of validators based on `MaxCommitteeSize`.
rg --type go -A 5 $'processSyncCommitteeUpdates'

Length of output: 3777


Script:

#!/bin/bash
# Check the context around the usage of processSyncCommitteeUpdates in the calling functions
rg --type go -A 10 -B 5 'processSyncCommitteeUpdates'

Length of output: 7939

Copy link

codecov bot commented Aug 12, 2024

Codecov Report

Attention: Patch coverage is 0% with 29 lines in your changes missing coverage. Please review.

Project coverage is 21.87%. Comparing base (fcf588a) to head (239a1d8).

Files Patch % Lines
.../pkg/state-transition/state_processor_committee.go 0.00% 18 Missing ⚠️
...ples/berad/pkg/state-transition/state_processor.go 0.00% 8 Missing ⚠️
...ad/pkg/state-transition/state_processor_staking.go 0.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1886      +/-   ##
==========================================
- Coverage   21.89%   21.87%   -0.03%     
==========================================
  Files         338      338              
  Lines       15758    15777      +19     
  Branches       21       21              
==========================================
  Hits         3451     3451              
- Misses      12190    12209      +19     
  Partials      117      117              
Files Coverage Δ
...ad/pkg/state-transition/state_processor_staking.go 0.00% <0.00%> (ø)
...ples/berad/pkg/state-transition/state_processor.go 0.00% <0.00%> (ø)
.../pkg/state-transition/state_processor_committee.go 0.00% <0.00%> (ø)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between a5b1fa9 and 239a1d8.

Files selected for processing (1)
  • examples/berad/pkg/state-transition/state_processor_committee.go (2 hunks)
Additional comments not posted (1)
examples/berad/pkg/state-transition/state_processor_committee.go (1)

38-58: Improved readability and maintainability.

The refactoring to an imperative style enhances the clarity of the code. The explicit handling of the validator updates is straightforward and easy to follow.

However, ensure that MaxCommitteeSize is always less than or equal to the length of vals to avoid potential index out-of-bounds errors.

@ocnc ocnc enabled auto-merge (squash) August 12, 2024 19:30
@ocnc ocnc merged commit fca1aac into main Aug 12, 2024
18 checks passed
@ocnc ocnc deleted the val-updates-within-my-committee branch August 12, 2024 20:29
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.

2 participants