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

feat: implementation of Solana restricted address #2795

Merged
merged 7 commits into from
Sep 9, 2024

Conversation

ws4charlie
Copy link
Contributor

@ws4charlie ws4charlie commented Aug 29, 2024

Description

  • block any deposit that involves restricted addresses (sender or receiver).
  • block any withdrawal that involves restricted addresses (sender or receiver).
  • added E2E tests to make sure that above are working without issue.

Closes: #2604

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

  • New Features

    • Added support for restricted addresses in Solana, enhancing address management capabilities.
    • Introduced new end-to-end tests for Solana deposit and withdrawal to restricted addresses.
    • Added compliance checks in transaction processing to ensure adherence to restrictions.
  • Bug Fixes

    • Improved handling of withdrawal transactions by allowing cancellation based on compliance checks.
  • Documentation

    • Updated changelog to reflect the latest changes and enhancements.
  • Chores

    • Streamlined logging messages for clarity during contract deployments.

Copy link
Contributor

coderabbitai bot commented Aug 29, 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

The changes encompass the addition of support for restricted addresses in Solana, modifications to compliance configuration handling, and enhancements to end-to-end testing for various blockchain interactions. New test cases were introduced for restricted deposits and withdrawals, while existing tests were updated to utilize new sample configurations. Additionally, compliance checks were integrated into transaction processing methods, and logging messages were streamlined for clarity.

Changes

File Path Change Summary
changelog.md Added entry for support of restricted addresses in Solana as part of pull request 2795.
cmd/zetaclientd/init.go Changed source of ComplianceConfig from testutils to sample.
cmd/zetae2e/local/local.go Added two new test cases for restricted deposits and withdrawals in Solana.
e2e/e2etests/e2etests.go Introduced tests for deposits and withdrawals to restricted addresses; modified existing deposit test's amount.
e2e/e2etests/helpers.go Added verifySolanaWithdrawalAmountFromCCTX function for verifying withdrawal amounts from cross-chain transactions.
e2e/e2etests/test_bitcoin_withdraw_restricted_address.go Updated import path for RestrictedBtcAddressTest from testutils to sample.
e2e/e2etests/test_erc20_deposit_restricted_address.go Updated import path for RestrictedEVMAddressTest from testutils to sample.
e2e/e2etests/test_eth_withdraw_restricted_address.go Updated import path for RestrictedEVMAddressTest from testutils to sample.
e2e/e2etests/test_solana_deposit_restricted_address.go New test for depositing to a restricted Solana address.
e2e/e2etests/test_solana_withdraw_restricted_address.go New test for withdrawing from a restricted Solana address.
e2e/e2etests/test_zeta_deposit_restricted_address.go Updated import path for RestrictedEVMAddressTest from testutils to sample.
e2e/runner/poste2e_checker.go Introduced methods for verifying no outbound transaction trackers and ensuring zero balance on restricted addresses.
e2e/runner/setup_zeta.go Simplified logging messages in SetZEVMSystemContracts and SetZEVMZRC20s methods.
e2e/runner/solana.go Modified WithdrawSOLZRC20 method to return a pointer to CrossChainTx.
testutil/sample/zetaclient.go Added constants for restricted addresses and a new ComplianceConfig function for sample compliance configuration.
zetaclient/chains/solana/observer/outbound.go Added compliance check in VoteOutboundIfConfirmed function for restricted contexts.
zetaclient/chains/solana/signer/signer.go Integrated compliance check in TryProcessOutbound method; modified SignMsgWithdraw signature to include cancelTx parameter.
zetaclient/chains/solana/signer/withdraw.go Updated SignMsgWithdraw to include cancelTx parameter for conditional withdrawal behavior.
zetaclient/testutils/testdata.go Removed ComplianceConfigTest function and reorganized constants related to test data paths.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant E2ERunner
    participant Compliance
    participant Solana

    User->>E2ERunner: Initiate Deposit to Restricted Address
    E2ERunner->>Compliance: Check if address is restricted
    Compliance-->>E2ERunner: Address is restricted
    E2ERunner->>Solana: Execute Deposit Transaction
    Solana-->>E2ERunner: Confirm Deposit
    E2ERunner-->>User: Deposit Successful
Loading
sequenceDiagram
    participant User
    participant E2ERunner
    participant Compliance
    participant Solana

    User->>E2ERunner: Initiate Withdrawal from Restricted Address
    E2ERunner->>Compliance: Check if address is restricted
    Compliance-->>E2ERunner: Address is restricted
    E2ERunner->>Solana: Execute Withdrawal Transaction
    Solana-->>E2ERunner: Confirm Withdrawal
    E2ERunner-->>User: Withdrawal Successful
Loading

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

Copy link

codecov bot commented Aug 29, 2024

Codecov Report

Attention: Patch coverage is 0% with 17 lines in your changes missing coverage. Please review.

Project coverage is 66.90%. Comparing base (d210011) to head (05bd6f0).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
zetaclient/chains/solana/signer/signer.go 0.00% 13 Missing ⚠️
zetaclient/chains/solana/observer/outbound.go 0.00% 2 Missing ⚠️
zetaclient/chains/solana/signer/withdraw.go 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2795      +/-   ##
===========================================
- Coverage    66.94%   66.90%   -0.04%     
===========================================
  Files          370      370              
  Lines        20965    20977      +12     
===========================================
  Hits         14035    14035              
- Misses        6290     6302      +12     
  Partials       640      640              
Files with missing lines Coverage Δ
zetaclient/testutils/testdata.go 85.82% <ø> (+1.98%) ⬆️
zetaclient/chains/solana/observer/outbound.go 27.42% <0.00%> (-0.32%) ⬇️
zetaclient/chains/solana/signer/withdraw.go 0.00% <0.00%> (ø)
zetaclient/chains/solana/signer/signer.go 26.73% <0.00%> (-3.61%) ⬇️

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 26c4fb1 and caa6850.

Files selected for processing (19)
  • changelog.md (1 hunks)
  • cmd/zetaclientd/init.go (2 hunks)
  • cmd/zetae2e/local/local.go (1 hunks)
  • e2e/e2etests/e2etests.go (4 hunks)
  • e2e/e2etests/helpers.go (2 hunks)
  • e2e/e2etests/test_bitcoin_withdraw_restricted_address.go (2 hunks)
  • e2e/e2etests/test_erc20_deposit_restricted_address.go (2 hunks)
  • e2e/e2etests/test_eth_withdraw_restricted_address.go (2 hunks)
  • e2e/e2etests/test_solana_deposit_restricted_address.go (1 hunks)
  • e2e/e2etests/test_solana_withdraw_restricted_address.go (1 hunks)
  • e2e/e2etests/test_zeta_deposit_restricted_address.go (2 hunks)
  • e2e/runner/poste2e_checker.go (1 hunks)
  • e2e/runner/setup_zeta.go (2 hunks)
  • e2e/runner/solana.go (2 hunks)
  • testutil/sample/zetaclient.go (2 hunks)
  • zetaclient/chains/solana/observer/outbound.go (2 hunks)
  • zetaclient/chains/solana/signer/signer.go (2 hunks)
  • zetaclient/chains/solana/signer/withdraw.go (2 hunks)
  • zetaclient/testutils/testdata.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • e2e/runner/setup_zeta.go
Additional context used
Path-based instructions (17)
e2e/e2etests/test_zeta_deposit_restricted_address.go (1)

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

e2e/e2etests/test_erc20_deposit_restricted_address.go (1)

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

e2e/e2etests/test_solana_deposit_restricted_address.go (1)

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

e2e/e2etests/test_bitcoin_withdraw_restricted_address.go (1)

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

e2e/e2etests/test_solana_withdraw_restricted_address.go (1)

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

testutil/sample/zetaclient.go (1)

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

e2e/e2etests/test_eth_withdraw_restricted_address.go (1)

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

e2e/runner/poste2e_checker.go (1)

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

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

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

cmd/zetaclientd/init.go (1)

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

e2e/runner/solana.go (1)

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

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

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

zetaclient/chains/solana/observer/outbound.go (1)

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

cmd/zetae2e/local/local.go (1)

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

e2e/e2etests/e2etests.go (1)

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

GitHub Check: codecov/patch
zetaclient/chains/solana/signer/withdraw.go

[warning] 30-31: zetaclient/chains/solana/signer/withdraw.go#L30-L31
Added lines #L30 - L31 were not covered by tests

zetaclient/chains/solana/signer/signer.go

[warning] 131-142: zetaclient/chains/solana/signer/signer.go#L131-L142
Added lines #L131 - L142 were not covered by tests


[warning] 146-146: zetaclient/chains/solana/signer/signer.go#L146
Added line #L146 was not covered by tests

zetaclient/chains/solana/observer/outbound.go

[warning] 164-164: zetaclient/chains/solana/observer/outbound.go#L164
Added line #L164 was not covered by tests


[warning] 166-166: zetaclient/chains/solana/observer/outbound.go#L166
Added line #L166 was not covered by tests

Additional comments not posted (39)
e2e/e2etests/test_zeta_deposit_restricted_address.go (2)

8-8: LGTM!

The change in the import path is approved.


18-18: LGTM!

The change in the reference to the restricted address constant is approved.

e2e/e2etests/test_erc20_deposit_restricted_address.go (2)

8-8: LGTM!

The change in the import path is approved.


18-18: LGTM!

The change in the reference to the restricted address constant is approved.

e2e/e2etests/test_solana_deposit_restricted_address.go (5)

1-1: LGTM!

The package declaration is appropriate.


3-8: LGTM!

The import statements are appropriate.


10-12: LGTM!

The function declaration and initial checks are appropriate.


13-17: LGTM!

The parsing of the restricted address and deposit amount is appropriate.


19-20: LGTM!

The execution of the deposit transaction is appropriate.

e2e/e2etests/test_bitcoin_withdraw_restricted_address.go (2)

10-10: LGTM!

The import path change aligns with the new structure of the test utilities.


27-27: LGTM!

The usage of sample.RestrictedBtcAddressTest aligns with the new structure of the test utilities.

e2e/e2etests/test_solana_withdraw_restricted_address.go (3)

1-1: LGTM!

The package declaration is correct and aligns with the file's purpose.


3-12: LGTM!

The import statements are correct and necessary for the file's functionality.


14-35: LGTM!

The function TestSolanaWithdrawRestricted is well-structured and correctly implements the test for restricted address withdrawal.

testutil/sample/zetaclient.go (2)

9-14: LGTM!

The new constants for restricted addresses are correctly defined and enhance the testability of the code.


35-44: LGTM!

The new function ComplianceConfig is well-structured and correctly returns a sample compliance configuration.

e2e/e2etests/test_eth_withdraw_restricted_address.go (2)

11-11: LGTM!

The import statement change to use sample instead of testutils is clear and likely improves maintainability.


34-34: LGTM!

The function now references sample.RestrictedEVMAddressTest instead of testutils.RestrictedEVMAddressTest, which is consistent with the updated import statement.

e2e/runner/poste2e_checker.go (3)

16-25: LGTM!

The EnsureNoTrackers function is correctly implemented and ensures that no trackers are left at the end of the test.


27-47: LGTM!

The EnsureZeroBalanceOnRestrictedAddress function is correctly implemented and ensures that the balance of the restricted address is zero for various tokens.


49-61: LGTM!

The ensureZRC20ZeroBalance function is correctly implemented and ensures that the balance of the ZRC20 token is zero on a given address.

zetaclient/chains/solana/signer/withdraw.go (3)

21-21: LGTM!

The addition of the cancelTx parameter to the SignMsgWithdraw function enhances functionality by allowing for conditional behavior in the withdrawal process.


29-32: LGTM!

The logic to set the withdrawal amount to zero if cancelTx is true is correctly implemented.

Tools
GitHub Check: codecov/patch

[warning] 30-31: zetaclient/chains/solana/signer/withdraw.go#L30-L31
Added lines #L30 - L31 were not covered by tests


21-21: Verify the impact of the change.

The attachWithdrawAccounts function no longer appends gatewayID to accountSlice. Ensure that this change does not affect the functionality.

Run the following script to verify the impact of the change:

cmd/zetaclientd/init.go (1)

113-113: LGTM! But verify the impact on application behavior.

The change to use sample.ComplianceConfig() instead of testutils.ComplianceConfigTest() is approved. However, ensure that this change does not negatively impact the application's behavior in production or testing environments.

Run the following script to verify the impact of the change:

e2e/runner/solana.go (1)

Line range hint 148-173: LGTM!

The update to the function signature of WithdrawSOLZRC20 to return a pointer to a CrossChainTx object is approved. This change enhances the method's functionality by allowing the caller to receive and utilize the transaction context information.

