Skip to content

feat(ton): send real gas usage #3699

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

Merged
merged 4 commits into from
Mar 12, 2025
Merged

feat(ton): send real gas usage #3699

merged 4 commits into from
Mar 12, 2025

Conversation

swift1337
Copy link
Contributor

@swift1337 swift1337 commented Mar 12, 2025

Closes #3655

Summary by CodeRabbit

  • New Features

    • Updated the v29.0.0 changelog to highlight enhanced real gas usage for TON withdrawals.
  • Refactor

    • Improved deposit processing by shifting to dynamic gas limit assignment.
    • Enhanced transaction fee management with thread-safe gas price tracking.
    • Streamlined outbound transaction handling with clearer error reporting.

These updates lead to more accurate gas consumption calculations and refined transaction processing for a smoother user experience.

@swift1337 swift1337 added the TON_TESTS Runs TON E2E tests label Mar 12, 2025
@swift1337 swift1337 self-assigned this Mar 12, 2025
@swift1337 swift1337 requested a review from a team as a code owner March 12, 2025 14:06
Copy link
Contributor

coderabbitai bot commented Mar 12, 2025

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 adds a new changelog entry under version v29.0.0 for using real gas usage in TON withdrawals. It removes obsolete commented code from the Sui client, modifies the TON observer’s deposit logic by replacing a hardcoded gas limit with a constant value, augments the Observer with an atomic field and helper methods for gas price management, and refactors outbound voting functions by updating type aliases, consolidating parameters, and improving error handling.

Changes

File(s) Change Summary
changelog.md Appended a new feature entry under the "Unreleased" section for v29.0.0 detailing the use of real gas usage for TON withdrawals.
zetaclient/chains/sui/sui.go Removed a block of commented-out code containing TODO items from the Start method.
zetaclient/chains/ton/observer/inbound.go,
zetaclient/chains/ton/observer/observer.go,
zetaclient/chains/ton/observer/outbound.go
Updated gas management for TON withdrawals: inbound now uses maxGasLimit in place of a hardcoded 0; Observer adds an atomic latestGasPrice field along with getter/setter methods and improves error wrapping in PostGasPrice; outbound vote methods have updated type aliases, consolidated parameters (using an outbound struct), and enhanced error handling with a switch statement.

Sequence Diagram(s)

sequenceDiagram
    participant Block as Block Data
    participant Observer
    participant VoteService as VoteGasPrice Service
    Block->>Observer: Provide block info (blockID.Seqno)
    Observer->>Observer: Compute new gas price
    Observer->>Observer: setLatestGasPrice(newGasPrice)
    Observer->>VoteService: PostVoteGasPrice(newGasPrice, block number)
    VoteService-->>Observer: Acknowledgement
    Observer-->>Block: Return success
Loading
sequenceDiagram
    participant Client
    participant Observer
    participant OutboundService as External Withdrawal Service
    Client->>Observer: VoteOutboundIfConfirmed(ctx, cctypes.CrossChainTx)
    Observer->>OutboundService: postVoteOutbound(ctx, cctx, outboundRes, withdrawal)
    OutboundService-->>Observer: Transaction response
    Observer-->>Client: Return vote status
Loading

Possibly related PRs

Suggested labels

UPGRADE_TESTS

Suggested reviewers

  • kingpinXD
  • lumtis
  • skosito

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

Copy link

!!!WARNING!!!
nosec detected in the following files: zetaclient/chains/ton/observer/outbound.go

Be very careful about using #nosec in code. It can be a quick way to suppress security warnings and move forward with development, it should be employed with caution. Suppressing warnings with #nosec can hide potentially serious vulnerabilities. Only use #nosec when you're absolutely certain that the security issue is either a false positive or has been mitigated in another way.

Only suppress a single rule (or a specific set of rules) within a section of code, while continuing to scan for other problems. To do this, you can list the rule(s) to be suppressed within the #nosec annotation, e.g: /* #nosec G401 */ or //#nosec G201 G202 G203
Broad #nosec annotations should be avoided, as they can hide other vulnerabilities. The CI will block you from merging this PR until you remove #nosec annotations that do not target specific rules.

