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

fix: module whitelist settings parse #572

Merged
merged 2 commits into from
Mar 13, 2024

Conversation

czarcas7ic
Copy link
Member

@czarcas7ic czarcas7ic commented Mar 13, 2024

Description

Closes: #XXXX

There is some really strange bug with appOpts.Get for string slices. I spent hours trying to figure out the root cause, but was unable to. Basically, it sets the result as an array of length 1, no mater how it is formated, along with adding an extra set of square brackets around the result.

So ["lockup"] becomes [lockup], ["lockup", "superfluid"] becomes [lockup superfluid], etc.

This just adds separate logic to get around this problem.

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an issue with module whitelist parsing in specific versions.
  • New Features

    • Enhanced server configuration with improved module whitelist handling.

Copy link

coderabbitai bot commented Mar 13, 2024

Walkthrough

This update enhances the server's configuration capabilities by improving module management. It introduces a new variable for whitelisting node modules in the default application options and adds a function to parse this whitelist from the application's options. These changes boost flexibility and security in module usage within the server environment.

Changes

File(s) Change Summary
server/util.go - Initialized fastNodeModuleWhitelist variable.
- Added ParseModuleWhitelist function.

🐇✨
In the realm of code, a rabbit hopped,
Bringing changes, not a single one flopped.
Modules whitelisted, with care,
Security and flexibility, beyond compare.
Hop, hop, hop, on the digital sod,
With each line of code, it nods.
🌟📦🔒

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-tests 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 tests 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 tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9345069 and 841924e.
Files selected for processing (1)
  • server/util.go (3 hunks)
Additional comments: 1
server/util.go (1)
  • 483-490: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [486-500]

The initialization of fastNodeModuleWhitelist using ParseModuleWhitelist(appOpts) and its subsequent use in baseapp.SetIAVLFastNodeModuleWhitelist(fastNodeModuleWhitelist) is a clear and direct approach to enhancing the module whitelist settings parsing mechanism. This change effectively integrates the new parsing logic into the existing configuration setup, ensuring that the whitelist settings are correctly applied to the IAVL fast node configuration.

Comment on lines +529 to +545
func ParseModuleWhitelist(appOpts types.AppOptions) []string {
var whitelist []string
if wl, ok := appOpts.Get(FlagIAVLFastNodeModuleWhitelist).([]string); ok {
// Trim the brackets from the string
trimmed := strings.Trim(wl[0], "[]")
// If the trimmed string is not empty, split it into a slice of strings
if trimmed != "" {
// Split the string into a slice of strings using space and comma as the separators
whitelist = strings.FieldsFunc(trimmed, func(c rune) bool {
return c == ' ' || c == ','
})
}
} else {
whitelist = cast.ToStringSlice(appOpts.Get(FlagIAVLFastNodeModuleWhitelist))
}
return whitelist
}
Copy link

Choose a reason for hiding this comment

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

The ParseModuleWhitelist function introduces a robust mechanism for parsing the module whitelist settings from AppOptions. It correctly handles both slice and string types for the FlagIAVLFastNodeModuleWhitelist option, ensuring flexibility in configuration. However, there are a few points to consider for refinement:

  1. Error Handling: The function lacks error handling or feedback mechanisms for cases where the parsing fails or the input format is unexpected. Adding error handling or logging could improve debuggability and user experience.
  2. Code Duplication: The trimming and splitting logic (lines 533-539) could be encapsulated into a helper function if similar parsing patterns are used elsewhere in the codebase, promoting code reuse and maintainability.
  3. Performance Consideration: While not critical for this specific use case, for larger lists or more frequent calls, optimizing the parsing logic (e.g., reducing string manipulations) could be beneficial.

Consider adding error handling or logging to provide feedback on parsing failures or unexpected input formats. Additionally, evaluate the potential for code reuse and performance optimizations in the parsing logic.

