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: prune cmd should disable async pruning #22656

Merged
merged 7 commits into from
Dec 4, 2024
Merged

Conversation

yihuang
Copy link
Collaborator

@yihuang yihuang commented Nov 26, 2024

Description

When async pruning enabled, prune cmd should wait for prune process to finish.


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

  • New Features

    • Support for simulating nested messages in the base application.
    • New Linux-only backend for the crypto/keyring module.
    • Enhanced ability to import hex keys via standard input in the client/keys module.
    • New command for synchronous pruning in the CLI module.
    • Configuration option for IAVL sync pruning in the server.
    • Added method for setting IAVL sync pruning in the CommitMultiStore interface.
  • Improvements

    • Removed redundant context in integration tests.
    • Enhanced configurability of the IAVL store with new pruning options.
  • Bug Fixes

    • Fixed issue with skipping simulation tests on validators.
    • Corrected address query in the CLI module.
    • Ensured pruning command disables asynchronous pruning.
  • Documentation

    • Updated changelog format for better readability and versioning clarity.

Copy link
Contributor

coderabbitai bot commented Nov 26, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces several updates across multiple modules, including new features such as nested message support, a Linux-only backend for the crypto/keyring module, and enhancements for importing hex keys. It also includes improvements like removing redundant contexts in tests and bug fixes related to simulation tests and CLI queries. Additionally, new methods for resource management have been added to the Store structs, enhancing error handling and cleanup processes. The changelog format has been refined to improve clarity and versioning.

Changes

File Change Summary
CHANGELOG.md Updates include new features, improvements, bug fixes, and breaking changes with refined formatting.
client/pruning/main.go Enhanced error handling in the Cmd function and ensured proper closure of the rootMultiStore.
store/iavl/store.go Added LoadStoreWithOpts function for flexible IAVL store loading and updated related methods.
store/rootmulti/store.go Introduced iavlSyncPruning field and SetIAVLSyncPruning method for pruning configuration.
baseapp/options.go Added SetIAVLSyncPruning function for configuring pruning options in the base application.
server/start.go Introduced FlagIAVLSyncPruning constant for server configuration related to IAVL pruning.
server/util.go Updated DefaultBaseappOptions to include IAVL sync pruning configuration.
store/types/store.go Added SetIAVLSyncPruning method to CommitMultiStore interface for managing IAVL pruning.
server/mock/store.go Added SetIAVLSyncPruning method to multiStore struct with a panic statement for unimplemented functionality.

Possibly related PRs

Suggested labels

backport/v0.52.x

Suggested reviewers

  • tac0turtle
  • sontrinh16
  • kocubinski
  • julienrbrt
  • akhilkumarpilli

📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4b8c9af and 8514dd4.

📒 Files selected for processing (1)
  • client/pruning/main.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • client/pruning/main.go

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

CHANGELOG.md Outdated Show resolved Hide resolved
store/rootmulti/store.go Fixed Show fixed Hide fixed
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

🧹 Outside diff range and nitpick comments (4)
store/rootmulti/store.go (1)

1173-1181: LGTM! Consider improving error handling.

The Close method implementation is well-structured with proper resource cleanup. However, it might be beneficial to log errors when they occur, as some errors might be silently combined.

Consider adding error logging:

 func (rs *Store) Close() error {
     errs := make([]error, 0, len(rs.stores))
     for _, store := range rs.stores {
         if closer, ok := store.(io.Closer); ok {
-            errs = append(errs, closer.Close())
+            if err := closer.Close(); err != nil {
+                rs.logger.Error("failed to close store", "err", err)
+                errs = append(errs, err)
+            }
         }
     }
     return errors.Join(errs...)
 }
🧰 Tools
🪛 GitHub Check: CodeQL

[warning] 1175-1179: Iteration over map
Iteration over map may be a possible source of non-determinism

CHANGELOG.md (3)

Line range hint 1-1: Add title to changelog file

The changelog file should start with a clear title like "# Changelog" to follow standard markdown documentation practices.

+ # Changelog

Line range hint 13-15: Improve version header formatting

The version headers should follow a consistent format with release date. Consider using H2 (##) headers for versions.

- ## [v0.47.16](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.16) - 2024-09-20
+ ## v0.47.16 (2024-09-20)
+ 
+ [Release Link](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.16)

Line range hint 2558-2558: Add footer section

The changelog should have a footer section with links to related resources and contribution guidelines.

+ ## Additional Resources
+ 
+ - [Contributing Guidelines](CONTRIBUTING.md)
+ - [Release Process](RELEASE_PROCESS.md)
+ - [Security Policy](SECURITY.md)
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 14d98d2 and dbf6912.

📒 Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • client/pruning/main.go (1 hunks)
  • store/iavl/store.go (1 hunks)
  • store/rootmulti/store.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

client/pruning/main.go (1)

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

store/iavl/store.go (1)

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

store/rootmulti/store.go (1)

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

🪛 GitHub Check: CodeQL
store/rootmulti/store.go

[warning] 1175-1179: Iteration over map
Iteration over map may be a possible source of non-determinism

🔇 Additional comments (3)
client/pruning/main.go (1)

92-94: LGTM! Improved error handling pattern

The simplified error handling follows Go's idiomatic patterns and improves code readability.

store/iavl/store.go (1)

407-412: LGTM! Clean implementation of resource cleanup.

The Close method follows Go's best practices for resource cleanup:

  • Safely handles cases where the tree doesn't implement io.Closer
  • Properly propagates errors from the underlying Close operation

Let's verify the usage of this Close method across the codebase:

✅ Verification successful

Let me analyze the usage of Close() method in the codebase to verify if there are any potential resource leaks.


Let me check if there are any other Store implementations that might require cleanup.


Based on the analysis of the codebase, I can now provide a final assessment of the Close() method implementation.

Implementation is correct and follows best practices

The Close() method implementation in store/iavl/store.go is properly designed:

  • It correctly implements the io.Closer interface by checking if the underlying tree implements io.Closer
  • The type assertion pattern closer, ok := st.tree.(io.Closer) is the idiomatic way to handle optional interface implementations
  • The method properly propagates any errors from the underlying Close operation
  • The implementation is consistent with other Store implementations in the codebase that require cleanup

The verification shows that:

  1. The Store struct is used in contexts where proper cleanup is needed (e.g., database connections)
  2. The Close method is called in appropriate places, particularly in cleanup paths
  3. The pattern of checking for io.Closer implementation is used consistently across the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for proper cleanup of Store instances
# Look for patterns where Store is used but Close is not called

# Search for Store instantiations
rg "NewStore|LoadStore|UnsafeNewStore" -A 5

# Search for defer Store.Close() patterns
rg "defer.*Close\(\)"

Length of output: 99577


Script:

#!/bin/bash
# Search for Store struct implementations that embed io.Closer
ast-grep --pattern 'type Store struct {
  $$$
  io.Closer
  $$$
}'

# Search for Store struct implementations that have Close method
ast-grep --pattern 'func ($x *Store) Close() $_ {
  $$$
}'

# Search for direct usage of Store.Close()
rg "store\.Close\(\)" -A 2

Length of output: 277


Script:

#!/bin/bash
# Search for any Store interface definitions that might require Close
ast-grep --pattern 'type $x interface {
  $$$
  Close() $_
  $$$
}'

# Search for any Store implementations that might require Close
rg "type.*Store.*interface" -A 10

# Look for any Close method implementations in store package
rg "func.*Close" store/

Length of output: 51300

store/rootmulti/store.go (1)

1175-1179: Non-deterministic map iteration is acceptable here.

The static analysis warning about non-deterministic map iteration can be safely ignored in this context because:

  1. All stores need to be closed regardless of order
  2. The order of error collection doesn't affect the functionality
  3. If deterministic error reporting becomes necessary, the existing keysFromStoreKeyMap helper function can be utilized
🧰 Tools
🪛 GitHub Check: CodeQL

[warning] 1175-1179: Iteration over map
Iteration over map may be a possible source of non-determinism

client/pruning/main.go Outdated Show resolved Hide resolved
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

🧹 Outside diff range and nitpick comments (7)
client/pruning/main.go (1)

92-98: Consider using defer for cleanup

To ensure cleanup happens even if pruning fails, consider using defer:

+       defer func() {
+           if closeErr := rootMultiStore.Close(); closeErr != nil {
+               if err == nil {
+                   err = closeErr
+               } else {
+                   // Log the close error if we already have a pruning error
+                   logger.Error("failed to close store", "error", closeErr)
+               }
+           }
+       }()
        if err := rootMultiStore.PruneStores(pruningHeight); err != nil {
            return err
        }
-       // close will wait for async pruning process to finish
-       if err := rootMultiStore.Close(); err != nil {
-           return err
-       }
store/iavl/store.go (1)

