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

chore(store): Disallow removing from validator registry to return all correctly #1805

Merged
merged 4 commits into from
Jul 29, 2024

Conversation

calbera
Copy link
Contributor

@calbera calbera commented Jul 29, 2024

Enforces the invariant that iterating in order over the validators indexed map for GetValidators returns a slice where the index of validator corresponds to validator's ValidatorIndex

Summary by CodeRabbit

  • New Features

    • Enhanced validator retrieval process, ensuring correct order and gap handling in the list of validators.
  • Bug Fixes

    • Improved memory allocation efficiency when retrieving validators, preventing potential performance issues.
  • Refactor

    • Streamlined the validator management interface by removing the RemoveValidatorAtIndex method, improving usability and reducing complexity.

Copy link
Contributor

coderabbitai bot commented Jul 29, 2024

Walkthrough

The changes improve the GetValidators function in the beacondb package, optimizing how validators are retrieved from a key-value store. By predefining the size of the vals slice and managing gaps in indices, the implementation increases efficiency and ensures the correct order of validators. Additionally, the removal of the RemoveValidatorAtIndex method from multiple interfaces reflects a streamlined approach to validator management, simplifying the codebase.

Changes

Files Change Summary
mod/storage/pkg/beacondb/registry.go Enhanced GetValidators function to predefine slice size and fill index gaps efficiently.
mod/node-core/pkg/components/storage/types.go Removed RemoveValidatorAtIndex method from KVStore interface, simplifying validator management.
mod/state-transition/pkg/core/interfaces.go Eliminated RemoveValidatorAtIndex from WriteOnlyBeaconState interface, streamlining state management.
mod/state-transition/pkg/core/state/interfaces.go Removed RemoveValidatorAtIndex from KVStore interface, promoting a more immutable approach to validators.

Poem

In the fields where validators play,
A rabbit hops, brightening the day.
With gaps now filled and slices right,
Memory dances in pure delight!
So here’s to the code, refined and neat,
A joyful tune, a coding feat! 🐇✨


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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 7320ce8 and dadf4ae.

Files selected for processing (1)
  • mod/storage/pkg/beacondb/registry.go (2 hunks)
Additional comments not posted (2)
mod/storage/pkg/beacondb/registry.go (2)

167-170: Consider edge cases for filling empty values.

The loop fills in empty values to maintain the order of the registry. Ensure that keyval.Key is always greater than or equal to index to avoid potential panics.

-		for j := index; j < keyval.Key; j++ {
+		if keyval.Key >= index {
+			for j := index; j < keyval.Key; j++ {
+				vals[j] = emptyVal
+			}
+		}

172-176: Ensure that the index is within bounds.

The index is incremented and used to access the vals slice. Ensure that the index does not exceed the slice bounds to avoid potential panics.

-		vals[keyval.Key] = keyval.Value
+		if keyval.Key < uint64(len(vals)) {
+			vals[keyval.Key] = keyval.Value
+		} else {
+			return nil, fmt.Errorf("index out of bounds: %d", keyval.Key)
+		}

mod/storage/pkg/beacondb/registry.go Outdated Show resolved Hide resolved
mod/storage/pkg/beacondb/registry.go Outdated Show resolved Hide resolved
mod/storage/pkg/beacondb/registry.go Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jul 29, 2024

Codecov Report

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

Project coverage is 25.46%. Comparing base (7320ce8) to head (2152e04).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1805      +/-   ##
==========================================
- Coverage   25.47%   25.46%   -0.01%     
==========================================
  Files         329      329              
  Lines       14612    14616       +4     
  Branches       21       21              
==========================================
  Hits         3722     3722              
- Misses      10760    10764       +4     
  Partials      130      130              
Files Coverage Δ
mod/storage/pkg/beacondb/registry.go 0.00% <0.00%> (ø)

@calbera calbera changed the title fix(store): Return correct validator registry for index chore(store): Disallow removing from validator registry to return all correctly Jul 29, 2024
@calbera calbera requested a review from archbear July 29, 2024 18:25
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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between dadf4ae and 2152e04.

Files selected for processing (4)
  • mod/node-core/pkg/components/storage/types.go (1 hunks)
  • mod/state-transition/pkg/core/interfaces.go (1 hunks)
  • mod/state-transition/pkg/core/state/interfaces.go (1 hunks)
  • mod/storage/pkg/beacondb/registry.go (3 hunks)
Additional comments not posted (32)
mod/node-core/pkg/components/storage/types.go (32)

Line range hint 63-63:
LGTM!

The Context method is straightforward and does not require any changes.


Line range hint 65-67:
LGTM!

The WithContext method is straightforward and does not require any changes.


Line range hint 69-69:
LGTM!

The Save method is straightforward and does not require any changes.


Line range hint 71-71:
LGTM!

The Copy method is straightforward and does not require any changes.


Line range hint 73-75:
LGTM!

The GetLatestExecutionPayloadHeader method is straightforward and does not require any changes.


Line range hint 77-79:
LGTM!

The SetLatestExecutionPayloadHeader method is straightforward and does not require any changes.


Line range hint 81-81:
LGTM!

The GetEth1DepositIndex method is straightforward and does not require any changes.


Line range hint 83-85:
LGTM!

The SetEth1DepositIndex method is straightforward and does not require any changes.


Line range hint 87-87:
LGTM!

The GetBalance method is straightforward and does not require any changes.


Line range hint 89-91:
LGTM!

The SetBalance method is straightforward and does not require any changes.


Line range hint 93-93:
LGTM!

The GetSlot method is straightforward and does not require any changes.


Line range hint 95-97:
LGTM!

The SetSlot method is straightforward and does not require any changes.


Line range hint 99-99:
LGTM!

The GetFork method is straightforward and does not require any changes.


Line range hint 101-103:
LGTM!

The SetFork method is straightforward and does not require any changes.


Line range hint 105-105:
LGTM!

The GetGenesisValidatorsRoot method is straightforward and does not require any changes.


Line range hint 107-109:
LGTM!

The SetGenesisValidatorsRoot method is straightforward and does not require any changes.


Line range hint 111-111:
LGTM!

The GetLatestBlockHeader method is straightforward and does not require any changes.


Line range hint 113-115:
LGTM!

The SetLatestBlockHeader method is straightforward and does not require any changes.


Line range hint 117-117:
LGTM!

The GetBlockRootAtIndex method is straightforward and does not require any changes.


Line range hint 119-121:
LGTM!

The StateRootAtIndex method is straightforward and does not require any changes.


Line range hint 123-123:
LGTM!

The GetEth1Data method is straightforward and does not require any changes.


Line range hint 125-127:
LGTM!

The SetEth1Data method is straightforward and does not require any changes.


Line range hint 129-129:
LGTM!

The GetValidators method is straightforward and does not require any changes.


Line range hint 131-131:
LGTM!

The GetBalances method is straightforward and does not require any changes.


Line range hint 133-133:
LGTM!

The GetNextWithdrawalIndex method is straightforward and does not require any changes.


Line range hint 135-137:
LGTM!

The SetNextWithdrawalIndex method is straightforward and does not require any changes.


Line range hint 139-139:
LGTM!

The GetNextWithdrawalValidatorIndex method is straightforward and does not require any changes.


Line range hint 141-143:
LGTM!

The SetNextWithdrawalValidatorIndex method is straightforward and does not require any changes.


Line range hint 145-145:
LGTM!

The GetTotalSlashing method is straightforward and does not require any changes.


Line range hint 147-149:
LGTM!

The SetTotalSlashing method is straightforward and does not require any changes.


Line range hint 151-151:
LGTM!

The GetRandaoMixAtIndex method is straightforward and does not require any changes.


Line range hint 62-62:
Review the removal of RemoveValidatorAtIndex method.

The removal of RemoveValidatorAtIndex from the KVStore interface suggests a shift in how validators are managed. Ensure that the functionality previously provided by this method is now handled elsewhere in the codebase.

Verification successful

Removal of RemoveValidatorAtIndex method successfully verified.

The RemoveValidatorAtIndex method has been completely removed from the codebase, and no lingering references were found. This confirms that the functionality previously provided by this method is now handled elsewhere or is no longer needed.

  • No occurrences of RemoveValidatorAtIndex were found in the codebase.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `RemoveValidatorAtIndex` in the codebase.

# Test: Search for the function usage. Expect: No occurrences of the removed method.
rg --type go -A 5 $'RemoveValidatorAtIndex'

Length of output: 42


Script:

#!/bin/bash
# Description: Verify the usage of `RemoveValidatorAtIndex` across the entire codebase.

# Test: Search for any references to `RemoveValidatorAtIndex`. Expect: No occurrences of the removed method.
rg 'RemoveValidatorAtIndex'

Length of output: 27

mod/storage/pkg/beacondb/registry.go Show resolved Hide resolved
mod/storage/pkg/beacondb/registry.go Show resolved Hide resolved
mod/storage/pkg/beacondb/registry.go Show resolved Hide resolved
@calbera calbera merged commit d3ea54b into main Jul 29, 2024
18 checks passed
@calbera calbera deleted the fix-val-registry branch July 29, 2024 18:40
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