Pay extra attention to the way #nosec is being used in the files listed above.

@github-actions github-actions bot added the nosec label Mar 12, 2025
Copy link

codecov bot commented Mar 12, 2025

Codecov Report

Attention: Patch coverage is 4.34783% with 44 lines in your changes missing coverage. Please review.

Project coverage is 64.58%. Comparing base (f5e208c) to head (8cbbc99).
Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
zetaclient/chains/ton/observer/outbound.go 3.22% 30 Missing ⚠️
zetaclient/chains/ton/observer/observer.go 0.00% 14 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3699      +/-   ##
===========================================
- Coverage    64.58%   64.58%   -0.01%     
===========================================
  Files          469      469              
  Lines        32915    32918       +3     
===========================================
  Hits         21259    21259              
- Misses       10691    10694       +3     
  Partials       965      965              
Files with missing lines Coverage Δ
zetaclient/chains/sui/sui.go 47.55% <ø> (ø)
zetaclient/chains/ton/observer/inbound.go 64.68% <100.00%> (ø)
zetaclient/chains/ton/observer/observer.go 17.80% <0.00%> (-3.16%) ⬇️
zetaclient/chains/ton/observer/outbound.go 28.96% <3.22%> (+1.21%) ⬆️
🚀 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: 2

🧹 Nitpick comments (1)
zetaclient/chains/ton/observer/outbound.go (1)

227-236: Enhanced gas price retrieval and validation

The implementation now retrieves the gas price atomically and includes proper validation before proceeding. The conversion to math.Int is also handled correctly.

Consider adding a fallback mechanism for when the gas price is not set, such as triggering a gas price update rather than returning an error.

if !ok {
-   return errors.New("gas price is not set (call PostGasPrice first)")
+   if err := ob.PostGasPrice(ctx); err != nil {
+       return errors.Wrap(err, "failed to update gas price")
+   }
+   gasPrice, ok = ob.getLatestGasPrice()
+   if !ok {
+       return errors.New("gas price is still not set after update attempt")
+   }
}
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 227-232: zetaclient/chains/ton/observer/outbound.go#L227-L232
Added lines #L227 - L232 were not covered by tests

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5bac6f9 and 226445f.

📒 Files selected for processing (5)
  • changelog.md (1 hunks)
  • zetaclient/chains/sui/sui.go (0 hunks)
  • zetaclient/chains/ton/observer/inbound.go (1 hunks)
  • zetaclient/chains/ton/observer/observer.go (4 hunks)
  • zetaclient/chains/ton/observer/outbound.go (4 hunks)
💤 Files with no reviewable changes (1)
  • zetaclient/chains/sui/sui.go
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code, point out issues relative to ...

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

  • zetaclient/chains/ton/observer/inbound.go
  • zetaclient/chains/ton/observer/observer.go
  • zetaclient/chains/ton/observer/outbound.go
🪛 GitHub Check: codecov/patch
zetaclient/chains/ton/observer/observer.go

[warning] 89-90: zetaclient/chains/ton/observer/observer.go#L89-L90
Added lines #L89 - L90 were not covered by tests


[warning] 94-97: zetaclient/chains/ton/observer/observer.go#L94-L97
Added lines #L94 - L97 were not covered by tests


[warning] 99-99: zetaclient/chains/ton/observer/observer.go#L99
Added line #L99 was not covered by tests


[warning] 101-101: zetaclient/chains/ton/observer/observer.go#L101
Added line #L101 was not covered by tests


[warning] 135-138: zetaclient/chains/ton/observer/observer.go#L135-L138
Added lines #L135 - L138 were not covered by tests


[warning] 141-142: zetaclient/chains/ton/observer/observer.go#L141-L142
Added lines #L141 - L142 were not covered by tests

zetaclient/chains/ton/observer/outbound.go

