Skip to content

Switch to collections in the ibcratelimit module.#2647

Open
nagarajdivine wants to merge 2 commits into
mainfrom
feat/collections-ibcratelimit
Open

Switch to collections in the ibcratelimit module.#2647
nagarajdivine wants to merge 2 commits into
mainfrom
feat/collections-ibcratelimit

Conversation

@nagarajdivine

@nagarajdivine nagarajdivine commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Description


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md).
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Added relevant changelog entries under .changelog/unreleased (see Adding Changes).
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for parameter initialization and updates so failures are reported and tests fail on misconfiguration.
  • Refactor
    • Migration of parameter storage to a schema-backed collections approach and corresponding changes to keeper initialization.
  • Documentation
    • Added changelog entry documenting the collections migration for the rate-limiting module.

@nagarajdivine nagarajdivine requested a review from a team as a code owner March 17, 2026 16:14
@coderabbitai

coderabbitai Bot commented Mar 17, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The PR migrates the x/ibcratelimit module from direct KVStore key usage to collections-based storage, replacing storetypes.StoreKey with store.KVStoreService, introducing a collections.Schema and ParamsItem, changing NewKeeper and SetParams signatures, and propagating error handling where SetParams is called.

Changes

Cohort / File(s) Summary
Keeper & Keys
x/ibcratelimit/keeper/keeper.go, x/ibcratelimit/keys.go
Replaced direct KVStore access with store.KVStoreService and a collections.Schema. Added ParamsItem (collections.Item[ibcratelimit.Params]) and ParamsKeyPrefix. Updated NewKeeper signature and GetParams/SetParams to use collections; SetParams now returns error.
App wiring
app/app.go
Updated RateLimitingKeeper construction to pass a KVStoreService wrapper (instead of StoreKey) into the keeper.
Genesis & Msg Server
x/ibcratelimit/keeper/genesis.go, x/ibcratelimit/keeper/msg_server.go
InitGenesis and UpdateParams now handle and propagate the error returned by SetParams; InitGenesis panics on failure.
Tests
testutil/ibc/testchain.go
RegisterRateLimiterContract now checks and asserts the error returned by SetParams instead of ignoring it.
Changelog
.changelog/unreleased/features/2493-collections-ibcratelimit.md
Added changelog entry documenting the migration to collections for the ibcratelimit module.

Sequence Diagram(s)

sequenceDiagram
participant App as App (module wiring)
participant Keeper as ibcratelimit.Keeper
participant Schema as collections.Schema
participant Store as KVStoreService

App->>Keeper: NewKeeper(storeService, ...)
note right of Keeper: builds Schema (collections.NewSchemaBuilder)\ninitializes ParamsItem
Keeper->>Schema: ParamsItem.Set(ctx, params)
Schema->>Store: persist params under prefix
note left of App: During InitGenesis / UpdateParams
App->>Keeper: InitGenesis calls SetParams(ctx, params)
Keeper->>ParamsItem: Set(ctx, params)
ParamsItem->>Store: write params
Store-->>Keeper: ack / error
Keeper-->>App: return error (propagated) or success
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

"I hopped through keys and schema bright,
Replaced raw stores with collections' light.
Params snug in items, tidy and neat,
State hops along on four little feet! 🐇"

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Switch to collections in the ibcratelimit module' directly and clearly summarizes the main change across all files in the changeset.
Linked Issues check ✅ Passed The PR successfully implements the primary objective from issue #2493: replacing state storage in x/ibcratelimit with Cosmos SDK collections throughout keeper, genesis, and related files.
Out of Scope Changes check ✅ Passed All changes are directly scoped to switching x/ibcratelimit to collections: KVStoreService replacement, collections schema implementation, error handling updates, and supporting infrastructure modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/collections-ibcratelimit
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can make CodeRabbit's review stricter and more nitpicky using the `assertive` profile, if that's what you prefer.

Change the reviews.profile setting to assertive to make CodeRabbit's nitpick more issues in your PRs.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
x/ibcratelimit/keeper/keeper.go (1)

26-30: Keep the collection handles unexported unless another package needs them.

