Skip to content

feat(core): state journal wrapper #30441 #33978#2295

Open
gzliudan wants to merge 1 commit intoXinFinOrg:dev-upgradefrom
gzliudan:tracing-v1.1
Open

feat(core): state journal wrapper #30441 #33978#2295
gzliudan wants to merge 1 commit intoXinFinOrg:dev-upgradefrom
gzliudan:tracing-v1.1

Conversation

@gzliudan
Copy link
Copy Markdown
Collaborator

@gzliudan gzliudan commented Apr 9, 2026

Proposed changes

add some more changes for live tracing API:

  • Hook OnSystemCallStartV2 was introduced with VMContext as parameter.
  • Hook OnBlockHashRead was introduced.
  • GetCodeHash was added to the state interface
  • The new WrapWithJournal construction helps with tracking EVM reverts in the tracer.

Ref:

Types of changes

What types of changes does your code introduce to XDC network?
Put an in the boxes that apply

  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Changes that don't change source code or tests
  • docs: Documentation only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that neither fixes a bug nor adds a feature
  • revert: Revert something
  • style: Changes that do not affect the meaning of the code
  • test: Adding missing tests or correcting existing tests

Impacted Components

Which parts of the codebase does this PR touch?
Put an in the boxes that apply

  • Consensus
  • Account
  • Network
  • Geth
  • Smart Contract
  • External components
  • Not sure (Please specify below)

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

  • This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
  • Tested on a private network from the genesis block and monitored the chain operating correctly for multiple epochs.
  • Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
  • Tested the backwards compatibility.
  • Tested with XDC nodes running this version co-exist with those running the previous version.
  • Relevant documentation has been updated as part of this PR
  • N/A

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5d3cc3d6-1d6c-43d1-919f-ccbf2dce5362

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the core tracing/state interfaces to support richer live-tracing signals (nonce-change reasons, blockhash reads, and code-hash access) and adds a journaling wrapper to automatically emit reverse state-change events on EVM reverts.

Changes:

  • Added core/tracing.WrapWithJournal to journal state-change hooks and emit revert (“reverse”) events on call-frame failure.
  • Introduced OnBlockHashRead hook and emitted it from the BLOCKHASH opcode path.
  • Extended nonce handling with NonceChangeReason and updated SetNonce signatures/call sites accordingly.

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/state_test_util.go Updates test pre-state nonce initialization to the new SetNonce signature.
internal/ethapi/override/override.go Updates state override nonce setting to pass a nonce-change reason.
eth/tracers/live/noop.go Wires up the new OnBlockHashRead hook in the live noop tracer.
core/vm/runtime/runtime_test.go Updates runtime benchmark setup to the new SetNonce signature.
core/vm/interface.go Extends VM StateDB interface SetNonce to include NonceChangeReason.
core/vm/instructions.go Emits OnBlockHashRead when executing BLOCKHASH.
core/vm/evm.go Tags contract-creation nonce changes with explicit nonce-change reasons.
core/txpool/legacypool/legacypool_test.go Updates txpool tests for new SetNonce signature.
core/tracing/journal.go Adds journaling wrapper implementation to replay reverse state changes on reverts.
core/tracing/journal_test.go Adds unit tests validating journaling wrapper behavior and hook coverage.
core/tracing/hooks.go Adds OnBlockHashRead, NonceChangeReason, OnNonceChangeV2, and GetCodeHash to tracing interfaces.
core/tracing/gen_balance_change_reason_stringer.go Updates generated stringer for new BalanceChangeRevert enum value.
core/tracing/CHANGELOG.md Documents new hooks/types and the journaling wrapper.
core/state/statedb.go Updates StateDB.SetNonce signature to accept NonceChangeReason.
core/state/statedb_utils.go Updates nonce increment helper to pass a nonce-change reason.
core/state/statedb_test.go Updates state tests for the new SetNonce signature.
core/state/statedb_hooked.go Propagates nonce-change reasons into tracing hooks (preferring V2 when present).
core/state/statedb_hooked_test.go Updates hooked statedb tests to pass a nonce-change reason.
core/state/statedb_fuzz_test.go Updates fuzz test actions to use the new SetNonce signature.
core/state_transition.go Tags transaction/authorization nonce changes with explicit reasons.
core/state_processor.go Tags nonce increments during tx processing and system processing with reasons.
core/state_processor_test.go Updates tests for new SetNonce signature in processor tests.
core/genesis.go Tags genesis nonce initialization with NonceChangeGenesis.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gzliudan gzliudan changed the title feat(core): state journal wrapper #30441 feat(core): state journal wrapper #30441 #33978 Apr 9, 2026
@gzliudan gzliudan force-pushed the tracing-v1.1 branch 3 times, most recently from 3cfa267 to a24f238 Compare April 9, 2026 10:35
@gzliudan gzliudan requested a review from Copilot April 9, 2026 10:36
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// invoked by the go-ethereum core at various points in the state transition.
//
// To create a tracer that can be invoked with Geth, you need to register it using
// [github.com/ethereum/go-ethereum/eth/tracers.LiveDirectory.Register].
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package-level docs link to github.com/ethereum/go-ethereum/eth/tracers.LiveDirectory.Register, but in this repo the package is github.com/XinFinOrg/XDPoSChain/eth/tracers (see eth/tracers/live.go). This makes the godoc link incorrect/broken; please update the reference to the correct module path (or use a relative reference) to keep docs accurate for this fork.

Suggested change
// [github.com/ethereum/go-ethereum/eth/tracers.LiveDirectory.Register].
// [github.com/XinFinOrg/XDPoSChain/eth/tracers.LiveDirectory.Register].

Copilot uses AI. Check for mistakes.
}

func (t *testTracer) OnStorageChange(addr common.Address, slot common.Hash, prev common.Hash, new common.Hash) {
t.t.Logf("OnStorageCodeChange(%v, %v, %v -> %v)", addr, slot, prev, new)
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log message says OnStorageCodeChange, but the hook is OnStorageChange. This looks like a copy/paste typo and can make test output confusing; consider renaming it to match the hook name.

Suggested change
t.t.Logf("OnStorageCodeChange(%v, %v, %v -> %v)", addr, slot, prev, new)
t.t.Logf("OnStorageChange(%v, %v, %v -> %v)", addr, slot, prev, new)

Copilot uses AI. Check for mistakes.
add some more changes for live tracing API:

- Hook OnSystemCallStartV2 was introduced with VMContext as parameter.
- Hook OnBlockHashRead was introduced.
- GetCodeHash was added to the state interface
- The new WrapWithJournal construction helps with tracking EVM reverts in the tracer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants