Skip to content

perf(vm): improve parallel precompile timeout handling - #7026

Merged
yanghang8612 merged 2 commits into
tronprotocol:release_v4.8.3from
yanghang8612:opt/precompile-parallel-timeout
Oct 27, 2026
Merged

yanghang8612 merged 2 commits into
tronprotocol:release_v4.8.3from
yanghang8612:opt/precompile-parallel-timeout

Conversation

@yanghang8612

@yanghang8612 yanghang8612 commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

This PR is a first-step optimization toward #6697, focused on parallel execution in BatchValidateSign and VerifyTransferProof.

Share deadline-aware waiting and result collection, and cancel unfinished tasks on timeout, interruption, worker failure, or partial submission failure. Result reads are bounded when the VM's transaction-end CPU check applies.

Why are these changes required?

VerifyTransferProof previously used unbounded Future.get() calls after its timed latch wait. Even when the latch reaches zero, a worker may not have published its result yet. Unsuccessful exits could also leave submitted tasks running or queued.

This PR has been tested by:

Validated on JDK 17 / macOS ARM64 after rebasing:

  • ./gradlew clean build -x test passed.
  • The CI Checkstyle command, the Math usage script, and git diff --check passed.
  • The framework suite completed 4,336 tests with zero failures (12 skipped), including all 24 terminal precompile VM scenarios and all 11 RelayServiceTest cases.
  • All 15 parallel waiting/result collection tests passed.

The local full-suite run encountered two DNS environment failures in p2p tests: the system resolves reserved .invalid names to 198.18.* addresses. Those tests are unchanged by this PR; the CI matrix provides verification on its normal resolver.

Follow up

The broader work in #6697 remains open, including common precompile entry/exit checks, consistent timeout propagation, and internal checkpoints. Full-VM differential tests comparing receipts, energy accounting, state, and logs, along with replay compatibility and activation assessment, are also follow-up work.

Extra details

The branch is rebased onto release_v4.8.3 through 409a33f21e, including the upstream HELLO test fixture fix from #7060.

Preserves historical timeout behavior for debug, solidity, and pre-energy-adjustment execution. Precompile addresses, ABI, and energy pricing are unchanged. Cancellation of running work remains best effort.

@halibobo1205 halibobo1205 added this to the GreatVoyage-v4.8.3 milestone Oct 13, 2026
@halibobo1205 halibobo1205 added the topic:vm VM, smart contract label Oct 13, 2026
@yanghang8612 yanghang8612 changed the title opt(vm): improve parallel precompile timeout handling perf(vm): improve parallel precompile timeout handling Oct 13, 2026

@sunny-tron sunny-tron left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A couple of notes after reading through the timeout paths:

  1. awaitParallel (via getCPUTimeLeftInNanoSecond()), readFuture and allowTimedOutResult each read getVmShouldEndInUs() separately. The equivalence with Program#checkCPUTimeLimit relies on all three using the same deadline as the calling program, so reading it once (for example at the start of collectParallel) and passing the value down would make that explicit and keep the three checks consistent.

  2. The new tests exercise the helpers with hand-set deadlines. Since the change is meant to leave transaction results unchanged, a test at the Program/VMActuator level showing that a timed-out BatchValidateSign / VerifyTransferProof call still ends as OUT_OF_TIME with the same energy usage under energy adjustment would cover the part that matters most for compatibility.

@yanghang8612

Copy link
Copy Markdown
Collaborator Author

Thanks @sunny-tron. Both points are addressed in 9be9f29:

  1. collectParallel now captures getVmShouldEndInUs() once and passes that deadline to the latch wait, future reads and timeout-result check. The historical latch deadline and the microsecond boundary used by Program#checkCPUTimeLimit are preserved. A focused helper test also verifies that collection reads the deadline only once.

  2. Added 24 parameterized regression cases that run a terminal precompile CALL through the real Program, VMActuator.execute() and runtime result mapping for both BatchValidateSign and VerifyTransferProof. They cover normal completion, latch timeout and delayed Future publication across normal, energy-adjustment-disabled, debug and solidity modes. With energy adjustment enabled in normal mode, timeout cases assert OUT_OF_TIME, the transaction-end CPU check and full transaction energy consumption. The other cases check the expected return bytes and energy usage.

The tests control task completion through a scoped FutureTask construction mock, so no worker fields or executor replacement were added to production code. Successful cases have a 5-second budget; timeout cases retain a separate 150ms budget.

Validation: all 45 targeted tests passed with test retries disabled, and Checkstyle passed. An additional temporary 300ms scheduling-pause probe passed all 8 normal-completion cases; the probe was removed before committing.

Collect parallel precompile results against the remaining VM deadline and
cancel unfinished tasks on timeout, interruption, and failed submission.
Preserve the existing timeout policies for BatchValidateSign and
VerifyTransferProof, including debug, solidity, and pre-energy-adjustment
execution.

Add regression coverage for delayed result publication, interruption,
worker failure, and cancellation.
@yanghang8612
yanghang8612 force-pushed the opt/precompile-parallel-timeout branch 2 times, most recently from 03f1349 to 879b50d Compare October 27, 2026 07:49
Capture the invocation deadline once for the latch wait and result reads,
and cover terminal precompile calls through the VM, actuator, and runtime
across CPU enforcement modes.
@yanghang8612
yanghang8612 force-pushed the opt/precompile-parallel-timeout branch from 879b50d to a6c9698 Compare October 27, 2026 08:21

@CodeNinjaEvan CodeNinjaEvan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@yanghang8612
yanghang8612 merged commit b241f33 into tronprotocol:release_v4.8.3 Oct 27, 2026
12 of 13 checks passed
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

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants