Skip to content

feat(vm): optimize resource processing (TIP-945) - #7069

Open
yanghang8612 wants to merge 9 commits into
feature/tip-944-voting-powerfrom
feature/tip-945-resource-processing
Open

yanghang8612 wants to merge 9 commits into
feature/tip-944-voting-powerfrom
feature/tip-945-resource-processing

Conversation

@yanghang8612

@yanghang8612 yanghang8612 commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Implement TIP-945 behind ALLOW_TVM_RESOURCE_OPTIMIZATION (104), applying the specified vote-input validation order and per-account Stake 2.0 weight accounting.

Behind the same parameter, persist the restored Stake 2.0 energy window when a successful contract transaction uses no energy.

Behind the same parameter, and only while Stake 2.0 is enabled, contract execution uses the same fractional energy weight as the account-resource query.

Behind the same parameter, use per-process seeded hashing for VM repository keys with independent unsigned 32-bit word coefficients. A fixed table covers keys up to 80 bytes; longer keys retain the legacy full-input hash.

Also recheck the transaction CPU deadline after nested contract execution returns.

Why are these changes required?

Keep TVM resource processing consistent with the protocol's validation and accounting rules. Reduce predictable repository-key collision families and catch nested execution that exhausts the CPU deadline in its final opcode.

Related to TIP-945.

This PR has been tested by:

  • ./gradlew clean build -x test on macOS ARM64 / JDK 17.
  • 101 targeted regression tests passed on macOS ARM64 / JDK 17, covering key collision families, proposal switches, long-key compatibility, jump-destination cache recompilation/eviction, storage migration, nested calls, TIP-945, and resource calculation.
  • 13 Key and jump-destination-cache regression tests passed on macOS x86_64 / JDK 8 (Rosetta).
  • A deterministic 24-case post-child CPU deadline probe passed for CALL, CALLCODE, DELEGATECALL, STATICCALL, CREATE, and CREATE2, with parameter 104 on/off and expired/unexpired deadlines.
  • Required Checkstyle tasks, .github/scripts/check_math_usage.sh, and git diff --check.
  • The full-suite attempt (./gradlew test --fail-fast) did not pass: LookUpTxtTest.testLookUpIp_nonexistentDomain_returnsNull received 198.18.2.51 for an .invalid domain in this machine's DNS environment. DbLiteRocksDbTest also hit a localhost gRPC deadline; that test passed when rerun alone. The remaining full-suite run was cancelled after these failures.

Follow up

Merge the TIP-944 implementation first, then rebase/retarget this PR onto release_v4.8.3.

Extra details

Targets feature/tip-944-voting-power so this review contains only TIP-945 changes. This is a branch dependency; runtime activation remains independent. Proposal validation, application, and parameter output follow the order 102, 103, 104.

@halibobo1205 halibobo1205 added this to the GreatVoyage-v4.8.3 milestone Oct 28, 2026
@halibobo1205 halibobo1205 added the topic:vm VM, smart contract label Oct 28, 2026
@yanghang8612
yanghang8612 force-pushed the feature/tip-945-resource-processing branch from db3830a to b88c860 Compare October 29, 2026 10:03
clearOwnerFreezeV2(ownerCapsule);
repo.updateAccount(ownerCapsule.createDbKey(), ownerCapsule);
repo.updateAccount(inheritorCapsule.createDbKey(), inheritorCapsule);
if (weightsBefore != null) {

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.

Using operation-local before/after weights keeps sequential transfers consistent with per-account rounding.

Gate seeded repository-key hashing and post-child CPU deadline checks behind
ALLOW_TVM_RESOURCE_OPTIMIZATION. Mix unsigned 32-bit words with a fixed
per-process seed table and retain the legacy hash for keys over 80 bytes.

Cover collision families, proposal switches, long-key compatibility, and
jump-destination cache recompilation and eviction. Select the proposal mode
before populating TIP-945 test repository caches.
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: No status

Development

Successfully merging this pull request may close these issues.

3 participants