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

Problem: iavl prune bug not reproduced in integration test #1705

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

yihuang
Copy link
Collaborator

@yihuang yihuang commented Nov 26, 2024

Solution: manage to reproduce it, change the iavl dependency to v1.2.1 will fail the test_permissions test case.

👮🏻👮🏻👮🏻 !!!! REFERENCE THE PROBLEM YOUR ARE SOLVING IN THE PR TITLE AND DESCRIBE YOUR SOLUTION HERE !!!! DO NOT FORGET !!!! 👮🏻👮🏻👮🏻

PR Checklist:

  • Have you read the CONTRIBUTING.md?
  • Does your PR follow the C4 patch requirements?
  • Have you rebased your work on top of the latest master?
  • Have you checked your code compiles? (make)
  • Have you included tests for any non-trivial functionality?
  • Have you checked your code passes the unit tests? (make test)
  • Have you checked your code formatting is correct? (go fmt)
  • Have you checked your basic code style is fine? (golangci-lint run)
  • If you added any dependencies, have you checked they do not contain any known vulnerabilities? (go list -json -m all | nancy sleuth)
  • If your changes affect the client infrastructure, have you run the integration test?
  • If your changes affect public APIs, does your PR follow the C4 evolution of public contracts?
  • If your code changes public APIs, have you incremented the crate version numbers and documented your changes in the CHANGELOG.md?
  • If you are contributing for the first time, please read the agreement in CONTRIBUTING.md now and add a comment to this pull request stating that your PR is in accordance with the Developer's Certificate of Origin.

Thank you for your code, it's appreciated! :)

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new prune method in the CosmosCLI for data management.
    • Added a method to configure synchronization pruning for IAVL stores.
  • Bug Fixes

    • Updated permissions test logic to reflect changes in roles and improved timing for operations.
  • Chores

    • Updated environment variables for better configuration management.

Copy link
Contributor

coderabbitai bot commented Nov 26, 2024

Walkthrough

The changes in this pull request involve updates to the go.mod file for dependency versions, the addition of a new method in the CosmosCLI class for pruning data, modifications to a test function to reflect new roles and increased wait times, updates to the .env file for environment variables, and the introduction of a new method in the Store struct for configuring IAVL synchronization pruning.

Changes

File Change Summary
go.mod Updated dependency version for github.com/cosmos/iavl and modified several replacement directives for dependencies.
integration_tests/cosmoscli.py Added prune method in CosmosCLI class to execute a prune command with an optional parameter.
integration_tests/test_permissions.py Modified test_permissions_updates function with a new docstring, updated cli instantiation, changed permission roles, increased wait times, and added node control commands.
scripts/.env Added CRONOS_ADMIN environment variable and updated IBC_CRO_DENOM for consistent export.
store/rootmulti/store.go Introduced SetIAVLSyncPruning method in Store struct to configure IAVL synchronization pruning.

Possibly related PRs

Suggested reviewers

  • leejw51crypto
  • devashishdxt
  • mmsqe

🐇 In the garden where bunnies play,
New methods bloom, brightening the day.
Dependencies updated, the code refined,
With pruning and tests, all well aligned.
Hops of joy for changes made,
In our code, let’s dance and parade! 🐾

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 golangci-lint (1.62.2)

level=warning msg="The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar."
level=warning msg="[runner] Can't run linter goanalysis_metalinter: buildir: failed to load package rootmulti: could not load export data: no export data for "github.com/crypto-org-chain/cronos/store/rootmulti""
level=error msg="Running error: can't run linter goanalysis_metalinter\nbuildir: failed to load package rootmulti: could not load export data: no export data for "github.com/crypto-org-chain/cronos/store/rootmulti""


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.

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

codecov bot commented Nov 26, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 33.68%. Comparing base (a3c2f70) to head (645ba6d).
Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
store/rootmulti/store.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #1705       +/-   ##
===========================================
+ Coverage   16.87%   33.68%   +16.81%     
===========================================
  Files          72      124       +52     
  Lines        6163    11898     +5735     
===========================================
+ Hits         1040     4008     +2968     
- Misses       5000     7521     +2521     
- Partials      123      369      +246     
Files with missing lines Coverage Δ
store/rootmulti/store.go 4.16% <0.00%> (ø)

... and 82 files with indirect coverage changes

@yihuang yihuang marked this pull request as ready for review November 30, 2024 02:21
@yihuang yihuang requested a review from a team as a code owner November 30, 2024 02:21
@yihuang yihuang requested review from mmsqe and leejw51crypto and removed request for a team November 30, 2024 02: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: 2

🧹 Outside diff range and nitpick comments (3)
integration_tests/test_permissions.py (3)

7-10: LGTM, but consider enhancing the docstring.

The docstring provides good context, but could be more detailed about the expected behavior and the specific conditions needed to reproduce the IAVL pruning issue.

Consider expanding the docstring to include:

  • Expected permission states before and after updates
  • Specific conditions required to trigger the IAVL pruning issue
  • Why node1 is specifically required for this test

24-26: LGTM, but enhance error validation.

The test correctly verifies both unauthorized and authorized permission updates, but could be more specific about expected error messages.

Consider adding specific error message validation:

     rsp = cli.update_permissions(acc, 3, from_="community")
-    assert rsp["code"] != 0, "should not have the permission"
+    assert rsp["code"] != 0 and "unauthorized" in rsp["raw_log"].lower(), \
+           f"Expected unauthorized error, got: {rsp['raw_log']}"

38-41: LGTM, but add explicit state verification.

The test verifies the permission update succeeds after pruning, but doesn't explicitly verify the final permission state.

Consider adding final state verification:

     rsp = cli.update_permissions(acc, 4, from_="admin")
     assert rsp["code"] == 0, rsp["raw_log"]
     wait_for_new_blocks(cli, 5)
+    final_perms = cli.query_permissions(acc)
+    assert final_perms["can_change_token_mapping"] is True, "Permissions not preserved after pruning"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3beaf73 and 645ba6d.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • go.mod (2 hunks)
  • integration_tests/cosmoscli.py (1 hunks)
  • integration_tests/test_permissions.py (2 hunks)
  • scripts/.env (1 hunks)
  • store/rootmulti/store.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • integration_tests/cosmoscli.py
🧰 Additional context used
🪛 GitHub Check: codecov/patch
store/rootmulti/store.go

[warning] 449-449: store/rootmulti/store.go#L449
Added line #L449 was not covered by tests

🔇 Additional comments (6)
integration_tests/test_permissions.py (1)

27-32: Verify the necessity of increased block wait time.

The wait time has been increased from 1 to 5 blocks. While this might be necessary for the IAVL pruning reproduction, it increases test execution time.

Could you confirm if this increased wait time is specifically required for the IAVL pruning issue reproduction? If not, we could optimize the test execution time.

scripts/.env (2)

11-11: LGTM! Export keyword standardization.

The standardization of the export keyword for IBC_CRO_DENOM maintains consistency while preserving the correct IBC denomination value.


9-10: LGTM! Verify the admin address derivation.

The addition of CRONOS_ADMIN using the same account as VALIDATOR1_MNEMONIC is well-documented.

Let's verify the address derivation from the mnemonic:

✅ Verification successful

The admin address is correctly used and verified in tests

The address crc12luku6uxehhak02py4rcz65zu0swh7wjsrw0pp is consistently used across the codebase:

  • In test cases validating Cronos address formats
  • In integration tests for governance parameter updates
  • In test configurations for auto-deployment settings
  • In message validation tests for token mapping updates

The address format is validated in params_test.go and is being used as a known-good test address, which aligns with its reuse as the admin address. The consistent usage across test files indicates this is a well-established test account.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that CRONOS_ADMIN address matches VALIDATOR1_MNEMONIC
# Note: This assumes the presence of the Cronos CLI tool in the test environment

# Extract the values
ADMIN_ADDRESS=$(grep CRONOS_ADMIN scripts/.env | cut -d'"' -f2)
VALIDATOR1_MNEMONIC=$(grep VALIDATOR1_MNEMONIC scripts/.env | cut -d'"' -f2)

echo "Admin address: $ADMIN_ADDRESS"
echo "Expected to match address derived from Validator1 mnemonic: $VALIDATOR1_MNEMONIC"

Length of output: 1048


Script:

#!/bin/bash
# Let's search for any tests or scripts that use this admin address
# to verify its usage and correctness

# Search for the admin address in the codebase
rg "crc12luku6uxehhak02py4rcz65zu0swh7wjsrw0pp" -B 2 -A 2

# Also search for any validator address derivation logic
rg -l "VALIDATOR1_MNEMONIC|CRONOS_ADMIN" --type ts --type js --type go

Length of output: 3274

go.mod (2)

92-92: Verify IAVL version selection

The PR description mentions reproducing the bug with v1.2.1, but this change updates to v1.2.2. Please verify if v1.2.2 contains the fix for the pruning bug.


254-256: Verify compatibility with updated dependencies

All cosmos-sdk related replacements are updated to the same commit hash. Please ensure these versions are compatible with the new IAVL v1.2.2.

✅ Verification successful

Dependencies are compatible with IAVL v1.2.2

The codebase is already using IAVL v1.2.2 as specified in go.mod, and there are multiple direct imports of IAVL across the codebase, particularly in the versiondb and memiavl packages. Since the cosmos-sdk fork replacements are all pointing to the same commit hash (6031e793ee95), and the codebase is actively using IAVL v1.2.2, this indicates the dependencies are aligned and compatible.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for IAVL version compatibility in the updated cosmos-sdk fork

# Check IAVL version in cosmos-sdk go.mod
gh api repos/crypto-org-chain/cosmos-sdk/contents/go.mod -q '.content' | base64 -d | grep "github.com/cosmos/iavl"

# Check for any breaking changes in the cosmos-sdk fork
gh api repos/crypto-org-chain/cosmos-sdk/commits/6031e793ee95 --jq '.commit.message' | grep -i "breaking"

Length of output: 313


Script:

#!/bin/bash
# Let's try a different approach to check IAVL compatibility

# First, let's check our own go.mod for IAVL version
rg "github.com/cosmos/iavl" go.mod -A 2 -B 2

# Check if there are any IAVL-related imports in the codebase
rg "github.com/cosmos/iavl" --type go

# Let's also check for any store or IAVL-related changes in recent commits
git log --oneline -n 10 | grep -i "store\|iavl"

Length of output: 1117

store/rootmulti/store.go (1)

448-451: Add documentation for empty implementation.

The empty implementation appears intentional since memiavl manages its own pruning strategy. However, it would be helpful to add a comment explaining this, similar to other pruning-related methods in this file.

 // Implements interface CommitMultiStore
 func (rs *Store) SetIAVLSyncPruning(syncPruning bool) {
+  // not needed, memiavl manages its own pruning strategy
 }

Additionally, please add test coverage for this method to maintain consistency with the rest of the codebase.

✅ Verification successful

Let me gather more context about the pruning-related methods and tests in the codebase.


Let me check one more thing to understand the relationship between memiavl and pruning functionality.


Add explanatory comment for empty implementation

The empty implementation is correct as it follows the same pattern as other pruning-related methods in the file. Please add a comment to maintain consistency with similar methods:

 // Implements interface CommitMultiStore
 func (rs *Store) SetIAVLSyncPruning(syncPruning bool) {
+  // not needed, memiavl manage its own snapshot/pruning strategy
 }

No test coverage is needed since this is an intentionally empty method, consistent with other pruning-related methods in the same file that are also empty and documented as not needed due to memiavl managing its own pruning strategy.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check test coverage for the SetIAVLSyncPruning method

# Search for test files that might contain tests for this method
fd -e go -e _test.go | xargs rg "SetIAVLSyncPruning"

Length of output: 133


Script:

#!/bin/bash
# Search for other pruning-related methods and their tests
rg -A 3 "func.*Pruning|func.*prune" --type go

# Search for the CommitMultiStore interface definition
ast-grep --pattern 'type CommitMultiStore interface {
  $$$
}'

Length of output: 1675


Script:

#!/bin/bash
# Search for comments and documentation about memiavl pruning
rg -B 2 -A 2 "memiavl.*pruning|pruning.*memiavl" --type go

# Check if there are other empty pruning-related methods with explanatory comments
rg -B 1 -A 1 "not needed, memiavl|memiavl manage" --type go

Length of output: 1165

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 449-449: store/rootmulti/store.go#L449
Added line #L449 was not covered by tests

integration_tests/test_permissions.py Show resolved Hide resolved
integration_tests/test_permissions.py Show resolved Hide resolved
@@ -89,7 +89,7 @@ require (
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v1.2.1-0.20240731145221-594b181f427e // indirect
github.com/cosmos/iavl v1.2.2 // indirect
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@mmsqe
Copy link
Collaborator

mmsqe commented Nov 30, 2024

right, not sure why get app mismatch in versiondb after permission test

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