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

refactor(v2): proper iavl v2 config #23463

Merged
merged 3 commits into from
Jan 20, 2025
Merged

refactor(v2): proper iavl v2 config #23463

merged 3 commits into from
Jan 20, 2025

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Jan 20, 2025

Description

server/v2 config tests were failing and the iavl v2 config didn't have the store/v2 wrapper for the proper comments in the toml.


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, you can find examples of the prefixes below:
  • confirmed ! in 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
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • 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.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

Release Notes

  • Configuration Updates

    • Increased IAVL tree cache size
    • Added new configuration options for IAVL v2 tree management
  • Dependency Management

    • Updated Go module dependencies
    • Added new indirect dependencies
    • Removed some existing dependencies
  • Technical Improvements

    • Enhanced configuration handling for IAVL tree initialization
    • Introduced more flexible tree configuration options

These changes improve system performance and provide more granular control over tree storage and caching mechanisms.

@julienrbrt julienrbrt requested a review from a team as a code owner January 20, 2025 09:57
Copy link
Contributor

coderabbitai bot commented Jan 20, 2025

Warning

Rate limit exceeded

@julienrbrt has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 19 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 58caa95 and ddb0b77.

📒 Files selected for processing (3)
  • simapp/v2/app.go (1 hunks)
  • store/v2/commitment/iavlv2/config.go (1 hunks)
  • store/v2/commitment/iavlv2/tree.go (2 hunks)
📝 Walkthrough

Walkthrough

This pull request introduces significant changes to the IAVL (Immutable AVL) tree configuration and dependency management. The modifications primarily focus on enhancing the IAVL v2 configuration by introducing a new Config struct in the store/v2/commitment/iavlv2/config.go file. The changes include updating the go.mod file with new dependencies, modifying the app.toml configuration, and adjusting how tree options are passed to the NewTree function. These updates provide more granular control over the IAVL tree's behavior and improve dependency management.

Changes

File Change Summary
server/v2/go.mod - Uncommented local replace directives
- Added indirect dependencies: uniplot, go-sqlite-lite, iavl/v2, go-humanize, costor-api
- Removed indirect dependency: grocksdb
server/v2/testdata/app.toml - Increased cache-size from 100000 to 500000
- Added new [store.options.iavl-v2-config] section with multiple parameters
store/v2/commitment/iavlv2/config.go - Introduced new Config struct
- Added ToTreeOptions() method
- Created DefaultConfig() function
store/v2/commitment/iavlv2/tree.go - Modified NewTree() function signature to use Config instead of iavl.TreeOptions
store/v2/commitment/iavlv2/tree_test.go - Updated tree initialization to use DefaultConfig()
store/v2/root/factory.go - Changed IavlV2Config field type from iavl_v2.TreeOptions to iavlv2.Config

Sequence Diagram

sequenceDiagram
    participant Config as IAVL V2 Config
    participant Tree as IAVL Tree
    participant DB as Database

    Config->>Config: DefaultConfig()
    Config->>Config: ToTreeOptions()
    Config->>Tree: NewTree(cfg, dbOptions, logger)
    Tree->>DB: Initialize with options
    DB-->>Tree: Return tree instance
Loading

Possibly related PRs

Suggested labels

C:Store, C:server/v2, C:x/accounts, C:collections, C:server/v2 cometbft

Suggested reviewers

  • kocubinski
  • sontrinh16
  • tac0turtle
  • cool-develope

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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.

@github-actions github-actions bot added C:Store C:server/v2 Issues related to server/v2 labels Jan 20, 2025
@julienrbrt julienrbrt requested review from alpe and tac0turtle January 20, 2025 09:57
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

🧹 Nitpick comments (3)
store/v2/commitment/iavlv2/config.go (1)

21-32: Consider adding validation in ToTreeOptions.

While the conversion logic is correct, consider adding validation for critical fields like:

  • Non-negative values for intervals and memory
  • Valid range for ratios (0.0 to 1.0)
  • Minimum values for version keeping
 func (c *Config) ToTreeOptions() iavl.TreeOptions {
+    if c.CheckpointInterval < 0 {
+        panic("checkpoint interval must be non-negative")
+    }
+    if c.PruneRatio < 0.0 || c.PruneRatio > 1.0 {
+        panic("prune ratio must be between 0.0 and 1.0")
+    }
+    if c.MinimumKeepVersions < 1 {
+        panic("minimum keep versions must be at least 1")
+    }
     return iavl.TreeOptions{
         CheckpointInterval:  c.CheckpointInterval,
         CheckpointMemory:    c.CheckpointMemory,
store/v2/commitment/iavlv2/tree.go (1)

Line range hint 169-178: Consider deprecating DefaultOptions function.

With the introduction of the new Config structure and DefaultConfig() function, this function appears to be redundant and could cause confusion.

+// Deprecated: Use DefaultConfig() instead.
 func DefaultOptions(keepVersions int64) iavl.TreeOptions {
     opts := iavl.DefaultTreeOptions()
     opts.MinimumKeepVersions = keepVersions
store/v2/root/factory.go (1)

40-40: Initialize IavlV2Config in DefaultStoreOptions.

While the field type change is correct, consider initializing IavlV2Config in DefaultStoreOptions to provide default values when IAVL v2 is selected.

 func DefaultStoreOptions() Options {
     return Options{
         SCType: SCTypeIavl,
         SCPruningOption: &store.PruningOption{
             KeepRecent: 2,
             Interval:   100,
         },
         IavlConfig: &iavl.Config{
             CacheSize:              500_000,
             SkipFastStorageUpgrade: true,
         },
+        IavlV2Config: iavlv2.DefaultConfig(),
     }
 }
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f9bb180 and 58caa95.

⛔ Files ignored due to path filters (1)
  • server/v2/go.sum is excluded by !**/*.sum
📒 Files selected for processing (6)
  • server/v2/go.mod (4 hunks)
  • server/v2/testdata/app.toml (1 hunks)
  • store/v2/commitment/iavlv2/config.go (1 hunks)
  • store/v2/commitment/iavlv2/tree.go (2 hunks)
  • store/v2/commitment/iavlv2/tree_test.go (1 hunks)
  • store/v2/root/factory.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
store/v2/commitment/iavlv2/tree_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

store/v2/root/factory.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

store/v2/commitment/iavlv2/tree.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

store/v2/commitment/iavlv2/config.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: tests (03)
  • GitHub Check: tests (00)
  • GitHub Check: test-integration
  • GitHub Check: Analyze
  • GitHub Check: Summary
🔇 Additional comments (8)
store/v2/commitment/iavlv2/tree_test.go (1)

28-28: LGTM! Consistent usage of the new configuration structure.

The change correctly uses the new DefaultConfig() function instead of the deprecated DefaultTreeOptions(), maintaining consistency with the new configuration approach.

store/v2/commitment/iavlv2/config.go (2)

9-18: Well-structured configuration with clear documentation.

The Config struct is well-designed with:

  • Appropriate types for each field
  • Consistent struct tags for mapstructure and toml
  • Clear comments explaining each field's purpose

34-48: LGTM! Proper initialization of default configuration.

The function correctly initializes all fields from the default tree options.

store/v2/commitment/iavlv2/tree.go (1)

Line range hint 28-38: LGTM! Clean transition to new configuration structure.

The function signature change from treeOptions to cfg is well-implemented, using the new configuration structure correctly.

server/v2/testdata/app.toml (2)

40-43: Verify memory requirements for increased cache size.

The cache size has been increased significantly from 100000 to 500000. While this might improve performance, it could also substantially increase memory usage.

Please confirm:

  1. Memory requirements have been calculated
  2. Target environments can handle the increased memory load
  3. Performance benefits justify the increased memory usage

44-58: Document recommended values for IAVL v2 configuration parameters.

All parameters in the new IAVL v2 configuration section are initialized to 0 or false, which might not be optimal for production use.

Please provide documentation for:

  1. Recommended values for different deployment scenarios
  2. Impact of each parameter on performance and storage
  3. Guidelines for tuning these parameters:
    • checkpoint-interval
    • checkpoint-memory
    • state-storage
    • height-filter
    • eviction-depth
    • prune-ratio
    • minimum-keep-versions
server/v2/go.mod (2)

60-60: Review stability of IAVL v2 alpha dependency.

Using an alpha version (v2.0.0-alpha.4) of github.com/cosmos/iavl/v2 in production could lead to stability issues.

Please confirm:

  1. This alpha version has been thoroughly tested
  2. There are no known breaking changes planned
  3. There's a plan to upgrade to the stable version when available

6-9: Remove development-only replace directives before deployment.

The uncommented replace directives are meant for development only and should not be used in production.

Ensure these replace directives are commented out before releasing:

-replace (
-	cosmossdk.io/server/v2/appmanager => ./appmanager
-	cosmossdk.io/store/v2 => ../../store/v2
-)
✅ Verification successful

Remove development-only replace directives before deployment.

The review comment is correct. The replace directives in server/v2/go.mod are explicitly marked as development-only with the comment "// server v2 integration (uncomment during development, but comment before release)". These directives should be commented out before deployment to production.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Check for documentation about replace directives
fd README.md | xargs rg -i "replace|development" -A 2 -B 2

# Find all go.mod files and check their replace directives
fd go.mod | xargs rg "^replace" -A 3 -B 1

# Verify if the referenced paths exist
fd -t d appmanager
fd -t d "store/v2"

Length of output: 15997


Script:

#!/bin/bash
# Search for deployment or production-related documentation
fd -e md | xargs rg -i "production|deploy" -A 2 -B 2

# Check if there are any specific docs about server/v2
fd -e md | xargs rg "server/v2|appmanager" -A 2 -B 2

Length of output: 44419

server/v2/go.mod Show resolved Hide resolved
@julienrbrt julienrbrt added this pull request to the merge queue Jan 20, 2025
Merged via the queue into main with commit 0440a13 Jan 20, 2025
72 of 73 checks passed
@julienrbrt julienrbrt deleted the julien/fix-iavlv2-cfg branch January 20, 2025 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:server/v2 Issues related to server/v2 C:Store
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants