[Feature] Standardize precompile execution with fine-grained timeout checks
Maintainers usually reply within 1 day
@yanghang8612 is already working on this.
Since Jun 5, 2026.
Assessment
This issue has not been assessed yet.
Description
Summary
Standardize execution across all TVM precompiled contracts, using a shared CPU-deadline policy, consistent timeout propagation, and resource cleanup. Add fine-grained internal checkpoints where the work warrants them, including iterative computation, multi-stage verification, and parallel tasks.
The common execution pattern applies to every precompile. Internal checkpoint placement should reflect the cost and structure of each implementation, including its helper methods. Lightweight operations can use common entry/exit checks; more substantial work needs checks between meaningful units of execution.
Motivation
Precompiles cover several execution shapes: fixed-work operations, collection traversal, iterative cryptographic computation, staged library calls, and parallel verification. Their execution wrappers, exception handling, and resource management have evolved separately.
A shared pattern would make the VM's CPU-budget contract easier to implement, review, and test across these shapes. BatchValidateSign and VerifyTransferProof remain the initial parallel-execution integration points, while the broader source review supports applying the same principles throughout the precompile set.
Proposed Solution
1. Establish a common execution lifecycle
Introduce a shared wrapper, for example execute(...) delegating to a precompile-specific doExecute(...), with:
- Entry and exit deadline checks under the applicable VM execution policy.
- Internal checkpoints in the implementation or its helpers where appropriate.
- Consistent propagation of
OutOfTimeExceptionthrough the public execution boundary. - Cleanup of resources and unfinished tasks owned by the invocation.
Preserve each precompile's ABI, result encoding, and ordinary input-validation and error semantics. Treat elapsed-time enforcement separately from existing fork-gated validation rules.
2. Use one deadline throughout the invocation
Sequential stages, helper methods, parallel workers, and blocking waits should use the same execution deadline. Each wait consumes the remaining budget rather than starting a new one.
Align the clock, units, expiration boundary, and timeout-enable policy with the VM. Validate all supported execution modes, including transaction execution, constant calls, replay, and debug operation. Workers that need checkpoints should receive the invocation's execution context explicitly.
3. Match checkpoint granularity to the work
Use the source inventory in the follow-up analysis to guide implementation:
- Internal execution changes: integrate checkpoints and task lifecycle handling into iterative, staged, or parallel work.
- Further granularity evaluation: use benchmarks to decide whether chunked computation provides enough benefit to justify the additional checks.
- Common-wrapper integration: retain simple implementations and small bounded traversals unless measurements justify additional internal checks.
Review shared parsing, signature, proof, and computation helpers as well as the visible execute(...) methods. Place checkpoints between meaningful work units and around library calls where supported, while preserving cryptographic and protocol behavior.
This is cooperative deadline enforcement. Checkpoint placement and cancellation must respect the capabilities of the underlying computation libraries; immediate interruption of every operation is not an implementation guarantee.
4. Share parallel execution and cleanup
Provide common handling for submission, deadline-aware waiting, result collection, and cancellation. Apply the same deadline throughout this lifecycle and make cleanup cover unsuccessful exits, including interruption and partial submission.
Preserve the caller's interrupt status where applicable, maintain the distinction between timeout and ordinary task failure, and propagate worker exceptions according to the common execution policy. Cancellation of running work is best effort and should be tested separately from cancellation of queued work.
Validation
- Verify common entry/exit behavior and timeout propagation through wrappers, helpers, and parallel execution.
- Use a controllable clock and isolated executors for deterministic lifecycle and cleanup tests.
- Cover sequential, staged, and parallel implementations, including successful execution and ordinary validation failures.
- Compare result encoding, receipts, energy accounting, state, and logs where applicable across supported execution modes.
- Benchmark representative supported workloads to select checkpoint frequency and assess overhead.
- Validate replay compatibility and activation requirements before rollout.
Impact and Compatibility
The intended outcome is a consistent precompile execution contract, appropriate internal deadline checks, and maintainable task/resource handling.
No precompile address, ABI, or energy-pricing change is intended. Normal successful and ordinary validation behavior should be preserved. Changes to timeout handling and checkpoint placement still require compatibility testing; consensus neutrality and the absence of a fork gate must not be assumed in advance.
The source inventory is an implementation-planning assessment. Final checkpoint placement and scope remain subject to implementation, regression testing, and performance measurements.
References
PrecompiledContracts.java: precompile implementations and common base.VM.javaandProgram.java: VM execution policy.VMActuator.java: execution result handling.
Additional Notes
- Do you have ideas regarding implementation? Yes.
- Are you willing to implement this feature? Yes.
- Dominant language
- Java
- Stars
- 4.2k
- Forks
- 1.8k
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 51
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tronprotocol/java-tron
-
Difficulty 3/5 1-2 days Newbie friendliness 70/100
tronprotocol/java-tron#7044 · 4 comments ·
Maintainers usually reply within 1 day
-
[Feature] Remove unused discovery message definitionsPossibly taken A pull request linked to this issue is open or already merged. Opentype:feature
Difficulty 4/5 3-5 days Newbie friendliness 35/100
tronprotocol/java-tron#7013 · 3 comments ·
Maintainers usually reply within 1 day
-
[Feature] Validate ECKey inputs and improve key handlingPossibly taken A pull request linked to this issue is open or already merged. Opentype:feature
Difficulty 4/5 3-5 days Newbie friendliness 40/100
tronprotocol/java-tron#6994 · 5 comments ·
Maintainers usually reply within 1 day
-
type:feature
Difficulty 5/5 Over a week Newbie friendliness 25/100
tronprotocol/java-tron#6989 · 7 comments ·
Maintainers usually reply within 1 day
-
[Feature] decouple json-rpc filter processing from ManagerPossibly taken A pull request linked to this issue is open or already merged. Opentype:feature
Difficulty 5/5 Over a week Newbie friendliness 48/100
tronprotocol/java-tron#6963 · 8 comments ·
Maintainers usually reply within 1 day
All issues in tronprotocol/java-tron
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
citrusframework/citrus#2044 ·
Maintainers usually reply within 1 day
-
[bug]打火石不能被放在厨具架上Open
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
KaleidoscopeMods/KaleidoscopeCookery#237 · 1 comment ·
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
molgenis/molgenis-emx2#7059 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
quarkiverse/quarkus-flow#1169 ·
Maintainers usually reply within 1 day