Exposing Schema and ParamsItem makes the keeper's storage layout part of its public API for no obvious gain.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@x/ibcratelimit/keeper/keeper.go` around lines 26 - 30, The keeper exposes
storage handles Schema and ParamsItem which should be unexported; rename those
fields to schema and paramsItem on the keeper struct (and update any
constructor/initializer and internal references to use schema and paramsItem) so
the storage layout is not part of the public API, and ensure any external access
uses exported getter methods if needed rather than direct field access.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@x/ibcratelimit/keeper/genesis.go`:
- Around line 28-30: The panic message in InitGenesis (inside the k.SetParams
error handling) contains a typo "ibctatelimit" making failures hard to search;
update the fmt.Errorf string used in the panic to the correct module name
"ibcratelimit" (i.e., change the message passed to panic(fmt.Errorf(...)) in the
k.SetParams error block), and scan the InitGenesis function (and nearby error
messages) for any other occurrences of the misspelled module name to correct
them similarly.

In `@x/ibcratelimit/keeper/keeper.go`:
- Around line 69-76: The current Get path masks collections.ErrNotFound by
returning ibcratelimit.DefaultParams(), hiding migration/deserialization errors;
change the behavior in the ParamsItem.Get handling so that when err != nil you
do not convert ErrNotFound into a default—return the original err (i.e., remove
the special-case that returns DefaultParams on errors from k.ParamsItem.Get) and
update callers such as ExportGenesis and the params query to handle and
propagate that error, or alternatively add a unit test that verifies older
on-chain param bytes deserialize correctly with the new format (testing
k.ParamsItem.Get round-trip) if you intentionally want backward compatibility.

In `@x/ibcratelimit/keeper/msg_server.go`:
- Around line 40-42: The error returned when calling k.SetParams(ctx,
msg.Params) in the UpdateParams handler currently contains a misspelling and the
wrong operation name; update the fmt.Errorf message inside UpdateParams (the
code that wraps the error from k.SetParams) to correctly spell "ibcratelimit"
and to say "failed to set ibcratelimit params during UpdateParams" (reference:
method UpdateParams, call k.SetParams).

---

Nitpick comments:
In `@x/ibcratelimit/keeper/keeper.go`:
- Around line 26-30: The keeper exposes storage handles Schema and ParamsItem
which should be unexported; rename those fields to schema and paramsItem on the
keeper struct (and update any constructor/initializer and internal references to
use schema and paramsItem) so the storage layout is not part of the public API,
and ensure any external access uses exported getter methods if needed rather
than direct field access.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 023d5c91-0705-4441-97cf-5ba33b6e4d2b

📥 Commits

Reviewing files that changed from the base of the PR and between 7f33589 and e4d088d.

📒 Files selected for processing (7)
  • .changelog/unreleased/features/2493-collections-ibcratelimit.md
  • app/app.go
  • testutil/ibc/testchain.go
  • x/ibcratelimit/keeper/genesis.go
  • x/ibcratelimit/keeper/keeper.go
  • x/ibcratelimit/keeper/msg_server.go
  • x/ibcratelimit/keys.go

Comment thread x/ibcratelimit/keeper/genesis.go
Comment thread x/ibcratelimit/keeper/keeper.go
Comment thread x/ibcratelimit/keeper/msg_server.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
x/ibcratelimit/keeper/keeper.go (1)

4-4: Collapse the redundant ErrNotFound branch in GetParams.

The current conditional returns the same value for all errors, so the special-case adds noise without behavior change.

♻️ Suggested simplification
 import (
-	"errors"
 	"fmt"
@@
 func (k Keeper) GetParams(ctx sdk.Context) (params ibcratelimit.Params, err error) {
 	params, err = k.ParamsItem.Get(ctx)
 	if err != nil {
-		if errors.Is(err, collections.ErrNotFound) {
-			return ibcratelimit.Params{}, err
-		}
 		return ibcratelimit.Params{}, err
 	}
 	return params, nil
 }

Also applies to: 70-74

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@x/ibcratelimit/keeper/keeper.go` at line 4, The GetParams function currently
checks for sdkerrors.ErrNotFound and returns the same (nil, false, nil) result
as the generic error branch; collapse the redundant branch by removing the
ErrNotFound special-case and handling all errors uniformly: on any error from
k.paramstore.Get (including ErrNotFound) return (nil, false, nil) or the
intended canonical response, leaving a single error-check path; update both
occurrences referenced (GetParams and the similar block around lines 70-74) so
only one conditional handles non-nil errors from paramstore.Get.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@x/ibcratelimit/keeper/keeper.go`:
- Line 4: The GetParams function currently checks for sdkerrors.ErrNotFound and
returns the same (nil, false, nil) result as the generic error branch; collapse
the redundant branch by removing the ErrNotFound special-case and handling all
errors uniformly: on any error from k.paramstore.Get (including ErrNotFound)
return (nil, false, nil) or the intended canonical response, leaving a single
error-check path; update both occurrences referenced (GetParams and the similar
block around lines 70-74) so only one conditional handles non-nil errors from
paramstore.Get.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bc7ed41c-29fa-4d60-9638-6a08ca1801b2

📥 Commits

Reviewing files that changed from the base of the PR and between e4d088d and 5c5e0ed.

📒 Files selected for processing (3)
  • x/ibcratelimit/keeper/genesis.go
  • x/ibcratelimit/keeper/keeper.go
  • x/ibcratelimit/keeper/msg_server.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • x/ibcratelimit/keeper/msg_server.go

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.

Switch to collections in the ibcratelimit module.

1 participant