Skip to content

fix(vm): isolate constant-call config, self-dispatch vote-witness cost#6857

Open
yanghang8612 wants to merge 2 commits into
tronprotocol:release_v4.8.2from
yanghang8612:vm-config-vote-482
Open

fix(vm): isolate constant-call config, self-dispatch vote-witness cost#6857
yanghang8612 wants to merge 2 commits into
tronprotocol:release_v4.8.2from
yanghang8612:vm-config-vote-482

Conversation

@yanghang8612

Copy link
Copy Markdown
Collaborator

Summary

Two related TVM consensus-safety fixes around how per-execution config/cost is selected when constant calls (triggerConstantContract / estimateEnergy) run concurrently with block processing, or after a reorg.

1. Isolate constant-call VMConfig from the process global

VMConfig is a process-global static, reloaded on every VM execution. A constant call served by the solidity/PBFT interface runs with the chainbase cursor on a lagging (not-yet-solidified) snapshot, so it loaded stale proposal flags into the global static, racing the block-processing thread during a proposal's activation-to-solidification window — a fork risk.

This routes a constant call's flags into a thread-local VMConfig.Snapshot; the block/broadcast path keeps writing and reading the process-global snapshot, and the getters read the thread-local view if present, otherwise the global. The constant-call path clears its thread-local view in a finally.

2. Self-dispatch the vote-witness cost by proposal flag

getVoteWitnessCost3 now falls back to cost2 when Osaka is off, and cost2 falls back to the legacy cost when energy adjustment is off. The vote-witness energy then stays correct even if a stale cost function lingers in the shared jump table after a reorg, or is read by a constant call whose view has the proposal off.

Tests

  • VMConfigIsolationTest: a thread's local snapshot does not pollute the global config that another thread reads; installing a global snapshot drops the thread-local view.
  • VoteWitnessCost3Test: cost self-dispatch (cost3 -> cost2 -> legacy) plus the existing overflow cases.
  • org.tron.common.runtime.vm.* package green; common and actuator module tests green.

@github-actions github-actions Bot requested a review from CodeNinjaEvan June 25, 2026 13:06
@yanghang8612 yanghang8612 changed the title fix(vm): isolate constant-call config and self-dispatch vote-witness cost fix(vm): isolate constant-call config, self-dispatch vote-witness cost Jun 25, 2026
getVoteWitnessCost3 falls back to cost2 when Osaka is off, and cost2 to the legacy cost when energy adjustment is off. The energy then stays correct even if a stale cost function lingers in the shared jump table after a reorg, or is read by a constant call whose view has the proposal off.
Constant calls bound to a lagging solidity/PBFT snapshot loaded their flags into the process-global VMConfig, racing block processing during a proposal's activation-to-solidification window and risking a fork. Route a constant call's config into a thread-local snapshot; the block/broadcast path keeps writing (and reading) the global.
@halibobo1205 halibobo1205 added the topic:vm VM, smart contract label Jun 26, 2026
@halibobo1205 halibobo1205 added this to the GreatVoyage-v4.8.2 milestone Jun 26, 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.

2 participants