Repository navigation
feat(vm): optimize V2 energy usage reset precision (TIP-945) - #7126
Merged
yanghang8612 merged 1 commit intoNov 25, 2026
Merged
yanghang8612 merged 1 commit into
yanghang8612 merged 1 commit into
Conversation
CodeNinjaEvan
approved these changes
Nov 24, 2026
| return value * numerator / denominator; | ||
| } | ||
|
|
||
| public void resetAccountUsage(AccountCapsule accountCap, |
Collaborator
There was a problem hiding this comment.
Unifying the resource-calculation methods in EnergyProcessor is the right split. With proposal 104 on, measuring and dividing the reservation on the same window fixes both the one-slot floor erasure and the equal-window scale-up. The old slot formula stays in place until 104 is enabled.
Move account energy usage reset methods from TransactionTrace to EnergyProcessor and refine V2 window reset under allowTvmResourceOptimization (TIP-945): - Record merged V2 window sizes (x1000 precision) for caller and origin in ReceiptCapsule and VMActuator. - In EnergyProcessor.resetAccountUsageV2, perform V2 area and window selection using V2 window sizes when allowTvmResourceOptimization is enabled, using BigInteger when allowHardenResourceCalculation is active and long V2 arithmetic otherwise, while preserving pre-proposal behavior when disabled. - Apply allowHardenResourceCalculation BigInteger arithmetic to V1 reset as well under allowTvmResourceOptimization. - Tighten getMaxResetEnergyUsage() from 2x to 1x totalEnergyCurrentLimit. - Add and update unit tests in Tip945VmTest covering V2 precision reset across proposal and hardening flags, large-usage hardened reset, and the 1x cap.
yanghang8612
force-pushed
the
opt/energy-usage-reset-precision
branch
from
November 25, 2026 06:11
39f491a to
37a5c9b
Compare
aiden3885
approved these changes
Nov 25, 2026
alan-eth
approved these changes
Nov 25, 2026
yanghang8612
merged commit Nov 25, 2026
3bddf57
into
tronprotocol:release_v4.8.3
12 of 13 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Refine Stake 2.0 account energy usage reset precision under
allowTvmResourceOptimization(TIP-945) and consolidate reset logic intoEnergyProcessor:ReceiptCapsule.java&VMActuator.java:callerEnergyMergedWindowSizeV2andoriginEnergyMergedWindowSizeV2, in ×1000 precision) alongside existing merged slot-window snapshots.EnergyProcessor.java&TransactionTrace.java:resetAccountUsage,resetAccountUsageV2, andcheckResetEnergyUsagefromTransactionTraceintoEnergyProcessor.resetAccountUsageV2, whenallowTvmResourceOptimization()is enabled, perform area calculation and window-merge selection uniformly in V2 (×1000) precision (currentSize2/mergedSize2/size2/newSize2), usingBigIntegerwhenhardenCalculation()(ALLOW_HARDEN_RESOURCE_CALCULATION) is enabled andlongV2 arithmetic otherwise.hardenCalculation()BigIntegerarithmetic consistently to V1resetAccountUsageunderallowTvmResourceOptimization().getMaxResetEnergyUsage()from2 * totalEnergyCurrentLimitto1 * totalEnergyCurrentLimit.allowTvmResourceOptimization()is disabled.Tip945VmTest.java:allowTvmResourceOptimization×allowHardenResourceCalculationflag combinations, large-usage hardened reset, and the1 * totalEnergyCurrentLimitupper-bound check.Why are these changes required?
Under Stake 2.0 V2 window accounting, window sizes are stored at ×1000 precision, while
resetAccountUsageV2previously computed the post-execution area using truncated slot-level window sizes (getWindowSize). AligningresetAccountUsageV2to V2 precision under TIP-945, pairing it withhardenCalculation(), and tightening the reset upper bound tototalEnergyCurrentLimitkeeps energy window accounting consistent and avoids intermediate precision loss or overflow. Moving the reset methods intoEnergyProcessoralso co-locates all energy usage calculation helpers in one processor class.This PR has been tested by:
./gradlew :framework:test --tests "org.tron.core.vm.nativecontract.Tip945VmTest"(16/16 passed)../gradlew :framework:test --tests "org.tron.core.db.TransactionTraceTest"(6/6 passed)../gradlew :framework:test --tests "org.tron.core.EnergyProcessorTest"(3/3 passed)../gradlew :framework:test --tests "org.tron.core.db.ResourceProcessorHardenTest"(10/10 passed)../gradlew :framework:checkstyleMain :framework:checkstyleTest :plugins:checkstyleMainpassed.bash .github/scripts/check_math_usage.shpassed with 0 violations.Follow up
None.
Extra details
Strictly gated behind
allowTvmResourceOptimization(TIP-945); pre-proposal behavior remains unchanged.