crypto-org-chain / cronos

Cronos is the first Ethereum-compatible blockchain network built on Cosmos SDK technology. Cronos aims to massively scale the DeFi, GameFi, and overall Web3 user community by providing builders with the ability to instantly port apps and crypto assets from other chains while benefiting from low transaction fees, high throughput, and fast finality.
Other
296 stars 238 forks source link

Problem: app hash mismatch occurs when upgrade to iavl v1.2.0 #1618

Closed mmsqe closed 1 month ago

mmsqe commented 1 month ago

๐Ÿ‘ฎ๐Ÿป๐Ÿ‘ฎ๐Ÿป๐Ÿ‘ฎ๐Ÿป !!!! REFERENCE THE PROBLEM YOUR ARE SOLVING IN THE PR TITLE AND DESCRIBE YOUR SOLUTION HERE !!!! DO NOT FORGET !!!! ๐Ÿ‘ฎ๐Ÿป๐Ÿ‘ฎ๐Ÿป๐Ÿ‘ฎ๐Ÿป

PR Checklist:

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

Summary by CodeRabbit

Release Notes

coderabbitai[bot] commented 1 month ago

Walkthrough

The pull request includes updates to the CHANGELOG.md, go.mod, gomod2nix.toml, and various files within the memiavl directory. Key changes involve updating dependencies, particularly the cosmos-sdk and iavl versions, as well as enhancements to error handling and version management in the memiavl component. The changelog documents breaking changes and improvements, while the memiavl files reflect modifications in versioning logic and testing enhancements.

Changes

File Change Summary
CHANGELOG.md Updated with entries for breaking changes in memiavl, improvements, bug fixes, and version upgrades.
go.mod Updated Go toolchain version and various module dependencies, including cosmos-sdk and ethermint.
gomod2nix.toml Updated github.com/cosmos/iavl version from v1.1.2 to v1.2.0 with hash change.
memiavl/db.go Modified reloadMultiTree method, refined error handling, and improved snapshot management.
memiavl/multitree.go Updated setInitialVersion method to use uint32, added overflow checks, and simplified tree management logic.
memiavl/tree.go Added cowVersion to Tree struct, simplified method signatures, and updated version handling logic.
.github/workflows/build.yml Streamlined testing commands and added conditional execution for relevant jobs.
Makefile Updated test target to depend on test-memiavl and test-store, added coverage options.

Possibly related PRs

Suggested reviewers

๐Ÿ‡ In the meadow, changes bloom,
With memiavl shedding gloom.
Versions rise, dependencies align,
Changelog notes the work divine.
Bugs are fixed, tests now sing,
A brighter code is what we bring! ๐ŸŒผ


