Skip to content

chore: fix lint issues in the node repo#4549

Open
kingpinXD wants to merge 3 commits intomainfrom
chore-fix-lints
Open

chore: fix lint issues in the node repo#4549
kingpinXD wants to merge 3 commits intomainfrom
chore-fix-lints

Conversation

@kingpinXD
Copy link
Member

@kingpinXD kingpinXD commented Feb 24, 2026

Description

Fix all lint issues

How Has This Been Tested?

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

Note

Low Risk
Mechanical lint-driven changes (slice preallocation and minor formatting) with no intended behavior changes; low risk aside from potential subtle differences if any code relied on nil vs empty slices.

Overview
Primarily resolves lint findings by replacing nil/empty slice declarations with make(..., 0, cap) preallocations across CLI tools, E2E tests, Solana/Bitcoin helpers, simulation genesis builders, and module key/keeper utilities.

Updates .golangci.yml to ignore two revive var-naming warnings, and makes a few small mechanical tweaks (e.g., preallocating proposal handler list in app/app.go, formatting long function calls) without changing behavior.

Written by Cursor Bugbot for commit b94b621. Configure here.

Summary by CodeRabbit

  • Chores

    • Enhanced code quality standards with new linting rules for naming conventions.
  • Refactor

    • Optimized memory allocation patterns across the codebase for improved performance.
  • Style

    • Code formatting improvements for consistency.

@kingpinXD kingpinXD requested a review from a team as a code owner February 24, 2026 17:16
@kingpinXD kingpinXD added the no-changelog Skip changelog CI check label Feb 24, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 24, 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

This pull request systematically pre-allocates slice capacity across 24 files throughout the codebase. Instead of initializing empty or nil slices and letting them grow dynamically, changes specify initial capacity using make() when the expected size is known, reducing memory reallocations during appends.

Changes

Cohort / File(s) Summary
Build Configuration
.golangci.yml
Added two new revive linter rules for var-naming validation (standard library package name conflicts and meaningless package names).
Core Application
app/app.go, cmd/zetacore_utils/main.go, cmd/zetatool/cctx/cctx_details.go
Pre-allocated slice capacity for govProposalHandlers, args, and hashList variables to avoid reallocations during appends.
CLI & Formatting
cmd/zetatool/cli/tss_balances.go
Reformatted function calls across multiple lines with trailing commas; no functional changes.
E2E Test Utilities
e2e/e2etests/test_crosschain_swap.go, e2e/e2etests/test_solana_withdraw_and_call_alt.go, e2e/e2etests/test_spl_withdraw_and_call_alt.go, e2e/runner/e2etest.go, e2e/runner/setup_bitcoin.go, e2e/runner/setup_solana.go, e2e/runner/solana.go, e2e/runner/solana_gateway_upgrade.go, e2e/utils/zetacore.go
Pre-allocated slice capacity across test utilities for msg, accounts, writableIndexes, randomWallets, tests, argsRawMsg, accountMeta, randomWalletsAta, and hashes variables to optimize memory allocation.
Solana Gateway Contracts
pkg/contracts/solana/gateway_message.go
Pre-allocated message buffer capacity in Hash() methods for multiple message types (MsgWithdraw, MsgTransfer, MsgWhitelist, MsgWithdrawSPL) based on expected field sizes.
Bitcoin Cryptography
pkg/proofs/bitcoin/bitcoin_spv.go
Pre-allocated proof and intermediate hash slices with capacity based on combined input sizes to reduce allocations in SPV proof construction.
State Simulation
simulation/state.go
Pre-allocated capacity for tssHistory, chainsNonces, pendingNonces, and foreignCoins slices aligned with expected element counts.
Cross-chain Module
x/crosschain/keeper/foreign_coins.go, x/crosschain/types/key_inbound_hash_to_cctx.go, x/crosschain/types/keys.go
Pre-allocated fCoins and key slices with appropriate capacity based on chains count or byte concatenation size.
Fungible & Configuration
x/fungible/types/key_foreign_coins.go, zetaclient/config/config.go
Pre-allocated key and address slices with capacity matching expected element counts to eliminate reallocations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The PR description is minimal and lacks substantive detail about the lint issues being fixed, their impact, and testing verification. Expand the description to specify which lint rules were addressed, document the rationale for slice pre-allocation optimizations across the codebase, and mark completed testing checkboxes to confirm the changes have been validated.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the primary change: fixing lint issues across the repository through mechanical optimizations and configuration updates.

✏️ 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
  • Commit unit tests in branch chore-fix-lints

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.

@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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)
e2e/e2etests/test_crosschain_swap.go (1)

86-96: Incomplete preallocation — one reallocation still occurs at line 96.

The capacity len(r.ZEVMSwapAppAddr.Bytes()) (20 bytes) only covers the first append. When memobytes is appended at line 96 the slice must reallocate. Computing memobytes first allows a fully precise capacity hint.

♻️ Proposed refactor to eliminate the remaining reallocation
-	msg := make([]byte, 0, len(r.ZEVMSwapAppAddr.Bytes()))
-	msg = append(msg, r.ZEVMSwapAppAddr.Bytes()...)
-	memobytes, err := r.ZEVMSwapApp.EncodeMemo(
+	memobytes, err := r.ZEVMSwapApp.EncodeMemo(
 		&bind.CallOpts{},
 		r.BTCZRC20Addr,
 		[]byte(r.GetBtcAddress().EncodeAddress()),
 	)
 	require.NoError(r, err)
 
 	r.Logger.Info("memobytes(%d) %x", len(memobytes), memobytes)
+	msg := make([]byte, 0, len(r.ZEVMSwapAppAddr.Bytes())+len(memobytes))
+	msg = append(msg, r.ZEVMSwapAppAddr.Bytes()...)
 	msg = append(msg, memobytes...)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@e2e/e2etests/test_crosschain_swap.go` around lines 86 - 96, The slice
preallocation for msg only uses len(r.ZEVMSwapAppAddr.Bytes()) so appending
memobytes forces a reallocation; call r.ZEVMSwapApp.EncodeMemo(...) first to get
memobytes and err, then create msg with capacity
len(r.ZEVMSwapAppAddr.Bytes())+len(memobytes), append the address bytes and
memobytes into msg, and keep the require.NoError and r.Logger.Info usage around
the EncodeMemo call; update references to memobytes, msg, r.ZEVMSwapAppAddr and
r.ZEVMSwapApp.EncodeMemo accordingly.
x/crosschain/types/key_inbound_hash_to_cctx.go (1)

14-16: LGTM on capacity; minor style note on single-byte append.

The capacity len(inboundHashBytes)+1 is exact and avoids any reallocation. On Line 16, spreading a slice literal for a single byte is unnecessary.

♻️ Proposed simplification
-	key = append(key, []byte("/")...)
+	key = append(key, '/')
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@x/crosschain/types/key_inbound_hash_to_cctx.go` around lines 14 - 16, The
code builds key with capacity len(inboundHashBytes)+1 then appends
inboundHashBytes and appends a single-byte separator using append(key,
[]byte("/")...), which is stylistically suboptimal; replace the spread of a
single-byte slice with append(key, '/') to append the single byte directly
(locate where variable key is created and the append of inboundHashBytes and the
separator in the function that handles inboundHashBytes).
x/crosschain/keeper/foreign_coins.go (1)

11-14: Capacity hint is a lower bound — may underestimate for chains with multiple foreign coins.

GetAllForeignCoinsForChain can return more than one coin per chain (e.g., a gas token plus registered ERC20 tokens), so len(chains) is a lower bound on the final slice size and reallocations may still occur. This is still a meaningful improvement over a nil slice. If profiling ever identifies this as a hot path, a pre-sizing pass or summation over GetAllForeignCoinsForChain counts could eliminate remaining reallocations.

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

In `@x/crosschain/keeper/foreign_coins.go` around lines 11 - 14, The capacity hint
for fCoins (created with make([]fungibleModuleTypes.ForeignCoins, 0,
len(chains))) underestimates when GetAllForeignCoinsForChain returns multiple
coins per chain; update the pre-sizing so it won't assume one coin per chain —
either perform a short pre-pass summing
len(k.fungibleKeeper.GetAllForeignCoinsForChain(ctx, chain.ChainId)) for each
chain to compute the exact capacity before make, or append into a nil slice (or
simple zero-cap slice) if you prefer simplicity; locate and change the
allocation around the fCoins variable and calls to
k.fungibleKeeper.GetAllForeignCoinsForChain(ctx, chain.ChainId) in
foreign_coins.go.
pkg/contracts/solana/gateway_message.go (1)

352-388: MsgExecute.Hash() and MsgExecuteSPL.Hash() still use var message []byte — consider a partial preallocation for consistency.

While the prealloc linter with its default simple: true setting does not flag these methods (their capacity depends on a conditional sender size and runtime-variable msg.data/remainingAccounts), all other Hash() implementations in the same file now preallocate. A base capacity covering the deterministic portion would align the file and reduce the initial growth cycle on the hot path.

♻️ Suggested partial preallocation for MsgExecute.Hash()
 func (msg *MsgExecute) Hash() [32]byte {
-	var message []byte
 	buff := make([]byte, 8)
+	// base: identifier(9) + instruction(1) + 3×uint64(24) + to(32) + max-sender(32) + data + accounts×32
+	baseCapacity := len(InstructionIdentifier) + 1 + 3*len(buff) + len(msg.to) + 32 + len(msg.data) + len(msg.remainingAccounts)*32
+	message := make([]byte, 0, baseCapacity)

Apply the same pattern to MsgExecuteSPL.Hash(), adding len(msg.mintAccount)+len(msg.recipientAta) to the base capacity.

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

In `@pkg/contracts/solana/gateway_message.go` around lines 352 - 388, The Hash
methods should preallocate the message slice with a deterministic base capacity
to avoid repeated growth: in MsgExecute.Hash() create message with make([]byte,
0, N) where N includes len(InstructionIdentifier)+1 (instruction byte)+8*3
(chainID, nonce, amount)+len(msg.to.Bytes())+max sender size (or the larger of
the two sender encodings) plus any fixed-size remainingAccounts count estimate
per account if known; do the same for MsgExecuteSPL.Hash() but add
len(msg.mintAccount)+len(msg.recipientAta) to the base capacity; update both
functions to use the preallocated slice before appending.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.golangci.yml:
- Around line 97-102: Remove the blanket revive exclusions under
linters.exclusions.rules that silence "var-naming: avoid package names that
conflict with Go standard library" and "var-naming: avoid meaningless package
names"; instead restore the full canonical message for the stdlib conflict entry
("avoid package names that conflict with Go standard library package names") and
reconfigure revive to handle package-name collisions via its option (e.g., set
skipPackageNameCollisionWithGoStd = true in revive config) or apply path-scoped
exclusions only for the specific offending directories, or fix offending package
names in code; ensure you remove the global text-based suppressions and replace
them with either the revive rule option, targeted exclusions, or inline
//nolint:revive on specific files.

---

Nitpick comments:
In `@e2e/e2etests/test_crosschain_swap.go`:
- Around line 86-96: The slice preallocation for msg only uses
len(r.ZEVMSwapAppAddr.Bytes()) so appending memobytes forces a reallocation;
call r.ZEVMSwapApp.EncodeMemo(...) first to get memobytes and err, then create
msg with capacity len(r.ZEVMSwapAppAddr.Bytes())+len(memobytes), append the
address bytes and memobytes into msg, and keep the require.NoError and
r.Logger.Info usage around the EncodeMemo call; update references to memobytes,
msg, r.ZEVMSwapAppAddr and r.ZEVMSwapApp.EncodeMemo accordingly.

In `@pkg/contracts/solana/gateway_message.go`:
- Around line 352-388: The Hash methods should preallocate the message slice
with a deterministic base capacity to avoid repeated growth: in
MsgExecute.Hash() create message with make([]byte, 0, N) where N includes
len(InstructionIdentifier)+1 (instruction byte)+8*3 (chainID, nonce,
amount)+len(msg.to.Bytes())+max sender size (or the larger of the two sender
encodings) plus any fixed-size remainingAccounts count estimate per account if
known; do the same for MsgExecuteSPL.Hash() but add
len(msg.mintAccount)+len(msg.recipientAta) to the base capacity; update both
functions to use the preallocated slice before appending.

In `@x/crosschain/keeper/foreign_coins.go`:
- Around line 11-14: The capacity hint for fCoins (created with
make([]fungibleModuleTypes.ForeignCoins, 0, len(chains))) underestimates when
GetAllForeignCoinsForChain returns multiple coins per chain; update the
pre-sizing so it won't assume one coin per chain — either perform a short
pre-pass summing len(k.fungibleKeeper.GetAllForeignCoinsForChain(ctx,
chain.ChainId)) for each chain to compute the exact capacity before make, or
append into a nil slice (or simple zero-cap slice) if you prefer simplicity;
locate and change the allocation around the fCoins variable and calls to
k.fungibleKeeper.GetAllForeignCoinsForChain(ctx, chain.ChainId) in
foreign_coins.go.

In `@x/crosschain/types/key_inbound_hash_to_cctx.go`:
- Around line 14-16: The code builds key with capacity len(inboundHashBytes)+1
then appends inboundHashBytes and appends a single-byte separator using
append(key, []byte("/")...), which is stylistically suboptimal; replace the
spread of a single-byte slice with append(key, '/') to append the single byte
directly (locate where variable key is created and the append of
inboundHashBytes and the separator in the function that handles
inboundHashBytes).

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 50aa497 and b94b621.

📒 Files selected for processing (22)
  • .golangci.yml
  • app/app.go
  • cmd/zetacore_utils/main.go
  • cmd/zetatool/cctx/cctx_details.go
  • cmd/zetatool/cli/tss_balances.go
  • e2e/e2etests/test_crosschain_swap.go
  • e2e/e2etests/test_solana_withdraw_and_call_alt.go
  • e2e/e2etests/test_spl_withdraw_and_call_alt.go
  • e2e/runner/e2etest.go
  • e2e/runner/setup_bitcoin.go
  • e2e/runner/setup_solana.go
  • e2e/runner/solana.go
  • e2e/runner/solana_gateway_upgrade.go
  • e2e/utils/zetacore.go
  • pkg/contracts/solana/gateway_message.go
  • pkg/proofs/bitcoin/bitcoin_spv.go
  • simulation/state.go
  • x/crosschain/keeper/foreign_coins.go
  • x/crosschain/types/key_inbound_hash_to_cctx.go
  • x/crosschain/types/keys.go
  • x/fungible/types/key_foreign_coins.go
  • zetaclient/config/config.go

Copy link
Contributor

@ws4charlie ws4charlie left a comment

Choose a reason for hiding this comment

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

lgtm

@kingpinXD kingpinXD marked this pull request as draft February 24, 2026 17:31
@kingpinXD kingpinXD marked this pull request as ready for review February 24, 2026 18:01
@kingpinXD kingpinXD enabled auto-merge February 24, 2026 18:02
@kingpinXD kingpinXD requested a review from a team as a code owner February 25, 2026 20:05
@github-actions github-actions bot added the ci Changes to CI pipeline or github actions label Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking:cli ci Changes to CI pipeline or github actions no-changelog Skip changelog CI check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants