-
Notifications
You must be signed in to change notification settings - Fork 599
consensus/bor: don't leak the live tracer into non-import system transactions #2353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nebojsa94
wants to merge
1
commit into
0xPolygon:master
Choose a base branch
from
nebojsa94:fix/system-tx-live-tracer-leak
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+84
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package bor | ||
|
|
||
| import ( | ||
| "math/big" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/core/state" | ||
| "github.com/ethereum/go-ethereum/core/tracing" | ||
| "github.com/ethereum/go-ethereum/core/types" | ||
| "github.com/ethereum/go-ethereum/core/vm" | ||
| ) | ||
|
|
||
| // TestSystemTxVMConfig verifies that system transactions (span commits and | ||
| // state-sync events) are traced only when the caller traces the state they | ||
| // are applied to. The node-wide live tracer stored in c.vmConfig must never | ||
| // leak into contexts that pass a plain state (miner and eth_simulateV1 via | ||
| // FinalizeAndAssemble, historical state regeneration via Finalize): those run | ||
| // outside the import goroutine, and invoking the singleton live tracer | ||
| // concurrently corrupts it. | ||
| func TestSystemTxVMConfig(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| liveTracer := &tracing.Hooks{ | ||
| OnEnter: func(depth int, typ byte, from, to common.Address, input []byte, gas uint64, value *big.Int) { | ||
| t.Error("live tracer must not be invoked for untraced states") | ||
| }, | ||
| } | ||
| c := &Bor{vmConfig: vm.Config{Tracer: liveTracer, NoBaseFee: true}} | ||
|
|
||
| plainState, err := state.New(types.EmptyRootHash, state.NewDatabaseForTesting()) | ||
| require.NoError(t, err) | ||
|
|
||
| // A plain state (regeneration, miner, eth_simulateV1) must not get the | ||
| // live tracer, but keeps the rest of the config. | ||
| cfg := c.systemTxVMConfig(plainState) | ||
| require.Nil(t, cfg.Tracer) | ||
| require.True(t, cfg.NoBaseFee) | ||
|
|
||
| // A hooked state (canonical import with a live tracer) keeps being traced | ||
| // with the hooks that trace the state itself. | ||
| importHooks := &tracing.Hooks{} | ||
| cfg = c.systemTxVMConfig(state.NewHookedState(plainState, importHooks)) | ||
| require.Same(t, importHooks, cfg.Tracer) | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
systemTxVMConfigsetscfg.Tracer = nilwhenever the passed-in state does not implementstateTracingHooks, and the parallel state processor passes an unwrapped*state.StateDBtoFinalize. With--vmtraceenabled, bor span-commit and state-sync system transactions therefore execute with no tracer on the parallel execution path.Impact: Observability only — no state, receipt, or consensus output changes — but live-tracer streams lose bor system transactions on the parallel-processor path with no error or warning, making the gap data-dependent and hard to detect downstream by consumers building external indexes/state feeds.
Evidence — the helper drops the tracer rather than falling back to the engine config:
Only
*hookedStateDBsatisfiesstateTracingHooks(core/state/statedb_hooked.go:314), and the two import paths differ:The PR and commit bodies declare an intentional change away from
c.vmConfigfor system transactions, so the contract change itself is deliberate; what needs confirmation is whether dropping tracing on the parallel import path is also intended, since canonical import was meant to keep tracer coverage.Suggested fix: either wrap the state in
core/parallel_state_processor.gobefore callingFinalize, mirroring the serial path'sstate.NewHookedState(statedb, hooks), or fall back to the engine-configured tracer instead ofnil:Suggested test: import a block through the parallel state processor with a live tracer configured and assert that
OnTxStart/OnEnterfire for the bor span-commit and state-sync system transactions.Relatedly, the added
consensus/bor/vmconfig_test.go(TestSystemTxVMConfig) only covers the helper in isolation; consider adding coverage asserting that system-transaction tracing is preserved on canonical import and suppressed forFinalizeAndAssemble/eth_simulateV1.