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: check Solana account rent exempt in zetacore to avoid outbound failure #2545

Merged
merged 5 commits into from
Jul 25, 2024

Conversation

ws4charlie
Copy link
Contributor

@ws4charlie ws4charlie commented Jul 24, 2024

Description

  1. Solana requires minimum balance in users' accounts. When cctxAmount < rentExempt and the funds is to sent to an account that holds 0 balance, the transaction will fail and this will block outbound.
  2. Add receiver address check into ValidateZrc20WithdrawEvent, similar to Bitcoin.

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
    • Introduced new constants for cryptocurrency withdrawal thresholds for Bitcoin and Solana.
    • Added a function to create ZRC20 withdrawal transactions.
  • Bug Fixes
    • Enhanced validation for Solana withdrawal events to ensure compliance with new requirements.
  • Tests
    • Refined error messages and added new test cases for Solana withdrawals in the validation logic.

Copy link
Contributor

coderabbitai bot commented Jul 24, 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 recent changes enhance the cryptocurrency withdrawal functionality by introducing new constants for withdrawal thresholds, adding a method for ZRC20 token withdrawals, and improving the validation logic for both Bitcoin and Solana withdrawals. These updates aim to ensure compliance with protocol specifications and improve the robustness of transaction handling across different blockchain networks.

Changes

File Change Summary
pkg/constant/constant.go Added BTCWithdrawalDustAmount (set to 1000 satoshis) and SolanaWalletRentExempt (set to 1,000,000 lamports) for enhanced withdrawal handling.
testutil/sample/crosschain.go Introduced ZRC20Withdrawal function to create ZRC20 withdrawal transactions with random gas fees.
x/crosschain/keeper/evm_hooks.go Refactored ValidateZrc20WithdrawEvent to include support for Solana withdrawals, enhancing transaction validation.
x/crosschain/keeper/evm_hooks_test.go Updated test cases for ValidateZrc20WithdrawEvent, refining error messages and adding cases for Solana withdrawals.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ZRC20Withdrawal
    participant Keeper

    User->>ZRC20Withdrawal: Request withdrawal
    ZRC20Withdrawal->>Keeper: Validate withdrawal data
    Keeper->>Keeper: Check blockchain type
    alt Bitcoin
        Keeper->>Keeper: Validate against BTCWithdrawalDustAmount
    else Solana
        Keeper->>Keeper: Validate against SolanaWalletRentExempt
    end
    Keeper->>User: Confirm withdrawal
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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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 Jul 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 46.70%. Comparing base (c7155e7) to head (a97b497).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2545      +/-   ##
===========================================
+ Coverage    46.68%   46.70%   +0.02%     
===========================================
  Files          464      464              
  Lines        30781    30793      +12     
===========================================
+ Hits         14369    14381      +12     
  Misses       15557    15557              
  Partials       855      855              
Files Coverage Δ
x/crosschain/keeper/evm_hooks.go 84.49% <100.00%> (+1.06%) ⬆️

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: 2

Outside diff range, codebase verification and nitpick comments (1)
x/crosschain/keeper/evm_hooks.go (1)

279-279: Improve readability by clarifying the purpose of additionalChains.

Consider adding a comment to explain the purpose of additionalChains for better readability.

+ // additionalChains contains the list of additional chains supported by the system
additionalChains := k.GetAuthorityKeeper().GetAdditionalChainList(ctx)
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a27aa9a and 6019620.

Files selected for processing (4)
  • pkg/constant/constant.go (1 hunks)
  • testutil/sample/crosschain.go (3 hunks)
  • x/crosschain/keeper/evm_hooks.go (2 hunks)
  • x/crosschain/keeper/evm_hooks_test.go (2 hunks)
Additional context used
Path-based instructions (4)
pkg/constant/constant.go (1)

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

x/crosschain/keeper/evm_hooks.go (1)

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

testutil/sample/crosschain.go (1)

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

x/crosschain/keeper/evm_hooks_test.go (1)

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

Additional comments not posted (4)
pkg/constant/constant.go (2)

15-15: LGTM!

The BTCWithdrawalDustAmount constant is well-documented and the value is justified.


21-21: LGTM!

The SolanaWalletRentExempt constant is well-documented and the value is justified.

x/crosschain/keeper/evm_hooks_test.go (2)

208-218: Verify the correctness of the invalid Solana address test case.

The test case correctly checks for an invalid Solana address. Ensure that the constant constant.SolanaWalletRentExempt is defined and imported correctly.

Verification successful

The test case for validating an invalid Solana address is correctly implemented.

The constant constant.SolanaWalletRentExempt is properly defined and imported, ensuring the test case functions as expected.

  • pkg/constant/constant.go: Definition of SolanaWalletRentExempt
  • x/crosschain/keeper/evm_hooks_test.go: Usage in the test case
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definition and import of `constant.SolanaWalletRentExempt`.

# Test: Search for the constant definition. Expect: The constant should be defined in the codebase.
rg --type go 'SolanaWalletRentExempt'

Length of output: 699


220-237: Verify the correctness of the Solana withdrawal amount test case.

The test case correctly checks for amounts below the minimum required for Solana withdrawals. Ensure that the constant constant.SolanaWalletRentExempt is defined and imported correctly.

Verification successful

The constant SolanaWalletRentExempt is correctly defined and imported.

  • The constant SolanaWalletRentExempt is defined in pkg/constant/constant.go and is used in the test case as expected.
  • The test case correctly checks for amounts below the minimum required for Solana withdrawals.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definition and import of `constant.SolanaWalletRentExempt`.

# Test: Search for the constant definition. Expect: The constant should be defined in the codebase.
rg --type go 'SolanaWalletRentExempt'

Length of output: 699

x/crosschain/keeper/evm_hooks.go Show resolved Hide resolved
testutil/sample/crosschain.go Show resolved Hide resolved
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, lest a minor comment

@lumtis lumtis added this pull request to the merge queue Jul 25, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Jul 25, 2024
@lumtis lumtis enabled auto-merge July 25, 2024 08:53
@lumtis lumtis added this pull request to the merge queue Jul 25, 2024
Merged via the queue into develop with commit 949f124 Jul 25, 2024
28 checks passed
@lumtis lumtis deleted the zetacore-solana-minimum-withdraw branch July 25, 2024 09:28
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.

3 participants