node icon indicating copy to clipboard operation
node copied to clipboard

refactor(zetaclient): wait for expected nonce and defer relayer signing

Open gartnera opened this issue 9 months ago • 2 comments

There is no reason to even try to submit the transaction until the nonce is in the expected range. Update: that would not be true if we enabled skipping the preflight checks (which may be a better solution than this).

If we defer relayer transaction signing until we're closer to actually being able to relay the transaction, we can avoid starting the two minute recentBlockhash timer (ref).

We need to continue doing TSS signing immediately to avoid desynchronization.

TODO:

  • [ ] deduplicate signer.client.GetAccountInfoWithOpts calls. We should only make 1 call even if we have N pending transactions
  • [ ] inject the fallbackTx as txGetterT and resolve it only when actually needed. Although I don't exactly understand why we actually would want to do this. Testing for the NonceMismatch will have a lot of false positives since we see it during normal operations.

Note, I have another older version of this logic that make the relayer more like a queue. But that has a bunch of concurrency overhead that could be a bit of maintenance burden.

Related to https://github.com/zeta-chain/node/issues/3383

Performance Test Comparison

We see 10-20% reductions in latency since we are spending less time in the relayer backoff loop

Before (nightly run)

perf_sol_wit | Latency report:
perf_sol_wit | min:  42.59
perf_sol_wit | max:  649.80
perf_sol_wit | mean: 330.21
perf_sol_wit | std:  182.90
perf_sol_wit | p50:  314.24
perf_sol_wit | p75:  480.37
perf_sol_wit | p90:  576.56
perf_sol_wit | p95:  616.17

After (this PR)

perf_sol_wit | Latency report:
perf_sol_wit | min:  26.58
perf_sol_wit | max:  568.70
perf_sol_wit | mean: 296.78
perf_sol_wit | std:  159.03
perf_sol_wit | p50:  296.59
perf_sol_wit | p75:  425.42
perf_sol_wit | p90:  512.57
perf_sol_wit | p95:  531.25

Summary by CodeRabbit

  • New Features

    • Introduced enhanced retrieval of account details by allowing additional query options.
  • Refactor

    • Improved outbound transaction handling by deferring transaction creation, which streamlines error management and processing efficiency.

gartnera avatar Mar 04 '25 22:03 gartnera

[!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

This pull request introduces a new method to the SolanaRPCClient interface, GetAccountInfoWithOpts, allowing retrieval of account information using additional options. In parallel, the transaction signing logic is refactored by introducing a new function type txGetterT, with various transaction preparation functions updated to return a getter closure. The outbound processing now includes a loop to verify PDA nonce conditions before proceeding. The associated mock implementation is also updated to support the new interface method.

Changes

File(s) Change Summary
zetaclient/chains/interfaces/.../interfaces.go
zetaclient/testutils/mocks/.../solana_rpc.go
Added new method GetAccountInfoWithOpts to the SolanaRPCClient interface and its mock implementation, providing an option-based account information retrieval.
zetaclient/chains/solana/signer/signer.go Introduced a new function type txGetterT and refactored transaction preparation functions (e.g., prepareWhitelistTx, prepareWithdrawTx, etc.) to return a closure, along with adding a loop in TryProcessOutbound for PDA nonce verification.

Sequence Diagram(s)

sequenceDiagram
    participant S as Signer
    participant RPC as SolanaRPCClient
    participant Tx as Tx Getter Function

    S->>RPC: GetAccountInfoWithOpts(ctx, account, opts)
    alt PDA nonce < outbound nonce
        loop Retry Loop
            RPC-->>S: Return AccountInfo (nonce low)
            S->>S: Wait and recheck PDA nonce
        end
    else PDA nonce ≥ outbound nonce
        S->>Tx: Invoke txGetterT closure
        Tx-->>S: Return Transaction
    end

Possibly related PRs

  • zeta-chain/node#3071: Introduces the same GetAccountInfoWithOpts method in the mock implementation, ensuring interface consistency.
  • zeta-chain/node#3077: Focuses on implementing the new RPC method in mocks, aligning with the interface enhancements.
  • zeta-chain/node#2563: Also adds the GetAccountInfoWithOpts method, targeting uniform account info retrieval across implementations.

Suggested labels

breaking:cli

Suggested reviewers

  • skosito
  • lumtis
  • fbac
  • swift1337
  • kingpinXD
  • brewmaster012

🪧 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.
  • @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.

coderabbitai[bot] avatar Mar 04 '25 22:03 coderabbitai[bot]

Codecov Report

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

Project coverage is 64.47%. Comparing base (93b9b1c) to head (d6c90df). Report is 109 commits behind head on develop.

Files with missing lines Patch % Lines
zetaclient/chains/solana/signer/signer.go 0.00% 115 Missing :warning:
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3633      +/-   ##
===========================================
- Coverage    64.59%   64.47%   -0.13%     
===========================================
  Files          469      469              
  Lines        32911    32973      +62     
===========================================
  Hits         21259    21259              
- Misses       10687    10749      +62     
  Partials       965      965              
Files with missing lines Coverage Δ
zetaclient/chains/solana/signer/signer.go 10.13% <0.00%> (-1.37%) :arrow_down:
:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Mar 04 '25 22:03 codecov[bot]

This PR will be replaced by https://github.com/zeta-chain/node/pull/3940

ws4charlie avatar May 30 '25 21:05 ws4charlie