Skip to content

fix: remove tx format assumption from solana parse gateway instruction#3957

Merged
skosito merged 3 commits intodevelopfrom
remove-assumptions-from-parse-gateway-instruction
Jun 5, 2025
Merged

fix: remove tx format assumption from solana parse gateway instruction#3957
skosito merged 3 commits intodevelopfrom
remove-assumptions-from-parse-gateway-instruction

Conversation

@skosito
Copy link
Member

@skosito skosito commented Jun 4, 2025

Description

https://github.com/zeta-chain/protocol-private/issues/235

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

  • Bug Fixes

    • Improved handling of Solana transaction instructions by accurately validating and selecting gateway instructions based on nonce, reducing errors in outbound instruction parsing.
  • Documentation

    • Updated changelog to record the removal of a transaction format assumption in Solana gateway instruction parsing.

@skosito skosito requested a review from a team as a code owner June 4, 2025 19:55
@skosito skosito added the SOLANA_TESTS Run make start-solana-test label Jun 4, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 4, 2025

📝 Walkthrough

Walkthrough

The changes refactor the Solana gateway instruction parsing logic to support multiple gateway instructions per transaction and enforce nonce validation during parsing. The ParseGatewayInstruction function now accepts an expectedNonce parameter, with all related call sites and tests updated accordingly. Error handling and test assertions were also enhanced for clarity.

Changes

