Skip to content

Conversation

@ws4charlie
Copy link
Contributor

@ws4charlie ws4charlie commented Dec 30, 2025

Description

This PR wires following two chain parameters to TON in a way similar to Sui and Solana.

  1. outbound_schedule_interval
  2. outbound_schedule_lookahead

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

  • Refactor
    • Consolidated scheduling configuration across blockchain implementations for consistent transaction processing.
    • Enhanced cross-chain transaction scheduling with improved validation boundaries and lookahead-based processing control.
    • Streamlined transaction processing logic while preserving existing safety checks.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 30, 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

Refactored CCTX scheduling logic across multiple chain implementations. Extracted a local constant outboundLookbackFactor into a package-level constant OutboundLookbackFactor, updated chain schedulers (EVM, Solana, Sui, TON) to reference it, and introduced lookahead-based termination and scheduling interval mechanisms in affected chains.

Changes

Cohort / File(s) Summary
Changelog documentation
changelog.md
Added release notes documenting TON CCTX scheduling improvements using outbound_schedule_interval and outbound_schedule_lookahead parameters.
Constant extraction
pkg/constant/constant.go
Introduced exported constant OutboundLookbackFactor (value: 1.0) to centralize lookback logic configuration; added blank line for formatting consistency.
EVM chain scheduler
zetaclient/chains/evm/evm.go
Migrated from local outboundLookBackFactor to package constant; imported constant package.
Solana chain scheduler
zetaclient/chains/solana/solana.go
Migrated to package constant; enhanced CCTX loop to track iteration index; added early-exit logic when index reaches lookahead threshold.
Sui chain scheduler
zetaclient/chains/sui/sui.go
Reorganized logger initialization within loop-variable declaration block; changed nonce boundary check from >= to > (exclusive threshold).
TON chain scheduler (major refactoring)
zetaclient/chains/ton/ton.go
Inlined processCCTX logic into scheduleCCTX; introduced outbound scheduling parameters (interval, lookahead, lookback) derived from chain configuration; added gating checks for receiver chain, nonce bounds, and active processing state; replaced VoteOutboundIfConfirmed flow with conditional inline handling; implemented lookahead-based termination; scheduled keysign processing via goroutines with interval alignment; imported constant package.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: applying two chain parameters (outbound_schedule_interval and outbound_schedule_lookahead) to TON scheduler, mirroring the stated PR objective.
Description check ✅ Passed The description covers the key purpose and includes testing status, though testing coverage is incomplete with only localnet testing performed and other test types skipped.

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@ws4charlie ws4charlie added the TON_TESTS Runs TON E2E tests label Dec 30, 2025
@github-actions
Copy link

!!!WARNING!!!
nosec detected in the following files: zetaclient/chains/ton/ton.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 Dec 30, 2025
@ws4charlie ws4charlie added SUI_TESTS Run make start-sui-tests SOLANA_TESTS Run make start-solana-test zetaclient Issues related to ZetaClient and removed nosec labels Dec 30, 2025
@github-actions github-actions bot added the nosec label Dec 30, 2025
@codecov
Copy link

codecov bot commented Dec 30, 2025

Codecov Report

❌ Patch coverage is 6.25000% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.68%. Comparing base (4993bee) to head (a6bf68d).

Files with missing lines Patch % Lines
zetaclient/chains/ton/ton.go 5.40% 35 Missing ⚠️
zetaclient/chains/solana/solana.go 20.00% 3 Missing and 1 partial ⚠️
zetaclient/chains/sui/sui.go 0.00% 4 Missing ⚠️
zetaclient/chains/evm/evm.go 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4513      +/-   ##
===========================================
- Coverage    64.72%   64.68%   -0.05%     
===========================================
  Files          477      477              
  Lines        28998    29017      +19     
===========================================
  Hits         18769    18769              
- Misses        9202     9222      +20     
+ Partials      1027     1026       -1     
Files with missing lines Coverage Δ
zetaclient/chains/evm/evm.go 35.13% <0.00%> (ø)
zetaclient/chains/solana/solana.go 53.27% <20.00%> (-0.89%) ⬇️
zetaclient/chains/sui/sui.go 47.66% <0.00%> (ø)
zetaclient/chains/ton/ton.go 50.90% <5.40%> (-9.31%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ws4charlie ws4charlie removed the SOLANA_TESTS Run make start-solana-test label Dec 30, 2025
@ws4charlie ws4charlie marked this pull request as ready for review January 2, 2026 01:55
@ws4charlie ws4charlie requested a review from a team as a code owner January 2, 2026 01:55
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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
zetaclient/chains/sui/sui.go (1)

30-35: Inconsistency: Sui still uses local constant instead of shared package constant.

While evm.go and solana.go were updated to use constant.OutboundLookbackFactor, sui.go still defines and uses a local outboundLookbackFactor constant. This is inconsistent with the broader refactoring goal of centralizing the lookback factor configuration.

🔎 Suggested fix to align with other chain implementations

Remove the local constant at lines 30-35:

-const (
-	// outboundLookbackFactor is the factor to determine how many nonces to look back for pending cctxs
-	// For example, give OutboundScheduleLookahead of 120, pending NonceLow of 1000 and factor of 1.0,
-	// the scheduler need to be able to pick up and schedule any pending cctx with nonce < 880 (1000 - 120 * 1.0)
-	// NOTE: 1.0 means look back the same number of cctxs as we look ahead
-	outboundLookbackFactor = 1.0
-)

Add the constant package import and update line 143 to use the shared constant:

+import (
+	"github.com/zeta-chain/node/pkg/constant"
+)
-		lookback = uint64(float64(lookahead) * outboundLookbackFactor)
+		lookback = uint64(float64(lookahead) * constant.OutboundLookbackFactor)

Also applies to: 143-143

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4993bee and 0354c32.

📒 Files selected for processing (6)
  • changelog.md
  • pkg/constant/constant.go
  • zetaclient/chains/evm/evm.go
  • zetaclient/chains/solana/solana.go
  • zetaclient/chains/sui/sui.go
  • zetaclient/chains/ton/ton.go
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go

⚙️ CodeRabbit configuration file

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

Files:

  • zetaclient/chains/solana/solana.go
  • pkg/constant/constant.go
  • zetaclient/chains/evm/evm.go
  • zetaclient/chains/ton/ton.go
  • zetaclient/chains/sui/sui.go
🧠 Learnings (9)
📚 Learning: 2025-03-04T22:39:58.395Z
Learnt from: gartnera
Repo: zeta-chain/node PR: 3632
File: zetaclient/chains/solana/signer/signer.go:304-304
Timestamp: 2025-03-04T22:39:58.395Z
Learning: The Solana signer implementation in zetaclient/chains/solana/signer/signer.go has limited test coverage, particularly for the transaction broadcasting logic with fallback scenarios. Adding this coverage has been acknowledged as a potential future improvement outside the scope of immediate fixes.

Applied to files:

  • zetaclient/chains/solana/solana.go
  • zetaclient/chains/ton/ton.go
📚 Learning: 2024-10-08T15:34:48.217Z
Learnt from: ws4charlie
Repo: zeta-chain/node PR: 2907
File: zetaclient/chains/bitcoin/observer/outbound_test.go:81-82
Timestamp: 2024-10-08T15:34:48.217Z
Learning: In the `mineTxNSetNonceMark` function within `bitcoin/observer/outbound_test.go`, it's acceptable to hardcode the chain ID, as the tests do not require varying chain IDs.

Applied to files:

  • zetaclient/chains/solana/solana.go
  • zetaclient/chains/evm/evm.go
  • zetaclient/chains/ton/ton.go
  • zetaclient/chains/sui/sui.go
📚 Learning: 2025-09-15T13:42:17.594Z
Learnt from: lumtis
Repo: zeta-chain/node PR: 4199
File: zetaclient/chains/evm/signer/signer_admin.go:25-26
Timestamp: 2025-09-15T13:42:17.594Z
Learning: In PR 4199, the CLI references to CmdMigrateTssFunds in x/crosschain/client/cli/ files are intentionally not updated as they are out of scope for this specific refactor focused on removing ERC20 custody messages.

Applied to files:

  • pkg/constant/constant.go
📚 Learning: 2025-07-28T18:08:13.883Z
Learnt from: ws4charlie
Repo: zeta-chain/node PR: 4053
File: e2e/e2etests/test_bitcoin_std_deposit.go:42-42
Timestamp: 2025-07-28T18:08:13.883Z
Learning: In Bitcoin deposit E2E tests for the ZetaChain project, `DepositBTCWithAmount` is preferred over `DepositBTCWithExactAmount` because depositing exact amounts to a ZEVM receiver is complex. The tests use rough amounts and then calculate the actual received amount from the raw Bitcoin transaction to verify balance changes, making the tests more robust and less flaky.

Applied to files:

  • pkg/constant/constant.go
📚 Learning: 2025-01-22T22:46:58.820Z
Learnt from: gartnera
Repo: zeta-chain/node PR: 3395
File: .github/workflows/reusable-sim.yml:29-30
Timestamp: 2025-01-22T22:46:58.820Z
Learning: The zeta-chain/node repository uses Go version >= 1.22. Do not suggest downgrading to earlier versions like 1.21.

Applied to files:

  • zetaclient/chains/evm/evm.go
  • zetaclient/chains/ton/ton.go
📚 Learning: 2025-02-04T06:12:41.760Z
Learnt from: ws4charlie
Repo: zeta-chain/node PR: 3461
File: x/observer/types/chain_params.go:59-62
Timestamp: 2025-02-04T06:12:41.760Z
Learning: The legacy `ConfirmationCount` field in the ChainParams struct is planned to be deprecated after a full upgrade to the new confirmation count system that uses SafeInboundCount, FastInboundCount, SafeOutboundCount, and FastOutboundCount fields.

Applied to files:

  • zetaclient/chains/ton/ton.go
📚 Learning: 2024-10-30T17:56:16.341Z
Learnt from: gartnera
Repo: zeta-chain/node PR: 3070
File: cmd/zetae2e/init.go:0-0
Timestamp: 2024-10-30T17:56:16.341Z
Learning: In code reviews for Go files like `cmd/zetae2e/init.go` in the ZetaChain project, avoid suggesting unrelated refactoring. Focus comments on changes relevant to the PR objectives.

Applied to files:

  • zetaclient/chains/ton/ton.go
  • zetaclient/chains/sui/sui.go
📚 Learning: 2024-11-27T22:01:49.732Z
Learnt from: gartnera
Repo: zeta-chain/node PR: 3228
File: zetaclient/orchestrator/orchestrator.go:388-401
Timestamp: 2024-11-27T22:01:49.732Z
Learning: When reviewing code changes in `zetaclient/orchestrator/orchestrator.go`, avoid suggesting refactoring that is unrelated to the current PR.

Applied to files:

  • zetaclient/chains/ton/ton.go
  • zetaclient/chains/sui/sui.go
📚 Learning: 2024-10-31T16:19:26.038Z
Learnt from: gartnera
Repo: zeta-chain/node PR: 3071
File: e2e/e2etests/test_stress_eth_withdraw.go:58-59
Timestamp: 2024-10-31T16:19:26.038Z
Learning: In the Go code within `e2e/utils/zetacore.go`, the function `WaitCctxMinedByInboundHash` does not return an error.

Applied to files:

  • zetaclient/chains/ton/ton.go
🧬 Code graph analysis (2)
zetaclient/chains/evm/evm.go (1)
pkg/constant/constant.go (1)
  • OutboundLookbackFactor (51-51)
zetaclient/chains/ton/ton.go (3)
pkg/constant/constant.go (1)
  • OutboundLookbackFactor (51-51)
zetaclient/chains/base/signer.go (1)
  • OutboundIDFromCCTX (215-218)
zetaclient/chains/zrepo/zrepo.go (1)
  • ZetaRepo (46-52)
🔇 Additional comments (10)
zetaclient/chains/evm/evm.go (1)

13-13: LGTM! Shared constant refactoring is correctly applied.

The migration from a local outboundLookBackFactor constant to the shared constant.OutboundLookbackFactor maintains the same calculation logic while improving consistency across chain implementations.

Also applies to: 131-131

zetaclient/chains/sui/sui.go (1)

165-166: Verify the nonce boundary change from inclusive to exclusive.

The nonce validation changed from nonce >= maxNonce (implicit in old code) to nonce > maxNonce. This now allows nonces equal to maxNonce that were previously rejected. Please confirm this boundary relaxation is intentional and aligns with the desired scheduling behavior.

pkg/constant/constant.go (1)

47-51: LGTM! Well-documented shared constant.

The OutboundLookbackFactor constant is clearly documented with an example calculation, making it easy to understand its purpose in the outbound scheduling logic.

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

11-11: LGTM! Shared constant correctly applied.

The migration to constant.OutboundLookbackFactor maintains consistency with the EVM implementation.

Also applies to: 132-132


142-155: LGTM! Lookahead termination correctly implemented.

The addition of index tracking and the early return when int64(i) == scheduleLookahead correctly implements the lookahead limit. This ensures that the scheduler processes at most scheduleLookahead number of pending CCTXs per invocation, as intended by the PR objectives.

zetaclient/chains/ton/ton.go (5)

12-12: LGTM on the import addition.

The import of constant.OutboundLookbackFactor aligns with the shared constant usage across EVM, Solana, and Sui implementations, ensuring consistent lookback factor configuration.


129-132: LGTM on the early return guard.

Clean no-op pattern for empty CCTX list.


183-186: LGTM on the interval-based scheduling logic.

The modulo-based distribution nonce%interval == zetaHeight%interval effectively spreads keysign processing across blocks. The goroutine invocation for TryProcessOutbound ensures non-blocking execution, consistent with Sui and Solana implementations.


172-181: LGTM on the VoteOutboundIfConfirmed integration.

Error handling is appropriately structured: failures are logged and processing continues to avoid blocking subsequent CCTXs, while already-processed outbounds are correctly skipped with informational logging.


134-147: Remove division by zero concern; upstream validation prevents this issue.

The OutboundScheduleInterval is validated in x/observer/types/chain_params.go (lines 105–110) to reject zero values and enforce a range of [1, 100]. This validation is mandatory for all chain parameters before they are stored and retrieved by the observer. Consequently, the modulo operation at line 184 is safe, and the #nosec G115 positive comment is justified.

Likely an incorrect or invalid review comment.

@ws4charlie ws4charlie requested a review from kingpinXD January 2, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

nosec SUI_TESTS Run make start-sui-tests TON_TESTS Runs TON E2E tests zetaclient Issues related to ZetaClient

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants