fix(vm): isolate constant-call config, self-dispatch vote-witness cost#6857
Open
yanghang8612 wants to merge 2 commits into
Open
fix(vm): isolate constant-call config, self-dispatch vote-witness cost#6857yanghang8612 wants to merge 2 commits into
yanghang8612 wants to merge 2 commits into
Conversation
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.
8b1cae6 to
1f8e8e5
Compare
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.
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
VMConfigis 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 afinally.2. Self-dispatch the vote-witness cost by proposal flag
getVoteWitnessCost3now falls back tocost2when Osaka is off, andcost2falls 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;commonandactuatormodule tests green.