File(s) Change Summary
changelog.md Documented the removal of a transaction format assumption from Solana parse gateway instruction (referencing #3957).
zetaclient/chains/solana/observer/outbound.go Refactored ParseGatewayInstruction to support multiple gateway instructions, added expectedNonce parameter, improved error handling, and updated call sites.
zetaclient/chains/solana/observer/outbound_test.go Updated tests to pass the new expectedNonce argument and adjusted error message assertions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Observer
    participant SolanaTx

    Client->>Observer: ParseGatewayInstruction(txResult, gatewayID, coinType, expectedNonce)
    Observer->>SolanaTx: Iterate all instructions
    loop For each instruction
        SolanaTx-->>Observer: If program matches gatewayID
        Observer->>Observer: Try parse as increment nonce or outbound (by coinType)
        Observer->>Observer: If nonce matches expectedNonce, collect
    end
    alt No matches
        Observer-->>Client: Error (no matching outbound instruction with expected nonce)
    else Multiple matches
        Observer-->>Client: Error (multiple matching outbound instructions)
    else Single match
        Observer-->>Client: Return parsed outbound instruction
    end
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@skosito skosito changed the title fix: remove tx format assumption from parse gateway instruction fix: remove tx format assumption from solana parse gateway instruction Jun 4, 2025
@codecov
Copy link

codecov bot commented Jun 4, 2025

Codecov Report

Attention: Patch coverage is 76.59574% with 11 lines in your changes missing coverage. Please review.

Project coverage is 64.18%. Comparing base (99a50da) to head (be16b38).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
zetaclient/chains/solana/observer/outbound.go 76.59% 10 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3957      +/-   ##
===========================================
- Coverage    64.18%   64.18%   -0.01%     
===========================================
  Files          474      474              
  Lines        34804    34803       -1     
===========================================
- Hits         22338    22337       -1     
- Misses       11437    11438       +1     
+ Partials      1029     1028       -1     
Files with missing lines Coverage Δ
zetaclient/chains/solana/observer/outbound.go 36.92% <76.59%> (-0.25%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

🧹 Nitpick comments (2)
zetaclient/chains/solana/observer/outbound.go (2)

351-355: Consider adding test coverage for edge cases.

The static analysis indicates that the increment_nonce instruction parsing (lines 351-355) and the Cmd/NoAssetCall coin type handling (lines 363-368) lack test coverage. While the implementation looks correct, adding tests for these paths would improve confidence in the code.

Would you like me to help generate test cases for these uncovered code paths?

Also applies to: 363-368

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 351-355: zetaclient/chains/solana/observer/outbound.go#L351-L355
Added lines #L351 - L355 were not covered by tests


391-393: Enhance error message for duplicate nonce detection.

While detecting multiple instructions with the same nonce is good defensive programming, the error message could be more informative for debugging purposes.

 // should not happen
 if matchCount > 1 {
-    return nil, fmt.Errorf("multiple outbounds with same nonce detected")
+    return nil, fmt.Errorf("multiple outbound instructions detected with nonce %d", expectedNonce)
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 99a50da and be16b38.

📒 Files selected for processing (3)
  • changelog.md (1 hunks)
  • zetaclient/chains/solana/observer/outbound.go (3 hunks)
  • zetaclient/chains/solana/observer/outbound_test.go (9 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

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

  • zetaclient/chains/solana/observer/outbound_test.go
  • zetaclient/chains/solana/observer/outbound.go
🧬 Code Graph Analysis (1)
zetaclient/chains/solana/observer/outbound_test.go (1)
zetaclient/chains/solana/observer/outbound.go (1)
  • ParseGatewayInstruction (320-396)
🪛 GitHub Check: codecov/patch
zetaclient/chains/solana/observer/outbound.go

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


[warning] 351-355: zetaclient/chains/solana/observer/outbound.go#L351-L355
Added lines #L351 - L355 were not covered by tests


[warning] 363-366: zetaclient/chains/solana/observer/outbound.go#L363-L366
Added lines #L363 - L366 were not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: start-solana-test / e2e
🔇 Additional comments (5)
changelog.md (1)

12-12: LGTM!

The changelog entry is correctly formatted and accurately describes the fix.

zetaclient/chains/solana/observer/outbound_test.go (2)

223-223: Test updates correctly reflect the API changes.

All test calls to ParseGatewayInstruction have been properly updated to include the expectedNonce parameter with value 0.

Also applies to: 246-246, 249-249, 264-264, 282-282, 300-300, 303-303, 318-318, 331-331, 935-935, 953-953


249-249: Error message assertions updated appropriately.

The error message checks now correctly verify the new format that includes the expected nonce value.

Also applies to: 303-303

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

128-128: Function calls updated correctly with nonce parameter.

Both VoteOutboundIfConfirmed and CheckFinalizedTx now pass the nonce to ParseGatewayInstruction, maintaining consistency with the new API.

Also applies to: 280-280

🧰 Tools
🪛 GitHub Check: codecov/patch

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


320-396: Excellent refactoring to remove transaction format assumptions.

The new implementation properly iterates through all instructions and validates against the expected nonce, making the parser more robust and flexible. The error aggregation provides better debugging information when parsing fails.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 351-355: zetaclient/chains/solana/observer/outbound.go#L351-L355
Added lines #L351 - L355 were not covered by tests


[warning] 363-366: zetaclient/chains/solana/observer/outbound.go#L363-L366
Added lines #L363 - L366 were not covered by tests

Copy link
Contributor

@ws4charlie ws4charlie left a comment

Choose a reason for hiding this comment

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

LGTM

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 99a50da and be16b38.

📒 Files selected for processing (3)
  • changelog.md (1 hunks)
  • zetaclient/chains/solana/observer/outbound.go (3 hunks)
  • zetaclient/chains/solana/observer/outbound_test.go (9 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

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

  • zetaclient/chains/solana/observer/outbound_test.go
  • zetaclient/chains/solana/observer/outbound.go
🧬 Code Graph Analysis (1)
zetaclient/chains/solana/observer/outbound.go (1)
pkg/contracts/solana/instruction.go (4)
  • OutboundInstruction (135-147)
  • ParseInstructionIncrementNonce (201-217)
  • ParseInstructionWhitelist (698-712)
  • ParseInstructionExecute (339-353)
🪛 GitHub Check: codecov/patch
zetaclient/chains/solana/observer/outbound.go

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


[warning] 351-355: zetaclient/chains/solana/observer/outbound.go#L351-L355
Added lines #L351 - L355 were not covered by tests


[warning] 363-366: zetaclient/chains/solana/observer/outbound.go#L363-L366
Added lines #L363 - L366 were not covered by tests

🔇 Additional comments (3)
changelog.md (1)

12-12: LGTM!

The changelog entry accurately documents the fix for removing transaction format assumptions.

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

223-223: Test updates are comprehensive and correct.

All test cases have been properly updated to pass the expected nonce parameter and verify the enhanced error messages that include nonce validation context.

Also applies to: 246-249, 264-264, 283-283, 300-303, 318-318, 331-331, 936-936, 954-954

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

391-393: Good defensive programming for nonce uniqueness.

The check for multiple instructions with the same nonce prevents ambiguity and potential security issues. This is a critical safety measure.

Copy link
Contributor

@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

@skosito skosito added this pull request to the merge queue Jun 5, 2025
Merged via the queue into develop with commit d2c403a Jun 5, 2025
51 checks passed
@skosito skosito deleted the remove-assumptions-from-parse-gateway-instruction branch June 5, 2025 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

SOLANA_TESTS Run make start-solana-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants