Skip to content
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

fix(zetaclient): orchestrator: signer resolution #3139

Merged
merged 4 commits into from
Nov 12, 2024

Conversation

swift1337
Copy link
Contributor

@swift1337 swift1337 commented Nov 11, 2024

Closes #3096

Summary by CodeRabbit

  • New Features

    • Introduced Whitelist message capability for SPL tokens.
    • Integrated SPL deposits functionality.
  • Improvements

    • Enhanced build reproducibility.
    • Improved error handling and logging for address updates.
  • Bug Fixes

    • Resolved configuration issues in the orchestrator.
    • Prevented blocked CCTX on out-of-gas scenarios during omnichain calls.
  • Refactor

    • Simplified address handling logic for Ethereum-related operations.
    • Removed unnecessary checks in the SetGatewayAddress methods across various chains.

Copy link
Contributor

coderabbitai bot commented Nov 11, 2024

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.

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request includes updates to the changelog, reflecting various enhancements, tests, refactoring, and fixes across the codebase. Key changes include the introduction of a Whitelist message capability for SPL tokens, improvements to build reproducibility, and the integration of SPL deposits. The logging mechanisms in the Signer struct methods were enhanced, and several methods were refactored for better performance and thread safety. Additionally, the orchestrator's handling of Ethereum addresses was simplified, addressing logging issues related to address updates.

Changes

File Path Change Summary
changelog.md Updated to include new features, improvements, tests, refactors, and fixes across the codebase.
zetaclient/chains/evm/signer/signer.go Enhanced logging in SetZetaConnectorAddress, SetERC20CustodyAddress, and SetGatewayAddress. Updated parameter type for SetGatewayAddress. Removed locking from getters.
zetaclient/chains/solana/signer/signer.go Improved logging and checks in SetGatewayAddress. Simplified GetGatewayAddress by removing locking.
zetaclient/chains/ton/signer/signer.go Added early return condition and logging in SetGatewayAddress.
zetaclient/orchestrator/orchestrator.go Renamed import from ethcommon to eth. Simplified address update logic in resolveSigner.

Assessment against linked issues

Objective Addressed Explanation
Ensure addresses are set only if not empty (3096)
Ensure addresses are not equal to current addresses (3096)

Possibly related PRs

Suggested labels

nosec, ADMIN_TESTS

Suggested reviewers

  • fbac
  • kingpinXD
  • skosito
  • lumtis
  • brewmaster012
  • ws4charlie

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • 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 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.

@swift1337 swift1337 force-pushed the fix/orchestrator-logging branch from 98d4030 to c1c1404 Compare November 11, 2024 18:10
@swift1337 swift1337 marked this pull request as ready for review November 11, 2024 18:10
@swift1337 swift1337 self-assigned this Nov 11, 2024
@swift1337 swift1337 added UPGRADE_LIGHT_TESTS Run make start-upgrade-test-light TON_TESTS Runs TON E2E tests labels Nov 11, 2024
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: 5

🧹 Outside diff range and nitpick comments (9)
zetaclient/chains/solana/signer/signer.go (3)

283-286: Optimize lock scope for better concurrency

The lock scope can be reduced to only wrap the critical section where shared state is modified.

-	signer.Lock()
-	signer.gatewayID = gatewayID
-	signer.pda = pda
-	signer.Unlock()
+	func() {
+		signer.Lock()
+		defer signer.Unlock()
+		signer.gatewayID = gatewayID
+		signer.pda = pda
+	}()

269-271: Enhance error logging structure

Consider using structured logging fields for better error tracking and analysis.

-		signer.Logger().Std.Error().Err(err).Str("address", address).Msgf("Unable to parse gateway address")
+		signer.Logger().Std.Error().
+			Err(err).
+			Str("address", address).
+			Str("function", "SetGatewayAddress").
+			Msg("Unable to parse gateway address")

Refactoring needed: EVM-specific functions should be removed from interface

The verification reveals a deeper architectural issue:

  • The ChainSigner interface in zetaclient/chains/interfaces/interfaces.go requires all chain implementations (EVM, Bitcoin, Solana, TON) to implement EVM-specific methods
  • These methods are only meaningfully used in EVM chains, as evidenced by empty implementations in Bitcoin, Solana, and TON signers
  • The orchestrator (zetaclient/orchestrator/orchestrator.go) only calls these methods for EVM chains

Recommended actions:

  • Extract EVM-specific methods into a separate EVMChainSigner interface
  • Update the ChainSigner interface to remove these methods
  • Modify the orchestrator to use type assertion for EVM-specific operations
🔗 Analysis chain

Line range hint 313-332: Verify the timeline for removing EVM-specific functions

These EVM-specific functions in the Solana signer violate interface segregation principle. While they are properly tracked for removal in issue #2532, let's verify the removal plan.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the status of issue #2532 and find any dependent code
gh issue view 2532

# Find any usage of these functions in the codebase
rg -A 2 "SetZetaConnectorAddress|SetERC20CustodyAddress|GetZetaConnectorAddress|GetERC20CustodyAddress" \
  --type go \
  --glob '!zetaclient/chains/solana/signer/signer.go'

Length of output: 8041

zetaclient/chains/ton/signer/signer.go (2)

281-281: LGTM! Consider enhancing error logging.

The guard clause correctly prevents unnecessary updates when the address is empty or unchanged. This aligns with the PR objectives and maintains thread safety.

Consider adding debug logging for skipped updates to aid in troubleshooting:

 if addr == "" || s.gateway.AccountID().ToRaw() == addr {
+    s.Logger().Std.Debug().
+        Str("addr", addr).
+        Str("current_addr", s.gateway.AccountID().ToRaw()).
+        Msg("Skipping gateway address update")
     return
 }

291-295: LGTM! Consider enhancing log message clarity.

The structured logging implementation provides excellent traceability by capturing both old and new addresses.

Consider making the log message more specific about the component being updated:

 s.Logger().Std.Info().
     Str("signer.old_gateway_address", s.gateway.AccountID().ToRaw()).
     Str("signer.new_gateway_address", acc.ToRaw()).
-    Msg("Updated gateway address")
+    Msg("TON signer gateway address updated")
zetaclient/chains/evm/signer/signer.go (3)

111-114: Improve comment clarity for early return conditions.

The comment "noop" doesn't effectively describe the conditions for early return. Consider being more explicit about the validation checks.

-	// noop
+	// Skip if the address is zero or unchanged

128-131: Improve comment clarity for early return conditions.

The comment "noop" doesn't effectively describe the conditions for early return. Consider being more explicit about the validation checks.

-	// noop
+	// Skip if the address is zero or unchanged

147-150: Improve comment clarity for early return conditions.

The comment "noop" doesn't effectively describe the conditions for early return. Consider being more explicit about the validation checks.

-	// noop
+	// Skip if the address is zero or unchanged
changelog.md (1)

23-23: Consider enhancing the changelog entry with more details.

The current entry "fix config resolution in orchestrator" could be more descriptive. Consider adding details about:

  • What specific configuration issue was fixed
  • The impact of the fix on the orchestrator's behavior
  • Any notable changes in configuration handling

Example:

-* [3139](https://github.com/zeta-chain/node/pull/3139) - fix config resolution in orchestrator
+* [3139](https://github.com/zeta-chain/node/pull/3139) - fix signer address resolution in orchestrator to ensure proper address validation and comparison
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7c70809 and c1c1404.

📒 Files selected for processing (5)
  • changelog.md (1 hunks)
  • zetaclient/chains/evm/signer/signer.go (1 hunks)
  • zetaclient/chains/solana/signer/signer.go (1 hunks)
  • zetaclient/chains/ton/signer/signer.go (2 hunks)
  • zetaclient/orchestrator/orchestrator.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
zetaclient/chains/evm/signer/signer.go (1)

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

zetaclient/chains/solana/signer/signer.go (1)

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

zetaclient/chains/ton/signer/signer.go (1)

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

zetaclient/orchestrator/orchestrator.go (1)

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

🔇 Additional comments (4)
zetaclient/chains/ton/signer/signer.go (1)

Line range hint 281-297: Consider potential race condition in address comparison.

There's a potential race condition between checking the current gateway address and updating it. While the current implementation is functionally correct due to the idempotent nature of the operation, consider moving the comparison inside the lock for strict thread safety.

Consider this alternative implementation:

 func (s *Signer) SetGatewayAddress(addr string) {
-    if addr == "" || s.gateway.AccountID().ToRaw() == addr {
+    if addr == "" {
+        s.Logger().Std.Debug().Str("addr", addr).Msg("Skipping empty gateway address update")
         return
     }
 
     acc, err := ton.ParseAccountID(addr)
     if err != nil {
         s.Logger().Std.Error().Err(err).Str("addr", addr).Msg("unable to parse gateway address")
         return
     }
 
     s.Lock()
+    if s.gateway.AccountID().ToRaw() == addr {
+        s.Logger().Std.Debug().Str("addr", addr).Msg("Skipping unchanged gateway address")
+        s.Unlock()
+        return
+    }
+
     s.Logger().Std.Info().
         Str("signer.old_gateway_address", s.gateway.AccountID().ToRaw()).
         Str("signer.new_gateway_address", acc.ToRaw()).
-        Msg("Updated gateway address")
+        Msg("TON signer gateway address updated")
 
-    s.Lock()
     s.gateway = toncontracts.NewGateway(acc)
     s.Unlock()
 }

Let's verify the thread safety of this method:

✅ Verification successful

Let me gather more information about concurrent access patterns to the gateway field.


Race condition concern is valid but impact is minimal due to design.

The code analysis reveals that while there is a theoretical race condition between the address comparison and update, the practical impact is minimal because:

  1. The gateway field is protected by mutex in critical sections
  2. The operation is idempotent - multiple identical updates result in the same final state
  3. The gateway is primarily read in GetGatewayAddress() and ProcessOutbound(), both properly synchronized

However, the suggested refactoring would indeed provide stricter thread safety and better logging. The proposed changes are production-grade improvements.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for concurrent access patterns to gateway address
# Look for other goroutines or concurrent operations that might access the gateway address

# Search for gateway address access patterns
rg -A 5 "gateway.*ToRaw\(\)" --type go

# Search for concurrent patterns (goroutines, channels) near gateway usage
rg -B 5 -A 5 "go\s+func|select|chan" --type go | rg -B 5 -A 5 "gateway"

Length of output: 6908


Script:

#!/bin/bash
# Check for all methods accessing the gateway field
ast-grep --pattern 's.gateway'

# Check for any concurrent operations in the Signer type
rg -B 10 -A 10 'type Signer struct' zetaclient/chains/ton/signer/signer.go

# Look for other methods that might use the gateway concurrently
rg -l 'func.*Signer.*\{' zetaclient/chains/ton/signer/signer.go | xargs cat

Length of output: 10283

zetaclient/orchestrator/orchestrator.go (2)

12-12: LGTM: Import alias simplification

The simplified import alias improves readability while maintaining the same functionality.


171-171: Consider validating gateway addresses for Solana and TON

The gateway address setting for Solana and TON chains lacks validation. Consider adding chain-specific address validation to prevent issues with invalid addresses.

Let's verify the address validation in the respective chain implementations:

Also applies to: 173-173

changelog.md (1)

Line range hint 1-1000: LGTM! Well-structured changelog.

The changelog follows best practices with:

  • Clear version sections
  • Consistent categorization of changes
  • Proper PR linking
  • Reverse chronological ordering

zetaclient/chains/evm/signer/signer.go Show resolved Hide resolved
zetaclient/chains/evm/signer/signer.go Show resolved Hide resolved
zetaclient/chains/evm/signer/signer.go Show resolved Hide resolved
zetaclient/chains/evm/signer/signer.go Show resolved Hide resolved
zetaclient/orchestrator/orchestrator.go Show resolved Hide resolved
Copy link
Member

@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

zetaclient/chains/solana/signer/signer.go Outdated Show resolved Hide resolved
@swift1337 swift1337 enabled auto-merge November 12, 2024 11:58
Copy link

codecov bot commented Nov 12, 2024

Codecov Report

Attention: Patch coverage is 45.76271% with 32 lines in your changes missing coverage. Please review.

Project coverage is 63.08%. Comparing base (1738618) to head (d521d58).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
zetaclient/chains/evm/signer/signer.go 41.17% 18 Missing and 2 partials ⚠️
zetaclient/chains/solana/signer/signer.go 57.14% 4 Missing and 2 partials ⚠️
zetaclient/chains/ton/signer/signer.go 0.00% 6 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3139      +/-   ##
===========================================
- Coverage    63.15%   63.08%   -0.07%     
===========================================
  Files          423      423              
  Lines        29872    29875       +3     
===========================================
- Hits         18865    18848      -17     
- Misses       10169    10186      +17     
- Partials       838      841       +3     
Files with missing lines Coverage Δ
zetaclient/orchestrator/orchestrator.go 18.56% <100.00%> (-3.91%) ⬇️
zetaclient/chains/solana/signer/signer.go 29.72% <57.14%> (-0.22%) ⬇️
zetaclient/chains/ton/signer/signer.go 45.12% <0.00%> (-1.42%) ⬇️
zetaclient/chains/evm/signer/signer.go 46.11% <41.17%> (-0.72%) ⬇️

@swift1337 swift1337 added this pull request to the merge queue Nov 12, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 12, 2024
@swift1337 swift1337 added this pull request to the merge queue Nov 12, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 12, 2024
@swift1337 swift1337 removed TON_TESTS Runs TON E2E tests UPGRADE_LIGHT_TESTS Run make start-upgrade-test-light labels Nov 12, 2024
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.

zetaclient: fix logging in orchestrator
4 participants