407-412: LGTM! Clean implementation of io.Closer

The implementation correctly handles resource cleanup by delegating to the underlying tree's Close method when available.

Consider adding a doc comment explaining the purpose:

+// Close implements io.Closer interface. It closes the underlying tree if it implements io.Closer,
+// otherwise returns nil. This ensures proper cleanup of resources, particularly after async operations.
 func (st *Store) Close() error {
store/rootmulti/store.go (1)

1173-1181: LGTM! Consider adding error logging.

The Close() implementation correctly handles resource cleanup by closing all stores that implement io.Closer. The use of errors.Join for combining multiple errors is a good practice.

Consider logging individual errors before joining them, to help with debugging:

 func (rs *Store) Close() error {
     errs := make([]error, 0, len(rs.stores))
     for _, store := range rs.stores {
         if closer, ok := store.(io.Closer); ok {
-            errs = append(errs, closer.Close())
+            if err := closer.Close(); err != nil {
+                rs.logger.Error("failed to close store", "err", err)
+                errs = append(errs, err)
+            }
         }
     }
     return errors.Join(errs...)
 }
🧰 Tools
🪛 GitHub Check: CodeQL

[warning] 1175-1179: Iteration over map
Iteration over map may be a possible source of non-determinism

CHANGELOG.md (4)

Line range hint 1-1: Add version table of contents for easier navigation

Consider adding a table of contents at the start of the changelog listing all versions with links for easier navigation through this extensive document.


Line range hint 785-785: Improve formatting consistency in breaking changes section

The breaking changes section uses inconsistent bullet point styles (sometimes * and sometimes -). Standardize on a single bullet point style throughout the document for better readability.


Line range hint 1452-1452: Fix typo in changelog entry

"Typographical" is misspelled as "Typograhical" in the list of review areas.


Line range hint 2345-2345: Add missing version release date

The release date for v0.44.0 is listed as "2021-XX-XX". This should be updated with the actual release date.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 14d98d2 and dbf6912.

📒 Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • client/pruning/main.go (1 hunks)
  • store/iavl/store.go (1 hunks)
  • store/rootmulti/store.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

client/pruning/main.go (1)

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

store/iavl/store.go (1)

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

store/rootmulti/store.go (1)

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

🪛 GitHub Check: CodeQL
store/rootmulti/store.go

[warning] 1175-1179: Iteration over map
Iteration over map may be a possible source of non-determinism

🔇 Additional comments (4)
client/pruning/main.go (2)

92-94: LGTM: Clean error handling pattern

The simplified error handling follows Go's idiomatic patterns and improves code readability.


96-98: LGTM: Proper cleanup with async handling

The addition of Close() ensures that async pruning operations complete before the command exits, addressing the core objective of this PR.

store/iavl/store.go (1)

407-412: Verify integration with pruning operations

Since this PR aims to fix pruning command waiting for async pruning, let's verify the integration.

✅ Verification successful

Let me analyze the pruning-related code to verify the integration with the Close method.


Let me check how the pruning manager interacts with the store.


Store Close implementation is correctly integrated with pruning operations

The Close method in store/iavl/store.go is properly integrated with pruning operations for the following reasons:

  1. The pruning manager operates independently of the store's Close method, using a separate pruner interface for both state commitment (SC) and state storage (SS).
  2. The Close method correctly handles cleanup by:
    • Checking if the underlying tree implements io.Closer
    • Properly propagating the Close call to the tree if it's closeable
    • Safely handling non-closeable trees by returning nil
  3. The pruning operations (Prune, PausePruning, ResumePruning) do not maintain any persistent resources that would require explicit cleanup through Close.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check how Close is used in pruning-related code

# Look for pruning-related files that should use Close
echo "Searching for pruning-related files..."
rg -l "pruning" --type go

# Check for Close usage in pruning operations
echo "Checking Close usage in pruning context..."
rg -B 5 -A 5 "Close\(\)" --type go

Length of output: 102805


Script:

#!/bin/bash
# Check for pruning-related code that interacts with Close
echo "Checking pruning manager code..."
rg -B 5 -A 5 "Close\(\)" store/pruning/
rg -B 5 -A 5 "Close\(\)" store/v2/pruning/

# Check for pruning manager tests
echo "Checking pruning manager tests..."
rg -B 5 -A 5 "Close" store/pruning/manager_test.go
rg -B 5 -A 5 "Close" store/v2/pruning/manager_test.go

# Check for store Close implementation
echo "Checking store Close implementation..."
rg -B 5 -A 5 "Close\(\)" store/iavl/store.go

Length of output: 1399


Script:

#!/bin/bash
# Check how pruning manager uses store
echo "Checking pruning manager store usage..."
rg -B 10 -A 10 "type Manager struct" store/pruning/manager.go
rg -B 10 -A 10 "type Manager struct" store/v2/pruning/manager.go

# Check pruning manager initialization
echo "Checking pruning manager initialization..."
rg -B 5 -A 10 "NewManager" store/pruning/manager.go
rg -B 5 -A 10 "NewManager" store/v2/pruning/manager.go

# Check store usage in pruning
echo "Checking store usage in pruning..."
rg -B 5 -A 10 "Prune" store/pruning/manager.go
rg -B 5 -A 10 "Prune" store/v2/pruning/manager.go

Length of output: 5636

store/rootmulti/store.go (1)

1175-1179: Non-deterministic map iteration is acceptable for cleanup.

The non-deterministic map iteration in the Close method is acceptable because:

  1. Resource cleanup doesn't require deterministic ordering
  2. All stores will be processed regardless of iteration order
  3. All errors are collected and joined
✅ Verification successful

Let me analyze the search results to verify if non-deterministic map iteration is acceptable for cleanup in this context.


Non-deterministic map iteration is acceptable for cleanup operations

The map iteration in the Close() method is safe because:

  1. The method's sole purpose is resource cleanup
  2. All stores are processed regardless of iteration order
  3. All errors are collected into a slice and joined together
  4. The order of cleanup doesn't affect the correctness or final state
  5. The implementation uses errors.Join() which handles multiple errors appropriately
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if deterministic ordering is required elsewhere in the codebase
# by checking for any comments or documentation mentioning order requirements.

rg -i "order|deterministic" --type go

Length of output: 122332


Script:

#!/bin/bash
# Check if the stores map is used in any other critical operations where order matters
ast-grep --pattern 'rs.stores'

Length of output: 30


Script:

#!/bin/bash
# Search for the usage of stores map in the file to understand the context
rg -A 5 -B 5 "stores\s*:=\s*make\(map\[string\]" store/rootmulti/store.go

Length of output: 75


Script:

#!/bin/bash
# Look for the Close method implementation and surrounding context
rg -A 10 -B 10 "func.*Close\(\)" store/rootmulti/store.go

Length of output: 524

🧰 Tools
🪛 GitHub Check: CodeQL

[warning] 1175-1179: Iteration over map
Iteration over map may be a possible source of non-determinism

CHANGELOG.md Outdated Show resolved Hide resolved
@yihuang yihuang marked this pull request as draft November 26, 2024 15:54
@yihuang yihuang changed the title fix: prune cmd wait for async pruning to finish fix: prune cmd should disable async pruning Nov 29, 2024
@yihuang yihuang marked this pull request as ready for review November 29, 2024 08:21
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

🧹 Outside diff range and nitpick comments (5)
baseapp/options.go (1)

89-92: Enhance function documentation

The implementation looks good and follows the established patterns. However, the documentation could be more descriptive to explain the impact of sync vs async pruning.

Consider expanding the documentation:

-// SetIAVLSyncPruning set sync/async pruning in the IAVL store.
+// SetIAVLSyncPruning configures whether IAVL store pruning should be synchronous or asynchronous.
+// When syncPruning is true, pruning operations will complete before returning control,
+// ensuring all pruned data is immediately removed. When false, pruning occurs
+// asynchronously in the background.
CHANGELOG.md (4)

Line range hint 1-1: Add title to changelog file

The changelog file should start with a clear title like "# Changelog" to follow documentation best practices.

+ # Changelog

Line range hint 3-3: Standardize version date format

The date format should be consistent across all versions. Currently some versions use YYYY-MM-DD while others use Month DD, YYYY.

Use ISO 8601 date format (YYYY-MM-DD) consistently for all version dates.


Line range hint 2-2: Add changelog guidelines section

Consider adding a "Changelog Guidelines" section at the top to document the expected format and style for changelog entries.

Add guidelines for:

  • Entry format and style
  • Section organization
  • Link formatting
  • Version numbering

Line range hint 1-2000: Fix markdown formatting inconsistencies

There are several formatting inconsistencies throughout the file:

  • Inconsistent indentation in lists
  • Mixed usage of * and - for bullet points
  • Inconsistent spacing around headers

Standardize on:

  • Using - for all bullet points
  • Consistent indentation (2 spaces)
  • One blank line before headers
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between dbf6912 and 37f4ccb.

📒 Files selected for processing (8)
  • CHANGELOG.md (1 hunks)
  • baseapp/options.go (1 hunks)
  • client/pruning/main.go (1 hunks)
  • server/start.go (1 hunks)
  • server/util.go (1 hunks)
  • store/iavl/store.go (1 hunks)
  • store/rootmulti/store.go (3 hunks)
  • store/types/store.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • client/pruning/main.go
  • store/iavl/store.go
  • store/rootmulti/store.go
🧰 Additional context used
📓 Path-based instructions (5)
CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

baseapp/options.go (1)

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

server/start.go (1)

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

server/util.go (1)

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

store/types/store.go (1)

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

🔇 Additional comments (3)
store/types/store.go (1)

224-226: Improve method documentation and verify implementation

The method documentation should be more descriptive about the impact of the sync parameter. Consider adding details about the behavior differences between sync and async pruning modes.

Let's verify that all implementations of CommitMultiStore have implemented this new method:

✅ Verification successful

Let's search more specifically for CommitMultiStore implementations and their relationship with the new method.


Let's check the implementation details and usage context with one final verification.


Documentation improvement needed for SetIAVLSyncPruning

The method is properly implemented in the rootmulti Store and correctly integrated into the BaseApp options, but the documentation should be enhanced to:

  • Explain that sync=true enables synchronous pruning while sync=false enables asynchronous pruning
  • Mention that this setting affects the IAVL store's pruning behavior
  • Reference that this can be configured through BaseApp options

Example documentation:

// SetIAVLSyncPruning sets the pruning mode for IAVL stores.
// When sync is true, pruning is performed synchronously during commits.
// When sync is false, pruning is performed asynchronously in the background.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all implementations of CommitMultiStore interface and verify they implement SetIAVLSyncPruning

# Find all Go files that might implement CommitMultiStore
echo "Searching for potential CommitMultiStore implementations..."
rg -l "type.*Store.*struct" --type go

# Find the actual method implementations
echo -e "\nSearching for SetIAVLSyncPruning implementations..."
ast-grep --pattern 'func ($x *$t) SetIAVLSyncPruning(sync bool) { $$$  }'

Length of output: 2395


Script:

#!/bin/bash
# Find direct implementations of CommitMultiStore
echo "Searching for CommitMultiStore interface implementations..."
rg -B 2 -A 2 "type.*struct.*{.*}" --type go | grep -B 2 -A 2 "implements.*CommitMultiStore"

# Search for rootmulti store which is likely the main implementation
echo -e "\nChecking rootmulti store implementation..."
rg "SetIAVLSyncPruning" store/rootmulti/store.go

# Look for any SetIAVLSyncPruning references
echo -e "\nSearching for all SetIAVLSyncPruning references..."
rg "SetIAVLSyncPruning" --type go

Length of output: 1249


Script:

#!/bin/bash
# Check the Store implementation in rootmulti
echo "Checking Store implementation in rootmulti..."
rg -B 5 -A 5 "func \(rs \*Store\) SetIAVLSyncPruning" store/rootmulti/store.go

# Check IAVL store implementation
echo -e "\nChecking IAVL store implementation..."
rg -B 5 -A 5 "syncPruning" store/iavl/store.go

# Check BaseApp usage
echo -e "\nChecking BaseApp usage..."
rg -B 5 -A 5 "SetIAVLSyncPruning" baseapp/options.go

Length of output: 2364

server/util.go (1)

558-558: LGTM! Verify flag definition.

The addition of IAVL sync pruning option follows the established pattern of other baseapp options. The implementation is correct and aligns with the PR objective to control pruning synchronization.

Let's verify the flag constant is properly defined:

✅ Verification successful

Flag constant is properly defined

The FlagIAVLSyncPruning constant is correctly defined in server/start.go as "iavl-sync-pruning", which follows the naming convention for flag constants in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if FlagIAVLSyncPruning is properly defined
# Expected: Find the flag definition in server package

# Search for the flag definition
rg "FlagIAVLSyncPruning.*=.*" --type go

Length of output: 104

server/start.go (1)

82-82: LGTM! Flag constant follows established patterns.

The new FlagIAVLSyncPruning constant follows the existing naming conventions and is properly placed with other IAVL-related flags.

Let's verify the flag usage across the codebase:

✅ Verification successful

Flag is properly integrated and used in the codebase

The FlagIAVLSyncPruning constant is correctly integrated into the codebase:

  • Used in server/util.go to configure IAVL store pruning behavior via baseapp.SetIAVLSyncPruning
  • Proper implementation exists in store/types, store/rootmulti, and baseapp/options.go
  • Used alongside other pruning-related flags in the pruning command context
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new IAVL sync pruning flag
# Test: Search for flag usage in code. Expect: Usage in pruning command and configuration.
rg "iavl-sync-pruning" --type go

Length of output: 95


Script:

#!/bin/bash
# Let's search for any references to the FlagIAVLSyncPruning constant
rg "FlagIAVLSyncPruning" --type go -A 3

Length of output: 716


Script:

#!/bin/bash
# Let's also check for any pruning-related command or configuration code
rg "func.*[Pp]rune|[Pp]runing" --type go -A 5

Length of output: 101956


Script:

#!/bin/bash
# Let's check for the actual usage of the flag in the codebase
rg "SetIAVLSyncPruning" --type go -A 3

Length of output: 1184


Script:

#!/bin/bash
# Let's also check for any pruning command implementation
rg "cmd.*[Pp]rune" --type go -A 5

Length of output: 1766

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

🧹 Outside diff range and nitpick comments (1)
server/mock/store.go (1)

145-147: LGTM! Consider adding interface documentation.

The implementation follows the established pattern for mock methods in this file. However, for better maintainability, consider adding a comment documenting the interface contract, especially since this is part of a larger pruning-related change.

Add documentation like this:

+// SetIAVLSyncPruning implements the MultiStore interface by providing a mock
+// that panics when called. This setting controls whether IAVL pruning should
+// be performed synchronously.
 func (ms multiStore) SetIAVLSyncPruning(syncPruning bool) {
 	panic("not implemented")
 }
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 37f4ccb and 4b8c9af.

📒 Files selected for processing (1)
  • server/mock/store.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
server/mock/store.go (1)

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

Comment on lines +145 to +147
func (ms multiStore) SetIAVLSyncPruning(syncPruning bool) {
panic("not implemented")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Missing implementation in CacheMultiStore

The SetIAVLSyncPruning method is defined in the MultiStore interface and needs to be implemented by all implementations. While rootmulti.Store has a proper implementation, cachemulti.Store is missing this method. The mock implementation in server/mock/store.go correctly panics for unimplemented functionality, but store/cachemulti/store.go needs to be updated to implement this interface method.

  • store/cachemulti/store.go: Add implementation of SetIAVLSyncPruning(bool) method
🔗 Analysis chain

Verify interface implementation across the codebase

Since this adds a new method to the MultiStore interface implementation, we should verify that all other implementations are updated accordingly.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all MultiStore interface implementations
ast-grep --pattern 'type $_ struct {
  $$$
}

var _ storetypes.MultiStore = $_'

Length of output: 81


Script:

#!/bin/bash
# Let's try a different approach to find MultiStore implementations
# First, let's find the interface definition
rg "type\s+MultiStore\s+interface" -A 10

# Then search for struct types that might implement it
rg "type.*Store.*struct"

# And also search for explicit interface checks
rg "var\s+_\s+.*MultiStore\s+=\s+"

Length of output: 7067


Script:

#!/bin/bash
# Let's check the implementation of the SetIAVLSyncPruning method in both implementations we found
# Check store/cachemulti/store.go
rg "SetIAVLSyncPruning" store/cachemulti/store.go -A 3

# Check store/rootmulti/store.go
rg "SetIAVLSyncPruning" store/rootmulti/store.go -A 3

# Let's also check the interface definition to see if this is a new method
rg "SetIAVLSyncPruning" store/types/store.go -A 3

Length of output: 445

@julienrbrt julienrbrt added this pull request to the merge queue Dec 4, 2024
@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Dec 4, 2024
Merged via the queue into cosmos:main with commit eb3bf8b Dec 4, 2024
69 of 71 checks passed
mergify bot pushed a commit that referenced this pull request Dec 4, 2024
(cherry picked from commit eb3bf8b)

# Conflicts:
#	store/iavl/store.go
#	store/rootmulti/store.go
#	store/types/store.go
@yihuang yihuang deleted the prune-cmd branch December 4, 2024 12:49
julienrbrt added a commit that referenced this pull request Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release C:CLI C:Store
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants