Skip to content

fix: use loaded addresses to refresh restricted address book#3971

Merged
ws4charlie merged 2 commits intodevelopfrom
fix-sherlock-79
Jun 12, 2025
Merged

fix: use loaded addresses to refresh restricted address book#3971
ws4charlie merged 2 commits intodevelopfrom
fix-sherlock-79

Conversation

@ws4charlie
Copy link
Contributor

@ws4charlie ws4charlie commented Jun 10, 2025

Description

The original code seems to be a typo and it still uses the old compliance config in zetaclient_config.json rather than the dedicated zetaclient_restricted_addresses.json file. Newly added addresses in zetaclient_restricted_addresses.json will be ignored by the zetaclients.

original code:

for _, addr := range cfg.ComplianceConfig.RestrictedAddresses {
	restrictedAddressBook[strings.ToLower(addr)] = true
}

modified code:

for _, addr := range addresses {
	restrictedAddressBook[strings.ToLower(addr)] = true
}

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

  • Bug Fixes

    • Resolved an issue where restricted addresses were not properly loaded from the configuration file, ensuring correct handling of restricted addresses.
  • Tests

    • Added new tests to verify that restricted addresses are accurately loaded from the configuration file.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 10, 2025

📝 Walkthrough

Walkthrough

The changes introduce a thread-safe method to retrieve restricted addresses and correct the loading logic to ensure addresses are sourced from the appropriate configuration file. A dedicated test validates the correct loading and retrieval of restricted addresses. The changelog is updated to document this fix.

Changes

File(s) Change Summary
zetaclient/config/config.go Added GetRestrictedAddresses() for thread-safe access; fixed loading logic to use the correct address source.
zetaclient/config/config_test.go Introduced tests to verify correct loading and retrieval of restricted addresses from configuration file.
changelog.md Added a fix entry documenting the correct loading of restricted addresses from the configuration file.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Suite
    participant Config as config.go
    participant File as Restricted Address File

    Test->>File: Write test restricted addresses to JSON file
    Test->>Config: Call LoadRestrictedAddressesConfig(basePath)
    Config->>File: Read zetaclient_restricted_addresses.json
    File-->>Config: Return restricted addresses (JSON)
    Config->>Config: Store addresses in restrictedAddressBook (lowercased)
    Test->>Config: Call GetRestrictedAddresses()
    Config-->>Test: Return all restricted addresses as []string
    Test->>Test: Assert addresses match expected (case-insensitive)
Loading

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this 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.

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.

@ws4charlie ws4charlie added zetaclient Issues related to ZetaClient bug labels Jun 10, 2025
@ws4charlie ws4charlie marked this pull request as ready for review June 10, 2025 20:51
@ws4charlie ws4charlie requested a review from a team as a code owner June 10, 2025 20:51
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

🔭 Outside diff range comments (1)
zetaclient/config/config.go (1)

128-135: ⚠️ Potential issue

Global map reassignment is racy – copy instead of replace

SetRestrictedAddressesFromConfig replaces the entire restrictedAddressBook map without any lock.
If another goroutine is concurrently reading through ContainRestrictedAddress() (which only takes an RLock), a data race occurs because the map pointer itself changes outside the lock.

Instead of swapping the map pointer, clear & repopulate the existing map under a full write-lock:

-func SetRestrictedAddressesFromConfig(cfg Config) {
-	restrictedAddressBook = cfg.GetRestrictedAddressBook()
+func SetRestrictedAddressesFromConfig(cfg Config) {
+	restrictedAddressBookLock.Lock()
+	defer restrictedAddressBookLock.Unlock()
+
+	// purge current entries
+	for k := range restrictedAddressBook {
+		delete(restrictedAddressBook, k)
+	}
+
+	// copy from config
+	for k := range cfg.GetRestrictedAddressBook() {
+		restrictedAddressBook[strings.ToLower(k)] = true
+	}
 }

This keeps the same map instance and removes the race.
Consider adding a unit test that runs SetRestrictedAddressesFromConfig in parallel with ContainRestrictedAddress using the -race flag to confirm.

🧹 Nitpick comments (4)
zetaclient/config/config.go (1)

96-106: Pre-allocate slice & keep result deterministic

Map size is already known, so allocate the slice up-front – this avoids an extra allocation and makes intent explicit.
Optionally, sorting guarantees deterministic ordering which is handy for logging and tests.

-	addresses := []string{}
+	addresses := make([]string, 0, len(restrictedAddressBook))
 	for addr := range restrictedAddressBook {
 		addresses = append(addresses, addr)
 	}
+	// sort.Strings(addresses) // <- optional, but recommended
zetaclient/config/config_test.go (2)

16-45: Enable test parallelisation for faster suite

The test has no shared state with others once the temp dir is unique, so it can safely run in parallel.

-func Test_LoadRestrictedAddressesConfig(t *testing.T) {
+func Test_LoadRestrictedAddressesConfig(t *testing.T) {
+	t.Parallel()

47-62: Mark helper as t.Helper() for cleaner stack traces

Marking the helper clarifies intent and produces nicer failure messages.

-func createRestrictedAddressesConfig(t *testing.T, basePath string, addresses []string) {
+func createRestrictedAddressesConfig(t *testing.T, basePath string, addresses []string) {
+	t.Helper()
changelog.md (1)

16-16: Update changelog entry for clarity and consistency

The entry should adopt the imperative style and explicitly note the file being replaced. For example:

- * [3971](https://github.com/zeta-chain/node/pull/3971) - zetaclient should load restricted addresses correctly from `zetaclient_restricted_addresses.json`
+ * [3971](https://github.com/zeta-chain/node/pull/3971) - load restricted addresses from `zetaclient_restricted_addresses.json` instead of `zetaclient_config.json`
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d17c8b3 and bef64ad.

📒 Files selected for processing (3)
  • changelog.md (1 hunks)
  • zetaclient/config/config.go (2 hunks)
  • zetaclient/config/config_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

**/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

  • zetaclient/config/config.go
  • zetaclient/config/config_test.go
🧬 Code Graph Analysis (1)
zetaclient/config/config_test.go (2)
testutil/sample/zetaclient.go (4)
  • RestrictedEVMAddressTest (11-11)
  • RestrictedBtcAddressTest (12-12)
  • RestrictedSolAddressTest (13-13)
  • RestrictedSuiAddressTest (14-14)
zetaclient/config/config.go (2)
  • LoadRestrictedAddressesConfig (141-147)
  • GetRestrictedAddresses (97-106)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: build-zetanode
  • GitHub Check: gosec
  • GitHub Check: lint
  • GitHub Check: build-and-test
  • GitHub Check: analyze (go)
  • GitHub Check: build

@codecov
Copy link

codecov bot commented Jun 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.21%. Comparing base (d17c8b3) to head (bef64ad).
Report is 3 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3971      +/-   ##
===========================================
+ Coverage    64.13%   64.21%   +0.08%     
===========================================
  Files          474      474              
  Lines        34863    34872       +9     
===========================================
+ Hits         22358    22393      +35     
+ Misses       11479    11448      -31     
- Partials      1026     1031       +5     
Files with missing lines Coverage Δ
zetaclient/config/config.go 19.87% <100.00%> (+19.87%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

LGTM

@ws4charlie ws4charlie added this pull request to the merge queue Jun 12, 2025
Merged via the queue into develop with commit 9a87da6 Jun 12, 2025
56 of 62 checks passed
@ws4charlie ws4charlie deleted the fix-sherlock-79 branch June 12, 2025 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

zetaclient Issues related to ZetaClient

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants