Skip to content

refactor(core): storage journal entry should revert dirtyness too #29641#2078

Merged
AnilChinchawale merged 1 commit intoXinFinOrg:dev-upgradefrom
gzliudan:state-journal-storage-revert
Mar 6, 2026
Merged

refactor(core): storage journal entry should revert dirtyness too #29641#2078
AnilChinchawale merged 1 commit intoXinFinOrg:dev-upgradefrom
gzliudan:state-journal-storage-revert

Conversation

@gzliudan
Copy link
Collaborator

Proposed changes

Currently our state journal tracks each storage update to a contract, having the ability to revert those changes to the previously set value.

For the very first modification however, it behaves a bit wonky. Reverting the update doesn't actually remove the dirty-ness of the slot, rather leaves it as "change this slot to it's original value". This can cause issues down the line with for example write witnesses needing to gather an unneeded proof.

This PR modifies the storageChange journal entry to not only track the previous value of a slot, but also whether there was any previous value at all set in the current execution context. In essence, the PR changes the semantic of storageChange so it does not simply track storage changes, rather it tracks dirty storage changes, an important distinction for being able to cleanly revert the journal item.

Ref: ethereum#29641

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

Copilot AI review requested due to automatic review settings February 24, 2026 10:52
@coderabbitai
Copy link

coderabbitai bot commented Feb 24, 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.

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
  • Post copyable unit tests in a comment

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

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 adjusts state journaling so reverting a storage journal entry can also clear the “dirty” marker for a slot when the reverted write was the first modification in the current execution context, preventing downstream components (e.g., witness/proof generation) from treating the slot as unnecessarily changed.

Changes:

  • Refactors storage slot reads to distinguish “dirty in current context” vs “committed value” (GetState + new internal getState).
  • Changes storageChange journal entries to optionally track a previous dirty value (or none), enabling revert to remove dirtiness.
  • Updates setState to support deleting a dirty slot entry on revert.

Reviewed changes

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

File Description
core/state/state_object.go Introduces dirty-aware storage reads and enables setState to delete dirty markers on revert.
core/state/journal.go Updates storageChange to store an optional previous value and uses it during revert.

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

Comment on lines +197 to +200
var prevvalue *common.Hash
if dirty {
prevvalue = &prev
}
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

Using *common.Hash for storageChange.prevvalue causes prevvalue = &prev to escape and allocate on the heap for every subsequent write to an already-dirty slot. Since this is a hot path, consider storing the previous value by value plus a separate boolean flag indicating whether it existed (dirty), avoiding per-write allocations.

Copilot uses AI. Check for mistakes.
Comment on lines +211 to +217
// setState updates a value in account dirty storage. If the value being set is
// nil (assuming journal revert), the dirtyness is removed.
func (s *stateObject) setState(key common.Hash, value *common.Hash) {
// If the first set is being reverted, undo the dirty marker
if value == nil {
delete(s.dirtyStorage, key)
return
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

This change introduces new semantics where reverting the first SetState should remove the dirty marker (delete from dirtyStorage). There isn't a regression test asserting that behavior (e.g., snapshot + one SetState + revert should leave dirtyStorage without the slot). Please add a unit test to lock in this behavior and prevent witness/proof regressions.

Copilot uses AI. Check for mistakes.
…ereum#29641

Currently our state journal tracks each storage update to a contract, having the ability to revert those changes to the previously set value.

For the very first modification however, it behaves a bit wonky. Reverting the update doesn't actually remove the dirty-ness of the slot, rather leaves it as "change this slot to it's original value". This can cause issues down the line with for example write witnesses needing to gather an unneeded proof.

This PR modifies the storageChange journal entry to not only track the previous value of a slot, but also whether there was any previous value at all set in the current execution context. In essence, the PR changes the semantic of storageChange so it does not simply track storage changes, rather it tracks dirty storage changes, an important distinction for being able to cleanly revert the journal item.
@gzliudan gzliudan force-pushed the state-journal-storage-revert branch from 2c40c1a to 1199d66 Compare March 3, 2026 09:54
@AnilChinchawale AnilChinchawale merged commit 3eb198b into XinFinOrg:dev-upgrade Mar 6, 2026
13 checks passed
@gzliudan gzliudan deleted the state-journal-storage-revert branch March 6, 2026 05:52
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.

7 participants