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(sidecar): add parsing validator indexes as ranges #119

Merged
merged 1 commit into from
Jul 5, 2024

Conversation

merklefruit
Copy link
Collaborator

@merklefruit merklefruit commented Jul 5, 2024

This PR adds the ability to parse validator index ranges from an array of comma-separated ranges.
ValidatorIndex also becomes a separate struct to allow for future parsing methods too, including from a keystore directory which would be handy for validators

example of valid values:

--validator-indexes 1,2,3,4,5
--validator-indexes 1..3,5..7
--validator-indexes 1,2,3,67..97,194,529..541

Copy link
Contributor

coderabbitai bot commented Jul 5, 2024

Walkthrough

The update introduces a new ValidatorIndexes type that replaces the use of Vec<u64> for managing validator indexes. This change promotes better encapsulation and functionality directly relevant to validator indexes, simplifying management and validation. Areas affected include configuration loading, the ConsensusState instantiation, and related method implementations, enhancing consistency and future maintenance.

Changes

File Change Summary
bolt-sidecar/bin/sidecar.rs Modified parameter passing to ConsensusState::new from a reference to a cloned value of config.validator_indexes.
bolt-sidecar/src/config/mod.rs Added validator_indexes module and ValidatorIndexes struct, updated Opts struct to use ValidatorIndexes.
bolt-sidecar/src/config/validator_indexes.rs Introduced ValidatorIndexes struct, methods for checking index containment, parsing from string representations, and test functions.
bolt-sidecar/src/state/consensus.rs Updated ConsensusState to use ValidatorIndexes for validator indexes, including the constructor and related logic adjustments.

The changes collectively transition the handling of validator indexes from a simple vector to a more structured and functional type, ValidatorIndexes, fostering a more robust and maintainable codebase.


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>.
    • 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 Configration 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.

@merklefruit merklefruit changed the title chore: add parsing validator indexes as ranges chore(sidecar): add parsing validator indexes as ranges Jul 5, 2024
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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between e3e93d0 and 7c6d7aa.

Files selected for processing (4)
  • bolt-sidecar/bin/sidecar.rs (1 hunks)
  • bolt-sidecar/src/config/mod.rs (5 hunks)
  • bolt-sidecar/src/config/validator_indexes.rs (1 hunks)
  • bolt-sidecar/src/state/consensus.rs (5 hunks)
Additional comments not posted (9)
bolt-sidecar/src/config/validator_indexes.rs (3)

6-9: LGTM! The contains method is correctly implemented.

The method correctly checks if a given index is in the internal Vec<u64>.


47-50: LGTM! The from method is correctly implemented.

The method correctly converts a Vec<u64> into a ValidatorIndexes object.


53-71: LGTM! The test module is well-implemented.

The tests cover different input formats and validate the correctness of the from_str method.

bolt-sidecar/bin/sidecar.rs (1)

39-43: LGTM! The updated function call to ConsensusState::new is correct.

The change correctly matches the updated function signature.

bolt-sidecar/src/state/consensus.rs (3)

62-68: LGTM! The updated new function is correct.

The change correctly matches the updated ConsensusState struct.


150-151: LGTM! The updated find_validator_index_for_slot method is correct.

The change correctly uses the new contains method of ValidatorIndexes.


185-185: LGTM! The updated test for find_validator_index_for_slot is correct.

The change correctly matches the updated ConsensusState struct.

bolt-sidecar/src/config/mod.rs (2)

Line range hint 10-55:
LGTM! The updated Opts struct is correct.

The change correctly matches the updated ValidatorIndexes type.


Line range hint 104-128:
LGTM! The updated Config struct is correct.

The change correctly matches the updated ValidatorIndexes type.

Comment on lines +12 to +44
impl FromStr for ValidatorIndexes {
type Err = eyre::Report;

/// Parse an array of validator indexes. Accepted values:
/// - a comma-separated list of indexes (e.g. "1,2,3,4")
/// - a contiguous range of indexes (e.g. "1..4")
/// - a mix of the above (e.g. "1,2..4,6..8")
///
/// TODO: add parsing from a directory path, using the format of
/// validator definitions
fn from_str(s: &str) -> Result<Self, Self::Err> {
let s = s.trim();
let mut vec = Vec::new();

for comma_separated_part in s.split(',') {
if comma_separated_part.contains("..") {
let mut parts = comma_separated_part.split("..");

let start = parts.next().ok_or_else(|| eyre::eyre!("Invalid range"))?;
let start = start.parse::<u64>()?;

let end = parts.next().ok_or_else(|| eyre::eyre!("Invalid range"))?;
let end = end.parse::<u64>()?;

vec.extend(start..=end);
} else {
let index = comma_separated_part.parse::<u64>()?;
vec.push(index);
}
}

Ok(Self(vec))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM! The from_str method is correctly implemented.

The method correctly handles different input formats and uses appropriate error handling.

Reminder: Add support for parsing from a directory path.

The TODO comment indicates a missing feature.

Do you want me to implement the parsing from a directory path or open a GitHub issue to track this task?

Copy link
Contributor

@namn-grg namn-grg left a comment

Choose a reason for hiding this comment

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

LGTM

@merklefruit merklefruit merged commit ec65059 into unstable Jul 5, 2024
@merklefruit merklefruit deleted the chore/val-indexes branch July 5, 2024 10:23
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