feat: add tracing support for StateSyncTx#2062
feat: add tracing support for StateSyncTx#2062milando12 wants to merge 19 commits into0xPolygon:developfrom
Conversation
| start := time.Now() | ||
| cx := statefull.ChainContext{Chain: chain, Bor: c} | ||
|
|
||
| // Start tracing StateSyncTx (if present in the block body) |
There was a problem hiding this comment.
I think we might have integration tests locally (we maintain our own Polygon Live Tracing branch for now).
I'll check if I could add that on top of your PR.
There was a problem hiding this comment.
That sounds great. Feel free to add them on top of this PR whenever you're ready.
- Introduced `vm.Config` to multiple functions for customizable VM tracing. - Added tracer configuration flags (`vmtrace` and `vmtrace.jsonconfig`) to streamline monitoring during blockchain synchronization. - Updated GenesisContract and spanner interfaces for trace integration. - Integrated tracing hooks for StateSyncTx events.
Remove the 4 [DEBUG] log lines that were added during development to diagnose StateSyncTx tracing issues.
When Finalize is called, the chain parameter can be a *core.HeaderChain (not just *core.BlockChain). Without this change, the tracer in vmCfg is nil during finalization, so StateSyncTx tracing hooks never fire. - Add vmConfig field and GetVMConfig() method to HeaderChain - Set hc.vmConfig in NewBlockChain after creating the HeaderChain - Add else-if branch in Finalize and FinalizeAndAssemble to extract VM config from HeaderChain
The Process function creates a tracingStateDB wrapper for tracing but was passing the unwrapped statedb to Finalize, causing the tracer to miss StateSyncTx state changes.
da6e677 to
2b43baf
Compare
Expand the `CommitState` method signature to include the `vm.Config` parameter, enabling proper VM tracing integration and configuration.
EVM struct has a comment saying never reuse
Add support for preconf and private transaction APIs - Introduce new flags and APIs for preconf and private transactions. - Add methods for transaction preconfirmation and private transaction handling in backends and API layers. - Update transaction submission logic to support preconf/private paths. - Include tests for all new functionalities and edge cases.
- Update method signatures to include `vm.Config`, enabling better VM tracing and configuration integration in testing and state processing logic.
…lper function - Consolidate duplicate code for retrieving `vm.Config` from `ChainHeaderReader`. - Simplify `Finalize` method by utilizing the new helper.
The state processor now passes the traced (hooked) StateDB to the consensus engine's Finalize method, so live tracers can observe balance changes from block reward distribution. This is the correct behavior — previously, Finalize received the raw StateDB, making block rewards invisible to live tracers like the supply tracer. Update TestSupplyRewards and TestSupplyEip1559Burn to include the expected ethash block reward (2 ETH) in their assertions, matching the new traced output.
|
@claude - review this PR. |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
It won't be able to review this PR is from a fork, and hence it doesn't have perms to fetch the branch. |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
| cx := statefull.ChainContext{Chain: chain, Bor: c} | ||
|
|
||
| // Start tracing StateSyncTx (if present in the block body) | ||
| if hooks := vmCfg.Tracer; hooks != nil && hooks.OnTxStart != nil { |
There was a problem hiding this comment.
it seems like this starts a single tx trace before checkAndCommitSpan and the CommitStates loop, but statefull.ApplyMessage does not emit per-call OnTxStart/OnTxEnd hooks. Can this cause any issue on sprint blocks (span commits and multiple state-syncs) breaking tracers that keep single tx state? If that's the case, maybe the hooks need to wrap each system call, not the whole finalize.
| }) | ||
| body.Transactions = append(body.Transactions, stateSyncTx) | ||
| receipts = insertStateSyncTransactionAndCalculateReceipt(stateSyncTx, header, body, state, receipts) | ||
| receipts = insertStateSyncTransactionAndCalculateReceipt(stateSyncTx, header, body, state, receipts, vmCfg) |
There was a problem hiding this comment.
Can we make the tracer lifecycle symmetric between Finalize and FinalizeAndAssemble? I think there's a difference there wrt insertStateSyncTransactionAndCalculateReceipt calls
| "github.com/ethereum/go-ethereum/params" | ||
|
|
||
| // Force-load the tracer engines to trigger registration | ||
| _ "github.com/ethereum/go-ethereum/eth/tracers/js" |
There was a problem hiding this comment.
Do we need to register js and native tracers here? IIUC, you're only leveraging LiveDirectory in this PR.
| backtrace = "" # Request a stack trace at a specific logging statement (e.g. "block.go:271") | ||
| debug = true # Prepends log messages with call-site location (file and line number) | ||
| enable-block-tracking = false # Enables additional logging of information collected while tracking block lifecycle | ||
| vmtrace = "supply" # Name of a tracer to record internal VM operations during blockchain synchronization (costly) |
There was a problem hiding this comment.
Shouldn't VMTrace and VMTraceJsonConfig be top level fields? I see they’re under [log] here
consensus/bor/statefull/processor.go
Outdated
| return Callmsg{ | ||
| ethereum.CallMsg{ | ||
| From: systemAddress, | ||
| From: SystemAddress, |
There was a problem hiding this comment.
Can we use a getter here instead of exposing?
|
Can we ad integration tests that verify the trace output for a block containing a StateSyncTx? |
|


Description
Adding tracing support for
StateSyncTx.Changes
Checklist
Cross repository changes
Testing
Manual tests
Ran the Node with this code for few days - no problems showed up and I verified that
StateSyncTxtrace that we get is correct.