e2e/e2etests/helpers.go (1)

99-123: LGTM!

The addition of the verifySolanaWithdrawalAmountFromCCTX function is approved. This function enhances the functionality of the test suite by enabling verification of withdrawal amounts specifically for Solana transactions.

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

19-19: LGTM!

The import statement for the compliance package is correct and necessary for the new functionality.


130-143: LGTM! But conditionally skip transaction processing based on cancelTx.

The compliance check is correctly integrated into the method. However, the cancelTx variable should be used to conditionally skip the transaction processing to avoid unnecessary processing.

 if cancelTx {
 	compliance.PrintComplianceLog(
 		logger,
 		signer.Logger().Compliance,
 		true,
 		chainID,
 		cctx.Index,
 		cctx.InboundParams.Sender,
 		params.Receiver,
 		"SOL",
 	)
+	return
 }
Tools
GitHub Check: codecov/patch

[warning] 131-142: zetaclient/chains/solana/signer/signer.go#L131-L142
Added lines #L131 - L142 were not covered by tests


146-146: LGTM!

The SignMsgWithdraw method call is correctly updated to include the cancelTx parameter.

Tools
GitHub Check: codecov/patch

[warning] 146-146: zetaclient/chains/solana/signer/signer.go#L146
Added line #L146 was not covered by tests

zetaclient/testutils/testdata.go (1)

22-25: LGTM!

The reformatting of test data path constants improves readability and consistency.

zetaclient/chains/solana/observer/outbound.go (1)

163-167: LGTM! But log the compliance status for better traceability.

The compliance check is correctly integrated into the function. However, ensure that the compliance status is logged for better traceability.

 if compliance.IsCctxRestricted(cctx) {
+	logger.Info().Msgf("VoteOutboundIfConfirmed: cctx %s is restricted", cctx.Index)
 	// use cctx's amount to bypass the amount check in zetacore
 	outboundAmount = cctx.GetCurrentOutboundParam().Amount.BigInt()
 }
Tools
GitHub Check: codecov/patch

[warning] 164-164: zetaclient/chains/solana/observer/outbound.go#L164
Added line #L164 was not covered by tests


[warning] 166-166: zetaclient/chains/solana/observer/outbound.go#L166
Added line #L166 was not covered by tests

cmd/zetae2e/local/local.go (2)

363-363: LGTM!

The addition of e2etests.TestSolanaDepositRestrictedName ensures that deposits to restricted addresses are tested.


364-364: LGTM!

The addition of e2etests.TestSolanaWithdrawRestrictedName ensures that withdrawals to restricted addresses are tested.

e2e/e2etests/e2etests.go (4)

62-62: LGTM!

The addition of TestSolanaDepositRestrictedName constant is necessary for the new test case.


63-63: LGTM!

The addition of TestSolanaWithdrawRestrictedName constant is necessary for the new test case.


378-378: Verify the impact of the default value change.

The default value for the "amount in lamport" for TestSolanaDeposit has been modified from 1200000 to 12000000. Ensure that this change does not negatively impact the test's behavior and outcomes.


407-423: LGTM!

The addition of TestSolanaDepositRestricted and TestSolanaWithdrawRestricted test cases ensures that deposits and withdrawals to restricted addresses are tested.

changelog.md (1)

18-18: LGTM!

The changelog entry is correctly formatted and provides a clear description of the new feature.

@fbac
Copy link
Contributor

fbac commented Sep 2, 2024

Changes LGTM, it should be good to merge after resolving the conflicts.

Copy link
Contributor

@swift1337 swift1337 left a comment

Choose a reason for hiding this comment

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

LGTM. Left a comment regarding E2E testing suite

e2e/runner/poste2e_checker.go Outdated Show resolved Hide resolved
@ws4charlie ws4charlie added chain:solana SOLANA_TESTS Run make start-solana-test labels Sep 9, 2024
@ws4charlie ws4charlie added this pull request to the merge queue Sep 9, 2024
Merged via the queue into develop with commit b251df6 Sep 9, 2024
29 of 30 checks passed
@ws4charlie ws4charlie deleted the feat-solana-restricted-address branch September 9, 2024 22:34
@coderabbitai coderabbitai bot mentioned this pull request Oct 17, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for restricted address for Solana network
4 participants