๐Ÿ“œ Recent review details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
๐Ÿ“ฅ Commits Files that changed from the base of the PR and between af523664ac70cb83d470aa32fd193be6e839daec and bb0913ab45720eb619d17af5bf3eea705044cc2b.
๐Ÿ“’ Files selected for processing (3) * memiavl/db.go (1 hunks) * memiavl/multitree.go (7 hunks) * memiavl/tree.go (5 hunks)
๐Ÿšง Files skipped from review as they are similar to previous changes (1) * memiavl/tree.go
๐Ÿ”‡ Additional comments (11)
memiavl/multitree.go (10)
`108-110`: **LGTM: Improved type safety and readability** The changes in the `LoadMultiTree` function look good. The explicit casting of `initialVersion` to `uint32` ensures type safety, and the simplification of the empty check improves code readability. --- `137-142`: **LGTM: Enhanced safety in SetInitialVersion** The changes in the `SetInitialVersion` method are well-implemented. The additional check to ensure the tree is empty before setting the initial version prevents unintended modifications to non-empty trees. This, combined with the retained overflow check, significantly improves the method's robustness and safety. --- `146-151`: **LGTM: Improved version handling addresses PR objective** The changes in the `setInitialVersion` method are well-implemented and directly address the PR objective of resolving the app hash mismatch issue. The switch to `uint32` improves type consistency, and the updated logic ensures correct initial version setting for each tree when the version is greater than 1. This should resolve the version-related issues during upgrades. --- `158-158`: **LGTM: Simplified SetZeroCopy method** The change in the `SetZeroCopy` method looks good. It reflects an update in the `NamedTree` struct and simplifies the method call, improving code readability. --- `167-167`: **LGTM: Improved Copy method ensures separate tree copies** The change in the `Copy` method is well-implemented. By creating a new `NamedTree` with a copied `Tree`, it ensures that each tree in the copied `MultiTree` is a separate copy. This is crucial for maintaining the integrity of the snapshot and preventing unintended modifications to the original tree. --- `253-253`: **LGTM: Simplified ApplyChangeSet method** The change in the `ApplyChangeSet` method is consistent with the updates seen in other methods. It simplifies the method call and improves code readability, reflecting the updated structure of the `NamedTree` struct. --- `277-277`: **LGTM: Simplified SaveVersion method** The change in the `SaveVersion` method is consistent with the updates seen in other methods. It simplifies the method call by directly invoking `SaveVersion` on the `NamedTree` entry, improving code readability and maintaining consistency with the updated `NamedTree` struct. --- `298-299`: **LGTM: Simplified buildCommitInfo method** The changes in the `buildCommitInfo` method are consistent with the updates seen in other methods. Directly accessing `Version()` and `RootHash()` on the `NamedTree` entry simplifies the code and improves readability, while maintaining consistency with the updated `NamedTree` struct. --- `416-416`: **LGTM: Simplified Close method** The change in the `Close` method is consistent with the updates seen in other methods. Directly calling `Close()` on the `NamedTree` entry simplifies the code and improves readability, while maintaining consistency with the updated `NamedTree` struct. --- Line range hint `1-464`: **Overall assessment: Improved version handling and code consistency** The changes in this file consistently reflect an update in the `NamedTree` struct, making operations more direct and improving code readability. The modifications to version handling, particularly in the `setInitialVersion` method, directly address the PR objective of resolving the app hash mismatch issue during upgrades to iavl v1.2.0. Key improvements include: 1. Enhanced type safety with explicit casting to `uint32` for version handling. 2. Improved robustness in `SetInitialVersion` with additional checks. 3. Consistent simplification of method calls across the `MultiTree` struct. 4. Better handling of tree copies in the `Copy` method. These changes should resolve the version-related issues and improve the overall reliability and maintainability of the code.
memiavl/db.go (1)
`702-702`: **Pending WAL entries are now applied after reloading `MultiTree`** The addition of `return db.applyWALEntry(db.pendingLog)` ensures that any pending WAL entries are applied to the `MultiTree` after it has been reloaded. This change helps maintain the consistency of the database state by ensuring that no pending entries are lost during the reload process.
--- 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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
๐Ÿชง Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 71.42857% with 10 lines in your changes missing coverage. Please review.

Project coverage is 35.86%. Comparing base (766af76) to head (bb0913a). Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
memiavl/tree.go 64.70% 3 Missing and 3 partials :warning:
memiavl/import.go 0.00% 2 Missing :warning:
memiavl/multitree.go 86.66% 0 Missing and 2 partials :warning:
Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/crypto-org-chain/cronos/pull/1618/graphs/tree.svg?width=650&height=150&src=pr&token=92w0Dz1Coj&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=crypto-org-chain)](https://app.codecov.io/gh/crypto-org-chain/cronos/pull/1618?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=crypto-org-chain) ```diff @@ Coverage Diff @@ ## main #1618 +/- ## =========================================== + Coverage 17.72% 35.86% +18.14% =========================================== Files 72 123 +51 Lines 5208 9755 +4547 =========================================== + Hits 923 3499 +2576 - Misses 4162 5845 +1683 - Partials 123 411 +288 ``` | [Files with missing lines](https://app.codecov.io/gh/crypto-org-chain/cronos/pull/1618?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=crypto-org-chain) | Coverage ฮ” | | |---|---|---| | [memiavl/db.go](https://app.codecov.io/gh/crypto-org-chain/cronos/pull/1618?src=pr&el=tree&filepath=memiavl%2Fdb.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=crypto-org-chain#diff-bWVtaWF2bC9kYi5nbw==) | `64.11% <100.00%> (รธ)` | | | [memiavl/import.go](https://app.codecov.io/gh/crypto-org-chain/cronos/pull/1618?src=pr&el=tree&filepath=memiavl%2Fimport.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=crypto-org-chain#diff-bWVtaWF2bC9pbXBvcnQuZ28=) | `74.83% <0.00%> (รธ)` | | | [memiavl/multitree.go](https://app.codecov.io/gh/crypto-org-chain/cronos/pull/1618?src=pr&el=tree&filepath=memiavl%2Fmultitree.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=crypto-org-chain#diff-bWVtaWF2bC9tdWx0aXRyZWUuZ28=) | `76.11% <86.66%> (รธ)` | | | [memiavl/tree.go](https://app.codecov.io/gh/crypto-org-chain/cronos/pull/1618?src=pr&el=tree&filepath=memiavl%2Ftree.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=crypto-org-chain#diff-bWVtaWF2bC90cmVlLmdv) | `72.72% <64.70%> (รธ)` | | ... and [64 files with indirect coverage changes](https://app.codecov.io/gh/crypto-org-chain/cronos/pull/1618/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=crypto-org-chain)