Skip to content

feat(vm): add node-level vm.constantCallTimeoutMs for constant calls#6719

Open
yanghang8612 wants to merge 2 commits intodevelopfrom
feat/constant-call-timeout
Open

feat(vm): add node-level vm.constantCallTimeoutMs for constant calls#6719
yanghang8612 wants to merge 2 commits intodevelopfrom
feat/constant-call-timeout

Conversation

@yanghang8612
Copy link
Copy Markdown
Collaborator

What does this PR do?

Adds a node-level config vm.constantCallTimeoutMs (range [80, 500] ms; default 0 = sentinel meaning "use the network's maxCpuTimeOfOneTx") that extends the TVM execution-time window for triggerconstantcontract and eth_call only. Block-processing deadline is unchanged.

Pairs with vm.constantCallMaxConcurrency (default 10). The cap engages strictly when the operator's configured timeout exceeds the network's current maxCpuTimeOfOneTx; nodes leaving the timeout at 0 see no behaviour change — no new throttling, no regression on high-throughput RPC paths.

Closes #6681.

Why are these changes required?

triggerconstantcontract / eth_call are widely used for state queries and dry-runs but cap out at the same TVM deadline as block-processing (mainnet 80 ms). Operators currently have only --debug to extend this window, which also removes the block-processing timeout — unsafe for any node serving traffic, since it can desync from the network (#6266). This PR gives operators a scoped lever for the constant-call window without that side effect.

Design highlights:

  • Block-processing is structurally unaffected. The constant-call branch is gated by isConstantCall, so the new code path is unreachable from block validation — guaranteed by structure, not by convention.
  • Operators can only extend, never shrink. VmTimeoutPolicy.computeVmShouldEndInUs uses max(configured, networkMs) for the budget; setting a value below the current maxCpuTimeOfOneTx is a no-op (equivalent to sentinel 0).
  • Cap engagement is runtime. Wallet.callConstantContract reads the live maxCpuTimeOfOneTx from DynamicPropertiesStore and passes it to VmTimeoutPolicy.isCapEngaged. If the network committee raises maxCpuTimeOfOneTx later, the cap-engagement threshold tracks it automatically.
  • Sub-frames inherit the deadline. Cross-contract simulation uses the existing Program plumbing (getVmShouldEndInUs() is propagated to internal ProgramInvoke instances), so the override applies to deep call trees — the headline use case.
  • Validation is config-load only. VmConfig.postProcess() rejects values outside [80, 500]. Note: at config-load time the DB isn't open yet, so this >= 80 floor is a sanity check, not a comparison against the live network value; the runtime max(...) keeps semantics correct regardless.
  • Math safety. All arithmetic uses org.tron.common.math.StrictMathWrapper (max, multiplyExact, addExact) per the repo's math-check CI policy.

This PR has been tested by:

  • Unit Tests
    • VmTimeoutPolicyTest (11 cases): deadline math, max-of semantics (never shrink below network), block-processing isolation, cap-engagement gate against runtime network value.
    • VmConfigTest (6 new cases): defaults 0 / 10; valid override 200 / 4; boundary 0 / 80 / 500 accepted; < 80, > 500, and cap = 0 rejected.
    • Existing ArgsTest and WalletTest / WalletMockTest still green.

Follow up

Operators currently running with --debug purely to extend the constant-call window should switch to vm.constantCallTimeoutMs=<ms> once this lands. --debug additionally extends the block-processing timeout, which is unsafe for any node serving traffic (see #6266). Release notes will spell this out at both touchpoints.

Extra details

New config knob extends the TVM execution window for
triggerconstantcontract / eth_call only; pairs with a
concurrency cap that engages when the configured timeout
exceeds the network's current maxCpuTimeOfOneTx. Issue #6681.
VmTimeoutPolicy: deadline math, max-of semantics (never shrink
below network), and cap-engagement gate against the runtime
network value. VmConfig: 0 sentinel, [80, 500] range, cap > 0.
@github-actions github-actions Bot requested a review from CodeNinjaEvan April 28, 2026 11:02
@halibobo1205 halibobo1205 added this to the GreatVoyage-v4.8.2 milestone Apr 28, 2026
@halibobo1205 halibobo1205 added the topic:vm VM, smart contract label Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:vm VM, smart contract

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add a node-level configuration to control the TVM execution time limit for constant calls

2 participants