Skip to content

refactor(collections): remove core dependency #24081

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

Merged
merged 18 commits into from
Mar 28, 2025

Conversation

aaronc
Copy link
Member

@aaronc aaronc commented Mar 20, 2025

Description

This PR removes the dependency of cosmossdk.io/collections on cosmossdk.io/core by:

  • defining type aliases for the required core types in the collections/corecompat package
  • copies required coretesting code into the collections/internal/testutil package

This should allow collections work transparently with any version of core which has store types defined as type aliases (ex. #24088), or with any other version of core if the proper adapter types are used.


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
    • Introduced new abstractions for data encoding, key-value operations, and genesis data processing, enhancing modularity and flexibility.
  • Refactor
    • Reorganized internal dependencies and testing utilities to streamline the codebase and improve maintainability.
  • Chores
    • Updated project dependencies to more current and robust libraries, ensuring improved compatibility and long-term support.

Copy link
Contributor

coderabbitai bot commented Mar 20, 2025

📝 Walkthrough

Walkthrough

This pull request refactors the dependency structure across the collections module. Several import paths have been updated to replace references from the old cosmossdk.io/core packages with the new internal packages (collections/internal/coretesting and collections/corecompat). New files in the corecompat package introduce interfaces for codec, genesis, and store management, while files in internal/coretesting provide testing utilities including context management and key-value store services. The go.mod file has also been updated to remove obsolete dependencies and add new ones.

Changes

File(s) Change Summary
collections/collections_test.go, collections/genesis_test.go, collections/indexed_map_test.go, collections/indexes/indexes_test.go, collections/quad_test.go, collections/triple_test.go, collections/lookup_map_test.go Updated import paths: replaced references from cosmossdk.io/core/store and cosmossdk.io/core/testing with collections/internal/coretesting and updated store aliases from cosmossdk.io/corecompat.
collections/iter.go, collections/map.go, collections/schema.go, collections/protocodec/collections.go Adjusted import statements to source store, appmodule, and codec functionalities from the new collections/corecompat package.
collections/corecompat/codec.go, collections/corecompat/doc.go, collections/corecompat/genesis.go, collections/corecompat/store.go Introduced new interfaces and types for codec, genesis handling, and key-value store management within the new corecompat package.
collections/internal/coretesting/context.go, collections/internal/coretesting/store.go Added new internal testing utilities for context management (with dummyCtx) and a KVStoreService implementation for interacting with test key-value stores.
collections/go.mod Removed dependencies on cosmossdk.io/core and cosmossdk.io/core/testing and added new dependencies (e.g., github.com/cosmos/cosmos-db), along with several updated indirect dependencies.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test
    participant Ctx as coretesting.Context
    participant KS as KVStoreService
    participant DC as dummyCtx

    T->>Ctx: Call Context()
    Ctx-->>T: Return context with dummyCtx (store map)
    T->>KS: Call KVStoreService(ctx, moduleName)
    KS->>DC: Retrieve KVStore for moduleName from store map
    DC-->>KS: Return KVStore
    KS-->>T: Return KVStore instance
Loading

Possibly related PRs

Suggested labels

C:core/testing, C:server/v2, C:Cosmovisor, C:x/accounts, C:x/bank, C:x/gov, C:x/distribution, C:x/mint, C:x/staking, C:x/slashing, C:x/epochs, C:x/protocolpool, C:x/group, C:x/authz, C:x/nft, C:x/consensus, C:x/circuit, C:Store, backport/v0.52.x

Suggested reviewers

  • kocubinski
  • sontrinh16
  • julienrbrt
  • tac0turtle
  • testinginprod

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@aaronc aaronc marked this pull request as ready for review March 20, 2025 18:25
@aaronc aaronc requested a review from a team March 20, 2025 18:25
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

🧹 Nitpick comments (5)
collections/indexes/indexes_test.go (1)

6-8: Successfully updated test imports to use internal coretesting.

The test code has been properly updated to use the new internal coretesting package and corecompat store interface, aligning with the PR's goal of removing core dependencies.

According to the static analysis hint, there might be a formatting issue with the imports. Consider running go fmt to ensure proper formatting.

-
-	"cosmossdk.io/collections/internal/coretesting"
-
-	store "cosmossdk.io/collections/corecompat"
+	"cosmossdk.io/collections/internal/coretesting"
+	store "cosmossdk.io/collections/corecompat"
🧰 Tools
🪛 golangci-lint (1.64.8)

6-6: File is not properly formatted

(gci)

collections/internal/coretesting/store.go (1)

14-19: Check for Overwriting Existing Stores
This function unconditionally overwrites any store that might already exist under the same module name. Consider verifying if one already exists to avoid unintended overwrites or collisions.

 func KVStoreService(ctx context.Context, moduleName string) store.KVStoreService {
+    if _, ok := unwrap(ctx).stores[moduleName]; ok {
+        // Optionally return the existing store or return an error/warning
+    }
     unwrap(ctx).stores[moduleName] = NewMemKV()
     return kvStoreService{
         moduleName: moduleName,
     }
 }
collections/corecompat/genesis.go (1)

13-20: Minor Typo in Documentation
There is a small grammatical typo: “closers” instead of “closes.”

-// iteration. It is important the caller closers the writer AND checks the error
+// iteration. It is important the caller closes the writer AND checks the error
collections/internal/coretesting/memdb.go (1)

3-10: Format File for Consistency
The static analysis tool indicates a formatting discrepancy. Consider running tools like gci or goimports to ensure the imports and overall format conform to style guidelines.

collections/collections_test.go (1)

10-12: Import structure updated to remove core dependency

The imports have been updated to replace core dependencies with internal/compatible alternatives:

  1. Using the internal testing package cosmossdk.io/collections/internal/coretesting
  2. Aliasing the new store compatibility layer as store

This change aligns with the PR objective to remove the core dependency.

Note: There's a minor formatting issue flagged by gci static analysis. Consider fixing the spacing between imports.

-	"cosmossdk.io/collections/internal/coretesting"
-
-	store "cosmossdk.io/collections/corecompat"
+	"cosmossdk.io/collections/internal/coretesting"
+	store "cosmossdk.io/collections/corecompat"
🧰 Tools
🪛 golangci-lint (1.64.8)

10-10: File is not properly formatted

(gci)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9f8a03f and 9de156b.

⛔ Files ignored due to path filters (1)
  • collections/go.sum is excluded by !**/*.sum
📒 Files selected for processing (19)
  • collections/collections_test.go (1 hunks)
  • collections/corecompat/codec.go (1 hunks)
  • collections/corecompat/doc.go (1 hunks)
  • collections/corecompat/genesis.go (1 hunks)
  • collections/corecompat/store.go (1 hunks)
  • collections/genesis_test.go (2 hunks)
  • collections/go.mod (0 hunks)
  • collections/indexed_map_test.go (1 hunks)
  • collections/indexes/indexes_test.go (1 hunks)
  • collections/internal/coretesting/context.go (1 hunks)
  • collections/internal/coretesting/memdb.go (1 hunks)
  • collections/internal/coretesting/store.go (1 hunks)
  • collections/iter.go (1 hunks)
  • collections/lookup_map_test.go (1 hunks)
  • collections/map.go (1 hunks)
  • collections/protocodec/collections.go (2 hunks)
  • collections/quad_test.go (1 hunks)
  • collections/schema.go (9 hunks)
  • collections/triple_test.go (1 hunks)
💤 Files with no reviewable changes (1)
  • collections/go.mod
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.go`: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

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

  • collections/map.go
  • collections/corecompat/doc.go
  • collections/genesis_test.go
  • collections/triple_test.go
  • collections/indexed_map_test.go
  • collections/quad_test.go
  • collections/corecompat/codec.go
  • collections/iter.go
  • collections/indexes/indexes_test.go
  • collections/lookup_map_test.go
  • collections/internal/coretesting/context.go
  • collections/corecompat/store.go
  • collections/corecompat/genesis.go
  • collections/collections_test.go
  • collections/internal/coretesting/store.go
  • collections/protocodec/collections.go
  • collections/internal/coretesting/memdb.go
  • collections/schema.go
`**/*_test.go`: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

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

  • collections/genesis_test.go
  • collections/triple_test.go
  • collections/indexed_map_test.go
  • collections/quad_test.go
  • collections/indexes/indexes_test.go
  • collections/lookup_map_test.go
  • collections/collections_test.go
🧬 Code Definitions (5)
collections/genesis_test.go (1)
collections/corecompat/genesis.go (1) (1)
  • GenesisSource (11-11)
collections/corecompat/store.go (2)
collections/protocodec/collections.go (2) (2)
  • value (116-116)
  • value (126-126)
collections/iter.go (1) (1)
  • Iterator (211-218)
collections/internal/coretesting/store.go (2)
collections/internal/coretesting/context.go (2) (2)
  • Context (11-18)
  • unwrap (25-32)
collections/internal/coretesting/memdb.go (1) (1)
  • NewMemKV (34-41)
collections/protocodec/collections.go (3)
codec/collections.go (2) (2)
  • collValue (75-78)
  • protoMessage (56-59)
collections/corecompat/codec.go (1) (1)
  • Codec (4-7)
core/codec/codec.go (1) (1)
  • Codec (6-9)
collections/schema.go (1)
collections/corecompat/genesis.go (2) (2)
  • GenesisTarget (20-20)
  • GenesisSource (11-11)
🪛 golangci-lint (1.64.8)
collections/indexes/indexes_test.go

6-6: File is not properly formatted

(gci)

collections/collections_test.go

10-10: File is not properly formatted

(gci)

collections/internal/coretesting/store.go

7-7: File is not properly formatted

(gci)

collections/schema.go

10-10: File is not properly formatted

(gci)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: tests (00)
  • GitHub Check: test-system-v2
  • GitHub Check: Analyze
  • GitHub Check: Summary
🔇 Additional comments (39)
collections/iter.go (1)

10-10:

✅ Verification successful

LGTM: Successfully migrated import for store package.

The import has been correctly updated to use the new corecompat package instead of the core dependency, which aligns with the PR objective to remove core dependencies.


🏁 Script executed:

#!/bin/bash
# Verify the compatibility of store interfaces between core and corecompat
# Check if all required store interfaces are properly defined in corecompat

echo "Checking store interfaces in corecompat..."
rg -A 5 "type (KVStore|Iterator)" collections/corecompat/

echo "Checking for any imports still using cosmossdk.io/core/store in collections package..."
rg "cosmossdk.io/core/store" collections/ --glob "!**/*.md" --glob "!**/internal/**"

Length of output: 1680


Import Migration Verified:

  • The store package import in collections/iter.go has been successfully updated to use cosmossdk.io/collections/corecompat.
  • Verification shows that the store interfaces (e.g., KVStore, Iterator) in collections/corecompat/store.go are defined as expected.
  • No remaining references to the deprecated cosmossdk.io/core/store were found in the collections package.

LGTM.

collections/map.go (1)

9-9: LGTM: Successfully migrated store import to corecompat.

The import has been correctly updated to use the new corecompat package instead of the direct core dependency, which aligns with the PR objective of removing core dependencies.

collections/corecompat/codec.go (1)

1-27: Well-structured interface definitions for codec functionality.

The new interfaces provide a clean abstraction layer for encoding and decoding operations, which allows collections to work with codecs without direct dependencies on the core package. The interfaces are properly documented and follow good Go practices with clear, descriptive names and focused responsibilities.

collections/indexes/indexes_test.go (1)

12-14: LGTM: Test helper function now uses coretesting package.

The function correctly uses the new coretesting package instead of the core testing package, maintaining the same functionality while removing the core dependency.

collections/internal/coretesting/context.go (4)

9-10: Well-Scoped Context Key
Declaring an empty private struct for context keys is a common best practice, preventing key collisions.


11-18: Context Initialization Looks Good
The function neatly provides a preconfigured background context for testing. No immediate concerns noted.


20-22: Internal Structure Successfully Encapsulated
This unexported dummyCtx struct keeps test stores internal. It’s clear and sufficiently minimal for test usage.


24-31: Consider Avoiding Panics in Broader Context
While panics may be acceptable for testing, in production-like code paths returning an error might be safer. For test code, this is fine.

collections/internal/coretesting/store.go (2)

21-23: Minimal Data Holder
The struct is straightforward, storing only the module name, aligning well with the single-purpose interface approach.


25-31: Stored Module Lookup
Panicking for a missing module is consistent with test usage, though you might consider an error return if you ever need graceful error handling.

collections/corecompat/genesis.go (1)

5-11: Well-Documented Genesis Source
The function type and comments clearly describe stream-based reading. The nil response for missing fields is intuitive.

collections/internal/coretesting/memdb.go (4)

28-107: In-Memory Key-Value Logic Appears Sound
The MemKV struct and its supporting methods (set, get, delete, iterator, etc.) are coherent. The B-Tree usage is appropriate, and error checks for empty keys are helpful. Overall, this is well-engineered for an in-memory store.


109-259: Iterator Implementation is Well-Structured
Your memIterator correctly handles ascending/descending logic and ensures valid boundaries. Panics remain acceptable for tests.


261-340: Thread-Safe Wrapper on MemKV
MemDB uses mutex locks for concurrency, wrapping MemKV effectively. Methods like Get, Set, and Iterator appear consistent. Excellent for testing scenarios.


342-455: Batch Operations are Correct and Feature-Rich
memDBBatch implements essential batch sets/deletes alongside size tracking, finalizing with a write or close. The partial example of concurrency and error checks is balanced.

collections/corecompat/doc.go (1)

1-4: Well-structured package documentation

The package documentation clearly explains the purpose of the corecompat package and provides a solid rationale for redefinition of the interfaces from cosmossdk.io/core. This aligns well with the PR objective of removing core dependencies.

collections/indexed_map_test.go (3)

11-11: Import path update is consistent with PR objectives

The change from using the core testing package to an internal coretesting package aligns with the goal of removing dependencies on the core module. The test code continues to function correctly with this change.


47-50: Test continues to function with new import

The test code properly utilizes the new coretesting package, showing the import change was implemented correctly. The test initializes context and store service using the new package path without requiring any functional changes.


128-129: Successful migration to internal testing package

The test initialization in this section also successfully uses the new coretesting package, demonstrating consistent implementation of the dependency change throughout the file.

collections/lookup_map_test.go (2)

9-9: Import path update aligns with PR objectives

The import change from core testing to internal coretesting package successfully implements the goal of removing dependencies on the core module.


13-15: Test maintains functionality with updated imports

The test initialization correctly uses the new coretesting package for creating context and key-value store service. This confirms that the internal package provides the same functionality as the previous core testing package.

collections/triple_test.go (2)

10-10: Import path update follows pattern in related files

The change to use the internal coretesting package is consistent with the pattern seen in other test files, maintaining a consistent approach to removing core dependencies.


22-24: Test implementation successfully uses new package

The test initialization continues to work correctly with the new coretesting package, confirming that the internal implementation provides the necessary functionality for the tests.

collections/quad_test.go (1)

10-10: Dependency moved to internal package

This change updates the import path from cosmossdk.io/core/testing to cosmossdk.io/collections/internal/coretesting, which aligns with the PR objective of removing the core dependency. The test functionality remains unchanged, but now relies on an internal testing package rather than an external one.

collections/genesis_test.go (2)

11-11: Import updated to use corecompat instead of core/appmodule

The import has been updated to use the new compatibility layer instead of the direct core dependency, which aligns with the PR objective.


113-113: Function signature updated to use corecompat.GenesisSource

The return type has been updated from appmodule.GenesisSource to corecompat.GenesisSource to match the new import. This maintains compatibility while removing the core dependency.

The implementation of the function remains unchanged, which indicates that the interface defined in corecompat matches the original interface from appmodule.

collections/corecompat/store.go (1)

1-84: New compatibility layer implementing core store interfaces

This new file creates a compatibility layer that defines several interfaces previously imported from the core module:

  1. KVStoreService - For retrieving KVStore from context
  2. MemoryStoreService - For accessing memory-backed KVStore
  3. KVStore - For key-value operations
  4. Iterator - For iterating over keys

The interfaces are well-documented with clear comments explaining their purpose, behavior, and contracts. Each method includes information about error conditions and usage requirements.

This approach effectively removes the dependency on the core module while maintaining the same interfaces, which should minimize the impact on existing code.

collections/protocodec/collections.go (3)

13-13: Import updated to use new corecompat package.

The code now imports corecompat to replace the previous core package dependency, aligning with the PR's goal of removing direct core dependencies.


60-60: Updated type casting to use the new corecompat package.

The implementation now casts the codec to corecompat.Codec instead of using the previous core codec type while maintaining the same function signature and behavior.


64-64: Updated field type to use the new corecompat package.

The cdc field in the collValue struct has been updated to use corecompat.Codec instead of the previous core codec type, completing the dependency migration.

collections/schema.go (9)

172-172: Updated DefaultGenesis method signature.

The method signature has been updated to use corecompat.GenesisTarget instead of its core counterpart, maintaining the same functionality while reducing direct dependencies on the core package.


183-183: Updated defaultGenesis method signature.

The private implementation method signature has been updated to use corecompat.GenesisTarget to match the public method's changes.


199-199: Updated ValidateGenesis method signature.

The method signature has been updated to use corecompat.GenesisSource instead of its core counterpart, maintaining the same functionality while reducing direct dependencies on the core package.


209-209: Updated validateGenesis method signature.

The private implementation method signature has been updated to use corecompat.GenesisSource to match the public method's changes.


230-230: Updated InitGenesis method signature.

The method signature has been updated to use corecompat.GenesisSource instead of its core counterpart, maintaining the same functionality while reducing direct dependencies on the core package.


241-241: Updated initGenesis method signature.

The private implementation method signature has been updated to use corecompat.GenesisSource to match the public method's changes.


262-262: Updated ExportGenesis method signature.

The method signature has been updated to use corecompat.GenesisTarget instead of its core counterpart, maintaining the same functionality while reducing direct dependencies on the core package.


273-273: Updated exportGenesis method signature.

The private implementation method signature has been updated to use corecompat.GenesisTarget to match the public method's changes.


10-12:

❓ Verification inconclusive

Import statements updated to use new corecompat package.

The code now imports the store interface and related types from corecompat package instead of directly depending on core packages. However, there's a formatting issue identified by static analysis.


🏁 Script executed:

#!/bin/bash
# Format the import statements properly
gofmt -w collections/schema.go

Length of output: 32


Attention: Verify Formatting and Import Updates in collections/schema.go

The import statements now correctly reference the new corecompat package using the alias store alongside the direct import. The file was auto-formatted with gofmt -w, and no errors were reported. However, since the gofmt run produced no output, please manually verify that all formatting issues flagged by static analysis have been resolved and confirm that having both the aliased and unaliased imports is intentional.

🧰 Tools
🪛 golangci-lint (1.64.8)

10-10: File is not properly formatted

(gci)

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 (2)
collections/internal/coretesting/memdb.go (2)

253-259: Use error returns instead of panics for invalid iterator states.

Relying on a panic in assertValid() could disrupt the flow of code using the iterator, especially in high-level application logic. It may be safer to rely on error handling rather than panicking.


261-312: Revisit lock usage for iterators.

Calls to Iterator and ReverseIterator simply delegate to bt.kv without acquiring a lock, which could allow writes to occur while iterating. This can lead to inconsistent iterator views of the data. Consider adding read locks around iteration for thread safety, or document that concurrent writes are unsupported during iteration.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9de156b and d40a667.

⛔ Files ignored due to path filters (1)
  • collections/go.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • collections/go.mod (0 hunks)
  • collections/internal/coretesting/memdb.go (1 hunks)
  • collections/internal/coretesting/store.go (1 hunks)
💤 Files with no reviewable changes (1)
  • collections/go.mod
🚧 Files skipped from review as they are similar to previous changes (1)
  • collections/internal/coretesting/store.go
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

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

  • collections/internal/coretesting/memdb.go
🧬 Code Definitions (1)
collections/internal/coretesting/memdb.go (1)
collections/internal/coretesting/store.go (1) (1)
  • _ (10-10)
🪛 golangci-lint (1.64.8)
collections/internal/coretesting/memdb.go

22-22: var errValueNil is unused

(unused)


23-23: var errBatchClosed is unused

(unused)


341-341: type opType is unused

(unused)


344-344: const opTypeSet is unused

(unused)


345-345: const opTypeDelete is unused

(unused)


348-348: type operation is unused

(unused)


355-355: type memDBBatch is unused

(unused)


362-362: func newMemDBBatch is unused

(unused)


371-371: func (*memDBBatch).Set is unused

(unused)


387-387: func (*memDBBatch).Delete is unused

(unused)

⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: tests (03)
  • GitHub Check: tests (02)
  • GitHub Check: tests (01)
  • GitHub Check: tests (00)
  • GitHub Check: test-simapp-v2
  • GitHub Check: test-system-v2
  • GitHub Check: test-sim-nondeterminism
  • GitHub Check: test-integration
  • GitHub Check: build (arm64)
  • GitHub Check: build (amd64)
  • GitHub Check: Analyze
  • GitHub Check: golangci-lint
  • GitHub Check: Summary
🔇 Additional comments (1)
collections/internal/coretesting/memdb.go (1)

20-24: Static analysis warnings appear to be false positives.

The errValueNil and errBatchClosed variables are correctly referenced later in the batch operations, so you can safely disregard the "unused" lint messages related to them.

🧰 Tools
🪛 golangci-lint (1.64.8)

22-22: var errValueNil is unused

(unused)


23-23: var errBatchClosed is unused

(unused)

Comment on lines 44 to 46
func (bt MemKV) set(key, value []byte) {
bt.tree.Set(newItem(key, value))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider validating keys and values for consistency with batch logic.

Here, MemKV#set accepts any key/value without validation, while batch-based Set checks for empty keys and nil values. Standardizing validation across both paths would help achieve consistent behavior when storing data.

@aaronc aaronc marked this pull request as draft March 20, 2025 20:59
@aaronc aaronc marked this pull request as ready for review March 26, 2025 17:01
// Package corecompat defines the store, codec and genesis interface that collections expects
// or implements. These interfaces are all redefined from cosmossdk.io/core in order to
// avoid a direct dependency on cosmossdk.io/core.
package corecompat
Copy link
Member Author

Choose a reason for hiding this comment

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

Does this package feel like the right place to put this stuff?

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 (4)
collections/internal/coretesting/memdb.go (4)

18-18: Run Go format/lint.

The file doesn't appear to be formatted according to gofumpt style rules. Please run gofumpt or a similar tool to ensure consistent formatting.

🧰 Tools
🪛 golangci-lint (1.64.8)

18-18: File is not properly formatted

(gofumpt)


25-37: Use pointer receivers for consistency with Go best practices.

While using value receivers can be acceptable in some situations, typical Go convention suggests pointer receivers for methods that modify internal state or hold references (e.g., the *btree.BTreeG pointer). Consider changing these methods to use pointer receivers for better clarity and maintainability.

-type MemKV struct {
+type MemKV struct {
	tree *btree.BTreeG[item]
 }

-func (bt MemKV) set(key, value []byte) {
+func (bt *MemKV) set(key, value []byte) {
	bt.tree.Set(newItem(key, value))
}

56-73: Unify the empty-key handling.

iterator and reverseIterator return an error for empty start/end keys, but Set and Delete allow them without complaint. Consider providing a single consistent rule (e.g., always reject empty keys) to avoid unexpected usage errors.


249-254: Reconsider panicking in test utility code.

Panic on invalid iterator state can be acceptable in test-only code, but consider returning an error instead for non-catastrophic conditions. This approach can help avoid unexpected crashes and encourage more robust error handling, especially if MemKV is used outside strict test contexts.

🧰 Tools
🪛 GitHub Check: CodeQL

[warning] 253-253: Panic in BeginBock or EndBlock consensus methods
Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d40a667 and 9b5bf16.

📒 Files selected for processing (4)
  • collections/genesis_test.go (1 hunks)
  • collections/internal/coretesting/memdb.go (1 hunks)
  • collections/protocodec/collections.go (1 hunks)
  • collections/schema.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • collections/genesis_test.go
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

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

  • collections/protocodec/collections.go
  • collections/internal/coretesting/memdb.go
  • collections/schema.go
🪛 golangci-lint (1.64.8)
collections/internal/coretesting/memdb.go

18-18: File is not properly formatted

(gofumpt)

collections/schema.go

10-10: ST1019: package "cosmossdk.io/collections/corecompat" is being imported more than once

(stylecheck)


11-11: ST1019(related information): other import of "cosmossdk.io/collections/corecompat"

(stylecheck)

🪛 GitHub Check: CodeQL
collections/internal/coretesting/memdb.go

[warning] 253-253: Panic in BeginBock or EndBlock consensus methods
Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (3)
collections/protocodec/collections.go (1)

13-13: Import path change looks good

The import path has been correctly updated to use the new corecompat package instead of the previous core dependency, which aligns with the PR objective of removing dependencies on cosmossdk.io/core.

collections/internal/coretesting/memdb.go (2)

39-54: Validate keys consistently.

Currently, set, get, and delete do not reject empty keys, while other methods (iterator and reverseIterator) raise errors for empty slices. Standardizing this validation across all entry points ensures consistent behavior and reduces bug risks.


75-103: Note on concurrency.

The B-tree is configured with NoLocks: true, meaning this store is not safe for concurrent usage. If concurrency is needed, add a synchronization mechanism or lock-based B-tree. Otherwise, clearly document that this store is single-thread-only.

Would you like to verify if concurrency is required anywhere else in this module? If so, we can propose a locking strategy.

Comment on lines 10 to 11
appmodule "cosmossdk.io/collections/corecompat"
store "cosmossdk.io/collections/corecompat"
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fix duplicate import issue

The package cosmossdk.io/collections/corecompat is being imported twice with different aliases. This violates Go style guidelines and creates unnecessary confusion.

Consider refactoring to use a single import with appropriate naming:

-appmodule "cosmossdk.io/collections/corecompat"
-store "cosmossdk.io/collections/corecompat"
+corecompat "cosmossdk.io/collections/corecompat"

Then update references throughout the file to use the appropriate qualified names (e.g., corecompat.KVStore, corecompat.GenesisTarget).

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
appmodule "cosmossdk.io/collections/corecompat"
store "cosmossdk.io/collections/corecompat"
corecompat "cosmossdk.io/collections/corecompat"
🧰 Tools
🪛 golangci-lint (1.64.8)

10-10: ST1019: package "cosmossdk.io/collections/corecompat" is being imported more than once

(stylecheck)


11-11: ST1019(related information): other import of "cosmossdk.io/collections/corecompat"

(stylecheck)


type dummyKey struct{}

func Context() context.Context {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think instead of defining this stuff we should just go back to how we tested and created a test db before:

func deps() (store.KVStoreService, context.Context) {

This is a ref from collections/v0.4.0

Copy link
Member Author

Choose a reason for hiding this comment

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

How's this: 1efb5b2 ?

Copy link
Contributor

@aljo242 aljo242 left a comment

Choose a reason for hiding this comment

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

I think we should resuse as much as we can from the db package instead of reimplementing stuff in coretesting, but otherwise lgtm

@aaronc
Copy link
Member Author

aaronc commented Mar 26, 2025

I don't think we need a backport label because it's a separate go mod and we can tag off of main.

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

🧹 Nitpick comments (1)
collections/go.mod (1)

17-48: Indirect Dependencies Validation.
This block adds several indirect dependencies (e.g., dependencies from CockroachDB, DataDog, Prometheus, etc.) to support the updated dependency graph after removing core. It is recommended to run go mod tidy to ensure that all entries are necessary and there are no redundant or outdated dependencies. Additionally, please verify that these versions are compatible and do not introduce transitive conflicts.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9b5bf16 and 1efb5b2.

⛔ Files ignored due to path filters (1)
  • collections/go.sum is excluded by !**/*.sum
📒 Files selected for processing (2)
  • collections/go.mod (2 hunks)
  • collections/internal/coretesting/store.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • collections/internal/coretesting/store.go
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: tests (03)
  • GitHub Check: tests (02)
  • GitHub Check: tests (01)
  • GitHub Check: tests (00)
  • GitHub Check: test-sim-nondeterminism
  • GitHub Check: test-simapp-v2
  • GitHub Check: test-integration
  • GitHub Check: test-system-v2
  • GitHub Check: build (arm64)
  • GitHub Check: Analyze
  • GitHub Check: build (amd64)
  • GitHub Check: golangci-lint
  • GitHub Check: Summary
🔇 Additional comments (1)
collections/go.mod (1)

7-7: Dependency Update: Introduce cosmos-db Dependency.
The new dependency on github.com/cosmos/cosmos-db v1.1.1 replaces the removed core dependency and supports the new refactoring direction. Please verify that this dependency fully meets the required interface expectations previously provided by cosmossdk.io/core.

Copy link
Contributor

Choose a reason for hiding this comment

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

are there any downsides with the type Foo = ... style approach here?

Copy link
Member Author

Choose a reason for hiding this comment

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

The main downside is that you cannot add new interface members without breaking compatibility. We may have new store interfaces eventually but these interfaces have not changed for a long time so I consider them pretty stable.

Copy link
Contributor

Choose a reason for hiding this comment

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

i guess we can just call this testutil

Copy link
Member Author

Choose a reason for hiding this comment

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

renamed

@technicallyty
Copy link
Contributor

I don't think we need a backport label because it's a separate go mod and we can tag off of main.

why dont we just target v53 here? eventually we will overwrite main with v53 contents

@aaronc
Copy link
Member Author

aaronc commented Mar 27, 2025

I don't think we need a backport label because it's a separate go mod and we can tag off of main.

why dont we just target v53 here? eventually we will overwrite main with v53 contents

Double checking this, it looks like we've already backported collections v1 to the v53 branch is that right?

@technicallyty
Copy link
Contributor

I don't think we need a backport label because it's a separate go mod and we can tag off of main.

why dont we just target v53 here? eventually we will overwrite main with v53 contents

Double checking this, it looks like we've already backported collections v1 to the v53 branch is that right?

yes

@aaronc
Copy link
Member Author

aaronc commented Mar 27, 2025

Okay, I'll try changing the base branch of this PR

@aaronc aaronc marked this pull request as draft March 27, 2025 17:20
@aaronc aaronc changed the base branch from main to release/v0.53.x March 27, 2025 17:20
@aaronc aaronc force-pushed the aaronc/collections-no-core branch from 1efb5b2 to f91a55e Compare March 27, 2025 18:01
@aaronc aaronc marked this pull request as ready for review March 27, 2025 18:08
@aaronc
Copy link
Member Author

aaronc commented Mar 27, 2025

Okay, it's rebased now

@aljo242 aljo242 added this pull request to the merge queue Mar 28, 2025
Merged via the queue into release/v0.53.x with commit 2ccf08a Mar 28, 2025
46 checks passed
@aljo242 aljo242 deleted the aaronc/collections-no-core branch March 28, 2025 22:26
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.

3 participants