Skip to content

refactor: use slices.Contains to simplify code#4545

Open
nuxtreact wants to merge 1 commit intozeta-chain:developfrom
nuxtreact:develop
Open

refactor: use slices.Contains to simplify code#4545
nuxtreact wants to merge 1 commit intozeta-chain:developfrom
nuxtreact:develop

Conversation

@nuxtreact
Copy link

@nuxtreact nuxtreact commented Feb 10, 2026

Description

There is a new function added in the go1.21 standard library, which can make the code more concise and easy to read.

How Has This Been Tested?

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Summary by CodeRabbit

  • Refactor

    • Optimized internal containment checks across multiple modules for improved code maintainability and performance.
  • Bug Fixes

    • Corrected topic matching behavior in subscription filtering to ensure accurate filter handling.

@nuxtreact nuxtreact requested a review from a team as a code owner February 10, 2026 15:33
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 10, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The pull request refactors six files to replace manual containment checks with the standard library slices.Contains() function. All changes involve adding the slices import and simplifying loop-based membership lookups, with one file introducing a semantic change to topic matching behavior.

Changes

Cohort / File(s) Summary
Standard Containment Refactoring
app/ante/vesting.go, cmd/zetaclientd/utils.go, cmd/zetae2e/local/monitor_priority_txs.go, x/crosschain/keeper/cctx.go, x/observer/keeper/observer_set.go
Replaced manual iteration loops with slices.Contains() for membership checks. All changes preserve original behavior while simplifying implementation. Added slices import to each file.
Ethereum RPC Filters
rpc/namespaces/ethereum/eth/filters/utils.go
Replaced per-topic matching logic with slices.Contains(). Critical semantic change: empty subscription lists are no longer treated as wildcards; topics now require explicit presence in the subscription for a match. Requires careful validation against intended filtering behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the primary change: replacing manual containment checks with slices.Contains across multiple files for code simplification.
Description check ✅ Passed The description adequately addresses the change motivation (leveraging Go 1.21's slices.Contains), includes relevant reference documentation, and provides testing completion status with specific checkboxes marked.

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

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

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

🤖 Fix all issues with AI agents
In `@rpc/namespaces/ethereum/eth/filters/utils.go`:
- Around line 40-44: The loop over topics currently uses slices0.Contains(sub,
log.Topics[i]) which returns false for empty sub-slices and breaks the wildcard
semantics; change the conditional in the topics loop (the block that references
topics, sub, and log.Topics[i]) to treat an empty sub as a match (e.g., if
len(sub) == 0 then consider it matched) and only call slices0.Contains when sub
is non-empty, mirroring the bloomFilter logic that uses included := len(sub) ==
0; preserve the existing control flow that uses the Logs label when a non-match
occurs.
🧹 Nitpick comments (1)
rpc/namespaces/ethereum/eth/filters/utils.go (1)

5-5: Consolidate dual slices imports to use only the standard library package.

The file imports both slices (standard library, aliased as slices0) and golang.org/x/exp/slices, with inconsistent usage: line 41 uses the unaliased experimental import while line 42 uses the aliased stdlib import. Since the project targets Go 1.23.8—well above the Go 1.21 requirement when stdlib slices became stable—the external dependency is redundant. Remove golang.org/x/exp/slices and unify both Contains() calls to use the stdlib slices package.

♻️ Consolidation
 import (
 	"math/big"
-	slices0 "slices"
+	"slices"
 
 	"github.com/ethereum/go-ethereum/common"
 	ethtypes "github.com/ethereum/go-ethereum/core/types"
-	"golang.org/x/exp/slices"
 )

Update line 41 (slices.Contains) and line 42 to use the unaliased slices.Contains.

Signed-off-by: nuxtreact <nuxtreact@outlook.com>
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.

1 participant