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: improve solana tx broadcasting in e2e tests #3378

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

skosito
Copy link
Contributor

@skosito skosito commented Jan 18, 2025

Description

Improve broadcasting of solana txs in e2e test. This was tested on mainnet and contains couple of fixes, I tried 5 consecutive spl deposits and all worked without tx dropping.

For context, tx was dropped on mainnet and the biggest issue is that blockhash expired sometimes between tx signing and broadcasting, therefore changed to use confirmed commitment level, which is fine, especially for tests, since this should reduce that interval.

Other fixes:

  • add cp limit and price so tx is better packed
  • skip preflight for tests, as simulation is not needed for tests, and it speeds up broadcast
  • add preflight commitment with max retry - this is the tip i found, no matter that preflight is skipped, it is still affecting automatic retry
  • manual re-broadcast (this might be overkill as showed with latest testing, but still keeping it just in case, also would be ok to remove it for now imo, but leaving it in PR just in case)

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

Based on the comprehensive summary, here are the release notes:

  • Improvements

    • Enhanced Solana blockchain interaction by updating transaction commitment levels
    • Improved transaction handling and compute budget management
    • Added more robust error logging for transaction broadcasts
  • Technical Updates

    • Updated account information retrieval methods
    • Modified balance checking mechanisms across multiple test scenarios
    • Introduced more granular transaction confirmation strategies
  • Performance

    • Added compute unit limits and price settings for transactions
    • Optimized transaction broadcasting logic

These changes aim to improve the reliability and precision of blockchain interactions in our testing and deployment processes.

@skosito skosito added no-changelog Skip changelog CI check SOLANA_TESTS Run make start-solana-test labels Jan 18, 2025
@skosito skosito requested a review from a team as a code owner January 18, 2025 01:35
Copy link
Contributor

coderabbitai bot commented Jan 18, 2025

📝 Walkthrough

Walkthrough

The pull request introduces comprehensive modifications to Solana-related end-to-end (e2e) testing infrastructure, focusing on enhancing transaction handling, commitment levels, and compute budget management. The changes primarily involve updating method calls across multiple files to use CommitmentConfirmed instead of CommitmentFinalized, implementing more granular account information retrieval, and introducing compute unit instructions for transactions.

Changes

File Change Summary
e2e/e2etests/* Updated commitment levels from CommitmentFinalized to CommitmentConfirmed for token account balance retrievals
e2e/runner/balances.go Modified balance retrieval commitment level
e2e/runner/solana.go Added compute unit instructions, enhanced transaction broadcasting logic, updated account info retrieval
e2e/runner/verify.go Updated transaction retrieval with commitment options

Possibly related issues

  • Improve solana RPC tx broadcast #3354: Improve Solana RPC transaction broadcasting
    • The current changes align with the issue's recommendations for setting compute limits and improving transaction handling

Possibly related PRs

Suggested labels

UPGRADE_LIGHT_TESTS

Suggested reviewers

  • fbac
  • kingpinXD
  • ws4charlie
  • brewmaster012
  • lumtis
  • swift1337

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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
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: 7

🧹 Nitpick comments (6)
e2e/runner/solana.go (1)

238-241: Optimize compute budget instructions placement.

For clearer readability and potential reuse, consider grouping the compute budget instructions into a separate function or placing them at the beginning of the transaction construction.

e2e/e2etests/test_solana_whitelist_spl.go (1)

5-5: Organize imports according to Go conventions.

Consider grouping standard library imports separately from third-party imports for improved readability.

Apply this diff to organize imports:

 import (
     "github.com/gagliardetto/solana-go"
+    "github.com/gagliardetto/solana-go/rpc"
     "github.com/stretchr/testify/require"

     "github.com/zeta-chain/node/e2e/runner"
e2e/e2etests/test_spl_deposit.go (1)

48-51: Handle possible race conditions in balance assertions.

Using rpc.CommitmentConfirmed might cause the balances to reflect unfinalized transactions. Ensure that the balance assertions account for possible delays in state updates.

e2e/e2etests/test_spl_withdraw.go (1)

43-43: Consider adding retry mechanism for balance checks

While switching to CommitmentConfirmed helps reduce transaction drops, it might introduce race conditions in balance verification. Consider implementing a retry mechanism with timeout for balance checks to ensure test reliability.

+func getTokenBalanceWithRetry(client *rpc.Client, ctx context.Context, account solana.PublicKey, maxRetries int, interval time.Duration) (*rpc.GetTokenAccountBalanceResult, error) {
+    for i := 0; i < maxRetries; i++ {
+        balance, err := client.GetTokenAccountBalance(ctx, account, rpc.CommitmentConfirmed)
+        if err == nil {
+            return balance, nil
+        }
+        time.Sleep(interval)
+    }
+    return nil, fmt.Errorf("failed to get token balance after %d retries", maxRetries)
+}

Also applies to: 60-60

e2e/e2etests/test_spl_deposit_and_call.go (1)

32-32: Consolidate balance verification logic

Multiple similar balance checks could be consolidated into a helper function to improve maintainability and reduce code duplication.

+func verifyTokenBalance(r *runner.E2ERunner, account solana.PublicKey, expectedDelta int64, isDecrease bool) error {
+    balanceBefore, err := r.SolanaClient.GetTokenAccountBalance(r.Ctx, account, rpc.CommitmentConfirmed)
+    if err != nil {
+        return fmt.Errorf("failed to get balance before: %w", err)
+    }
+    
+    // ... perform transaction ...
+    
+    balanceAfter, err := r.SolanaClient.GetTokenAccountBalance(r.Ctx, account, rpc.CommitmentConfirmed)
+    if err != nil {
+        return fmt.Errorf("failed to get balance after: %w", err)
+    }
+    
+    beforeAmount := utils.ParseInt(r, balanceBefore.Value.Amount)
+    afterAmount := utils.ParseInt(r, balanceAfter.Value.Amount)
+    
+    if isDecrease {
+        return require.Equal(r, beforeAmount-expectedDelta, afterAmount)
+    }
+    return require.Equal(r, beforeAmount+expectedDelta, afterAmount)
+}

Also applies to: 36-36, 58-58, 61-61

e2e/runner/verify.go (1)

Line range hint 107-107: Consider documenting the commitment level trade-off.

The switch to CommitmentConfirmed trades finality for speed, which is suitable for testing. Consider adding a comment in the code or documentation explaining this trade-off and why CommitmentConfirmed was chosen over CommitmentFinalized for future maintainers.

Also applies to: 122-122, 45-47

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4bdfc0b and 519c416.

📒 Files selected for processing (9)
  • e2e/e2etests/test_solana_whitelist_spl.go (3 hunks)
  • e2e/e2etests/test_spl_deposit.go (2 hunks)
  • e2e/e2etests/test_spl_deposit_and_call.go (2 hunks)
  • e2e/e2etests/test_spl_withdraw.go (2 hunks)
  • e2e/e2etests/test_spl_withdraw_and_create_receiver_ata.go (2 hunks)
  • e2e/runner/balances.go (2 hunks)
  • e2e/runner/setup_solana.go (2 hunks)
  • e2e/runner/solana.go (8 hunks)
  • e2e/runner/verify.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (9)
e2e/e2etests/test_spl_withdraw_and_create_receiver_ata.go (1)

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

e2e/e2etests/test_spl_deposit.go (1)

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

e2e/e2etests/test_spl_withdraw.go (1)

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

e2e/runner/verify.go (1)

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

e2e/e2etests/test_spl_deposit_and_call.go (1)

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

e2e/runner/setup_solana.go (1)

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

e2e/e2etests/test_solana_whitelist_spl.go (1)

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

e2e/runner/balances.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.

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: start-solana-test / e2e
  • GitHub Check: start-e2e-test / e2e
🔇 Additional comments (6)
e2e/runner/solana.go (2)

145-145: Ensure CommitmentConfirmed is sufficient for blockhash validity.

Changing the commitment level to rpc.CommitmentConfirmed may help prevent blockhash expiration between signing and broadcasting. However, verify that CommitmentConfirmed provides a recent enough blockhash to avoid potential transaction failures due to expired blockhashes.


426-431: Consistent application of compute budget instructions.

The addition of compute budget instructions in SOLDepositAndCall aligns with their usage in SPLDepositAndCall. Ensure that this consistency is maintained across all transaction constructions that may benefit from compute budget optimizations.

e2e/e2etests/test_solana_whitelist_spl.go (1)

70-74: Ensure account existence after whitelisting.

After the whitelist transaction, confirm that the whitelistEntryInfo is not only non-nil but also contains the expected data to verify successful whitelisting.

e2e/e2etests/test_spl_deposit.go (1)

26-30: Consistent use of commitment levels when fetching balances.

Changing the commitment level to rpc.CommitmentConfirmed may result in fetching balances that are not yet finalized. Verify that this level of commitment is appropriate for your test scenarios.

e2e/runner/balances.go (1)

107-107: LGTM! Consistent commitment level changes.

The changes to use rpc.CommitmentConfirmed for both SOL and SPL token balance queries align with the PR's objective to improve transaction broadcasting reliability in e2e tests.

Also applies to: 122-122

e2e/runner/verify.go (1)

45-47: LGTM! Consistent use of CommitmentConfirmed.

The addition of transaction options with CommitmentConfirmed maintains consistency with other Solana client calls and supports the PR's goal of improving transaction reliability.

e2e/runner/solana.go Show resolved Hide resolved
e2e/runner/solana.go Show resolved Hide resolved
e2e/runner/solana.go Show resolved Hide resolved
e2e/runner/solana.go Show resolved Hide resolved
e2e/e2etests/test_solana_whitelist_spl.go Show resolved Hide resolved
e2e/runner/setup_solana.go Show resolved Hide resolved
@skosito skosito added this pull request to the merge queue Jan 22, 2025
Merged via the queue into develop with commit 815c8b8 Jan 22, 2025
44 of 48 checks passed
@skosito skosito deleted the stabilize-broadcast-for-solana-e2e-tests branch January 22, 2025 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog Skip changelog CI check SOLANA_TESTS Run make start-solana-test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants