-
Notifications
You must be signed in to change notification settings - Fork 69
cmd, core/state, eth, tests, trie: improve state reader #27428 #1166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev-upgrade
Are you sure you want to change the base?
Conversation
f527469 to
6c62710
Compare
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this 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()andNodeIterator()methods to handle unavailable state - Introduced a
committedflag in theTriestruct 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.
6c62710 to
dad2802
Compare
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 applyImpacted Components
Which part of the codebase this PR will touch base on,
Put an
✅in the boxes that applyChecklist
Put an
✅in the boxes once you have confirmed below actions (or provide reasons on not doing so) that