Skip to content

fix(core): remove slot dirtyness if it's set back to origin value #29731 #31874#2080

Merged
AnilChinchawale merged 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:filter-noop-storage-update
Mar 6, 2026
Merged

fix(core): remove slot dirtyness if it's set back to origin value #29731 #31874#2080
AnilChinchawale merged 1 commit into
XinFinOrg:dev-upgradefrom
gzliudan:filter-noop-storage-update

Conversation

@gzliudan
Copy link
Copy Markdown
Collaborator

Proposed changes

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 25, 2026 01:45
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 25, 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: 5bef07a4-dc6e-4457-9f75-1c01c7c6617a

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
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 adjusts the state storage “dirty” tracking so that a storage slot no longer remains marked dirty (and unnecessarily propagated through pending commit paths) when it is set back to its original value, improving correctness of change tracking and reducing internal churn in StateDB.

Changes:

  • Introduces an internal getState helper to return both current (dirty/committed) and original (committed) storage slot values.
  • Extends storage journaling to track both the previous value and the original value, enabling correct dirty-marker removal on revert paths.
  • Updates storage finalization logic to avoid keeping pending entries when a slot is reverted to its original value.

Reviewed changes

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

File Description
core/state/state_object.go Adds origin-aware storage reads/writes and removes dirty markers when a slot is set back to its original value; adjusts finalization behavior.
core/state/journal.go Updates storageChange journal entries to carry both previous and original values and uses them during revert.

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

Comment on lines +136 to +137
value, _ := s.getState(key)
return value
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

GetState now always calls GetCommittedState (via getState) even when a dirty value exists. This adds avoidable overhead in a very hot path (SLOAD/gas accounting), and can also force extra cache lookups compared to the previous early-return behavior. Consider restoring the fast-path: check dirtyStorage first and return it directly, only calling GetCommittedState when the slot isn't dirty (while keeping getState for callers that also need the origin).

Suggested change
value, _ := s.getState(key)
return value
// Fast-path: if there is a dirty value, return it directly without
// consulting the committed state or storage trie.
if value, dirty := s.dirtyStorage[key]; dirty {
return value
}
// Fallback to the committed state if the slot is not dirty.
return s.GetCommittedState(key)

Copilot uses AI. Check for mistakes.
Comment thread core/state/state_object.go Outdated
Comment on lines +207 to +214
// setState updates a value in account dirty storage. The dirtiness will be
// removed if the value being set equals to the original value.
func (s *stateObject) setState(key common.Hash, value common.Hash, origin common.Hash) {
// Storage slot is set back to its original value, undo the dirty marker
if value == origin {
delete(s.dirtyStorage, key)
return
}
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

The new behavior of clearing a storage slot’s dirty marker when it’s set back to the original value is subtle and easy to regress (especially across multiple SetState calls and snapshot reverts). There doesn’t appear to be a targeted unit test covering the “set -> set back to origin -> no net dirty/pending change” case; please add one to lock in the intended semantics.

Copilot uses AI. Check for mistakes.
@gzliudan gzliudan force-pushed the filter-noop-storage-update branch from 5ff36ef to 7142dca Compare March 6, 2026 07:44
@gzliudan gzliudan force-pushed the filter-noop-storage-update branch from 7142dca to 82ec111 Compare March 6, 2026 07:54
@AnilChinchawale AnilChinchawale merged commit 4f59928 into XinFinOrg:dev-upgrade Mar 6, 2026
9 checks passed
@gzliudan gzliudan deleted the filter-noop-storage-update branch March 6, 2026 07:58
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.

6 participants