[warning] 31-31: zetaclient/chains/ton/observer/outbound.go#L31
Added line #L31 was not covered by tests


[warning] 47-47: zetaclient/chains/ton/observer/outbound.go#L47
Added line #L47 was not covered by tests


[warning] 215-217: zetaclient/chains/ton/observer/outbound.go#L215-L217
Added lines #L215 - L217 were not covered by tests


[warning] 221-221: zetaclient/chains/ton/observer/outbound.go#L221
Added line #L221 was not covered by tests


[warning] 227-232: zetaclient/chains/ton/observer/outbound.go#L227-L232
Added lines #L227 - L232 were not covered by tests


[warning] 235-237: zetaclient/chains/ton/observer/outbound.go#L235-L237
Added lines #L235 - L237 were not covered by tests


[warning] 241-244: zetaclient/chains/ton/observer/outbound.go#L241-L244
Added lines #L241 - L244 were not covered by tests


[warning] 246-246: zetaclient/chains/ton/observer/outbound.go#L246
Added line #L246 was not covered by tests


[warning] 250-250: zetaclient/chains/ton/observer/outbound.go#L250
Added line #L250 was not covered by tests


[warning] 253-253: zetaclient/chains/ton/observer/outbound.go#L253
Added line #L253 was not covered by tests


[warning] 257-257: zetaclient/chains/ton/observer/outbound.go#L257
Added line #L257 was not covered by tests


[warning] 261-262: zetaclient/chains/ton/observer/outbound.go#L261-L262
Added lines #L261 - L262 were not covered by tests


[warning] 267-271: zetaclient/chains/ton/observer/outbound.go#L267-L271
Added lines #L267 - L271 were not covered by tests

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

14-14: New feature entry looks good

The changelog entry properly documents the addition of real gas usage for TON withdrawals, linked to the correct pull request number.

zetaclient/chains/ton/observer/inbound.go (1)

257-257: Replacing hardcoded gas limit with constant value

Good change replacing the hardcoded value of 0 with maxGasLimit for better consistency and maintainability. This aligns with the PR objective of using real gas usage for TON withdrawals.

zetaclient/chains/ton/observer/observer.go (1)

28-28: Good addition of atomic gas price tracking

Adding an atomic field for tracking the latest gas price ensures thread-safe operations across concurrent accesses.

zetaclient/chains/ton/observer/outbound.go (4)

20-22: Clear documentation of maximum gas limit

Good addition of comments explaining the source of the maximum gas limit value and its potential for future changes.


241-244: Dynamic gas parameters in vote outbound message

Now using actual block height, gas used, gas price, and maximum gas limit values instead of hardcoded ones, which improves accuracy and maintainability.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 241-244: zetaclient/chains/ton/observer/outbound.go#L241-L244
Added lines #L241 - L244 were not covered by tests


267-271: Improved error handling with switch statement

The error handling now uses a clearer switch statement pattern, improving readability and maintainability.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 267-271: zetaclient/chains/ton/observer/outbound.go#L267-L271
Added lines #L267 - L271 were not covered by tests


13-13: Updated imports for better code organization

Good practice to use a more descriptive alias cctypes instead of the shorter cc for better readability.

Also applies to: 16-17

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

@swift1337 swift1337 added this pull request to the merge queue Mar 12, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 12, 2025
@swift1337 swift1337 enabled auto-merge March 12, 2025 18:01
@swift1337 swift1337 added this pull request to the merge queue Mar 12, 2025
Merged via the queue into develop with commit 24290d1 Mar 12, 2025
44 of 45 checks passed
@swift1337 swift1337 deleted the feat/ton/outbounds-gas branch March 12, 2025 18:35
swift1337 added a commit that referenced this pull request Mar 12, 2025
* feat(ton): lite-server connection tweaks (#3697) [backport]

* feat(ton): send real gas usage (#3699) [backport]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nosec TON_TESTS Runs TON E2E tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix TON's effective gas params for outbounds
3 participants