Skip to content

Conversation

@gzliudan
Copy link
Collaborator

Proposed changes

Ref: ethereum#27428

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

@gzliudan gzliudan changed the title [WIP] cmd, core/state, eth, tests, trie: improve state reader #27428 cmd, core/state, eth, tests, trie: improve state reader #27428 Jan 30, 2026
@gzliudan gzliudan force-pushed the improve-state-reader branch from f527469 to 6c62710 Compare January 30, 2026 08:02
Copilot AI review requested due to automatic review settings January 30, 2026 08:02
@coderabbitai
Copy link

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

  • 🔍 Trigger a full 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 enhances the state reader functionality by improving error handling and state management. The changes make the Database.Reader() and Trie.NodeIterator() methods return errors when state is unavailable, and introduce a committed flag to prevent usage of tries after they have been committed.

Changes:

  • Added error returns to Database.Reader() and NodeIterator() methods to handle unavailable state
  • Introduced a committed flag in the Trie struct to prevent operations on committed tries
  • Updated all callers throughout the codebase to handle the new error signatures
  • Added MustNodeIterator() helper methods for backward compatibility where errors can be logged

Reviewed changes

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

Show a summary per file
File Description
trie/triedb/hashdb/database.go Modified Reader() to return error when state root is not available
trie/database_wrap.go Updated Reader() signature to return error
trie/trie_reader.go Removed NodeReader interface; updated newTrieReader to handle errors
trie/trie.go Added committed flag and error checks in mutation methods; added MustNodeIterator() helper
trie/secure_trie.go Updated NodeIterator() signature and added MustNodeIterator() wrapper
trie/errors.go Added ErrCommitted error type
trie/proof.go Added committed flag check to Prove() method
trie/*_test.go Updated tests to use MustNodeIterator() or handle errors from NodeIterator()
core/state/statedb.go Added documentation about post-commit state handling
core/state/statedb_test.go Added TestCommitCopy and updated TestCopyCommitCopy to verify committed state behavior
core/state/*.go Updated to handle errors from NodeIterator()
eth/api_debug.go Added error handling for NodeIterator() calls
eth/api_debug_test.go Updated test to reinitialize state after commit
cmd/XDC/dbcmd.go Added error handling for NodeIterator()
tests/state_test_util.go Reinitialize state after commit for further operations
XDCxlending/lendingstate/XDCx_trie.go Added error handling to NodeIterator() wrapper (returns nil on error)
XDCx/tradingstate/XDCx_trie.go Added error handling to NodeIterator() wrapper (returns nil on error)

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

The state availability is checked during the creation of a state reader.

-    In hash-based database, if the specified root node does not exist on disk disk, then
    the state reader won't be created and an error will be returned.

-    In path-based database, if the specified state layer is not available, then the
    state reader won't be created and an error will be returned.

This change also contains a stricter semantics regarding the `Commit` operation: once it has been performed, the trie is no longer usable, and certain operations will return an error.
@gzliudan gzliudan force-pushed the improve-state-reader branch from 6c62710 to dad2802 Compare January 30, 2026 09:41
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