Skip to content

Conversation

@gzliudan
Copy link
Collaborator

@gzliudan gzliudan commented Jan 8, 2026

Proposed changes

Ref: ethereum#29520

Types of changes

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

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)
  • Regular KTLO or any of the maintaince work. e.g code style
  • CICD Improvement

Impacted Components

Which part of the codebase this PR will touch base on,

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
  • 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

coderabbitai bot commented Jan 8, 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.


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 pull request refactors the core state management system by removing the account reset operation and introducing a new mutation tracking system. The changes aim to simplify account lifecycle management and improve state handling during contract creation.

Key changes:

  • Introduces a mutation tracking system to replace the previous approach of tracking dirty/pending/destruct states separately
  • Refactors contract creation logic to conditionally create accounts only when they don't exist
  • Adds a CreateContract method to mark accounts as new contracts for EIP-6780 compliance
  • Replaces the created/deleted flags with a newContract flag and removes the resetObjectChange journal entry

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
core/vm/interface.go Adds CreateContract method to StateDB interface for marking contract accounts
core/vm/evm.go Updates contract creation to check for existing accounts before calling CreateAccount and adds CreateContract call
core/state/statedb.go Major refactoring introducing mutation tracking system, replacing dirty/pending maps with mutations map, changing stateObjectsDestruct to store original account data
core/state/statedb_test.go Adds new tests for copy functionality with dirty journal and object state, updates existing tests to check account existence before creation
core/state/state_test.go Simplifies TestSnapshot2 to TestCreateObjectRevert focusing on account creation/revert behavior
core/state/state_object.go Renames created flag to newContract, removes deleted flag, adds origin field for tracking original state, changes code from Code type to []byte
core/state/journal.go Removes resetObjectChange, adds copy methods to all journal entry types for proper deep copying
Comments suppressed due to low confidence (1)

core/state/statedb.go:199

  • The Reset function clears out ephemeral state but doesn't reset the 'mutations' and 'stateObjectsDestruct' maps that were introduced in this PR. These maps track transaction-level changes and should be reset when the state is reset to maintain consistency with the rest of the state clearing logic.
func (s *StateDB) Reset(root common.Hash) error {
	tr, err := s.db.OpenTrie(root)
	if err != nil {
		return err
	}
	s.trie = tr
	s.stateObjects = make(map[common.Address]*stateObject)
	s.thash = common.Hash{}
	s.txIndex = 0
	s.logs = make(map[common.Hash][]*types.Log)
	s.logSize = 0
	s.preimages = make(map[common.Hash][]byte)
	s.clearJournalAndRefund()
	s.accessList = newAccessList()
	return nil

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

Comment on lines 596 to 607
func (s *StateDB) getStateObject(addr common.Address) *stateObject {
if obj := s.getDeletedStateObject(addr); obj != nil && !obj.deleted {
return obj
}
return nil
}

// getDeletedStateObject is similar to getStateObject, but instead of returning
// nil for a deleted state object, it returns the actual object with the deleted
// flag set. This is needed by the state journal to revert to the correct s-
// destructed object instead of wiping all knowledge about the state object.
func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject {
// Prefer live objects if any is available
if obj := s.stateObjects[addr]; obj != nil {
return obj
}
// Short circuit if the account is already destructed in this block.
if _, ok := s.stateObjectsDestruct[addr]; ok {
return nil
}
// Load the object from the database
start := time.Now()
data, err := s.trie.GetAccount(addr)
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

The getStateObject method now returns nil for already destructed accounts (lines 602-604), but it doesn't initialize the 'origin' field for accounts loaded from the database. The origin field is used at line 796 to track original account data for destructed accounts. When an account is loaded from the database, the origin field should be initialized with the original account data to ensure proper tracking of the account's original state before modifications.

Copilot uses AI. Check for mistakes.
Comment on lines 842 to 852
for addr, op := range s.mutations {
if op.applied {
continue
}
op.applied = true

if op.isDelete() {
deletedAddrs = append(deletedAddrs, addr)
} else {
obj.updateRoot(s.db)
s.updateStateObject(obj)
s.updateStateObject(s.stateObjects[addr])
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

Potential nil pointer dereference at line 851. Similar to line 826, this code accesses s.stateObjects[addr] without verifying the object exists. If a mutation is tracked for an address but the object has been removed from s.stateObjects, this would cause a panic. A nil check should be added before calling updateStateObject.

Copilot uses AI. Check for mistakes.
@gzliudan gzliudan force-pushed the no-reset-object-alt branch from b5a08b2 to 54a51d2 Compare January 9, 2026 01:53
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.

1 participant