@czarcas7ic czarcas7ic merged commit cf09bb5 into osmo/v0.47.5 Mar 13, 2024
6 of 7 checks passed
@czarcas7ic czarcas7ic deleted the adam/fix-app-setting-parse branch March 13, 2024 23:08
mergify bot pushed a commit that referenced this pull request Mar 13, 2024
* fix how we parse module whitelist

* changelog update

(cherry picked from commit cf09bb5)

# Conflicts:
#	CHANGELOG.md
mergify bot pushed a commit that referenced this pull request Mar 13, 2024
* fix how we parse module whitelist

* changelog update

(cherry picked from commit cf09bb5)

# Conflicts:
#	CHANGELOG.md
Copy link

@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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 841924e and f2e8ed9.
Files selected for processing (1)
  • CHANGELOG.md (2 hunks)
Additional comments: 10
CHANGELOG.md (10)
  • 50-53: The entry for the fix in version v0.47.5-v23-osmo-5-iavl-v1 and v0.47.5-v23-osmo-4 regarding module whitelist parsing is clear and concise. However, it would be beneficial to include a brief description of how the parsing issue was resolved or what the impact of the fix is, to provide more context to the reader.
  • 47-56: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [98-98]

The version v0.47.5 entry mentions the addition of QueryEventForTxCmd command. It's good practice to briefly describe the purpose or functionality of new features for clarity. Consider adding a short description.

  • 47-56: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [106-106]

In the entry for version v0.47.5, the improvement regarding the MigrateHandler function could be enhanced by specifying the benefits or use cases of this addition, making it more informative for the reader.

  • 47-56: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [112-112]

The entry under version v0.47.5 about combining depinject-enabled and non-depinject-enabled modules in app v2 could be rephrased for clarity. Consider simplifying the language to make it more accessible to readers unfamiliar with these terms.

  • 47-56: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [115-115]

The entry mentioning the draft-proposal command under version v0.47.5 bug fixes could benefit from a brief explanation of the issue that was fixed, providing more context to the reader.

  • 47-56: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [160-160]

The entry for version v0.47.3 about adding a Close method to BaseApp is concise. However, mentioning the scenarios or benefits of using this method could enhance the reader's understanding.

  • 47-56: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [227-228]

The entry under version v0.47.5 about adding FormatInt and FormatDec functions in the math package is informative. It would be helpful to include examples of how these functions can be used, to illustrate their utility.

  • 47-56: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [240-240]

The entry discussing the creation of the x/consensus module in version v0.47.5 is significant. Expanding on how this change affects developers or the migration process from x/params would provide valuable insights.

  • 47-56: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [266-266]

In the entry for version v0.47.5-v23-osmo-5-iavl-v1, the mention of adding iavl-lazy-loading configuration could be enhanced by briefly explaining the performance implications or scenarios where this feature is particularly beneficial.

  • 47-56: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [429-429]

The entry under version v0.47.5 about fixing snapshot checksum issues in Golang 1.19 is crucial. Providing a bit more detail on the nature of the checksum issue and its impact could help readers understand the importance of this fix.

czarcas7ic added a commit that referenced this pull request Mar 13, 2024
* fix: module whitelist settings parse (#572)

* fix how we parse module whitelist

* changelog update

(cherry picked from commit cf09bb5)

# Conflicts:
#	CHANGELOG.md

* merge conflict

---------

Co-authored-by: Adam Tucker <[email protected]>
Co-authored-by: Adam Tucker <[email protected]>
czarcas7ic added a commit that referenced this pull request Mar 13, 2024
* fix: module whitelist settings parse (#572)

* fix how we parse module whitelist

* changelog update

(cherry picked from commit cf09bb5)

# Conflicts:
#	CHANGELOG.md

* merge conflict

---------

Co-authored-by: Adam Tucker <[email protected]>
Co-authored-by: Adam Tucker <[email protected]>
czarcas7ic added a commit that referenced this pull request May 9, 2024
* fix how we parse module whitelist

* changelog update
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.

1 participant