Skip to content

Conversation

@gzliudan
Copy link
Collaborator

Proposed changes

Ref: ethereum#26995

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] core, trie: refactor trie API #26995 core, trie: refactor trie API #26995 Jan 5, 2026
Copilot AI review requested due to automatic review settings January 5, 2026 10:53
@coderabbitai
Copy link

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

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.


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 refactors the trie API to improve clarity and consistency by restructuring method naming conventions. The main changes rename the Try* methods (TryGet, TryUpdate, TryDelete, TryGetNode) to be the primary error-returning methods (Get, Update, Delete, GetNode), while the previous non-error-handling methods are renamed to Must* variants (MustGet, MustUpdate, MustDelete, MustGetNode) that log errors but don't return them.

Key changes:

  • Renamed Try* methods to regular methods (e.g., TryGetGet, TryUpdateUpdate) as the primary error-returning API
  • Renamed previous error-suppressing methods to Must* variants (e.g., GetMustGet, UpdateMustUpdate)
  • Updated the TrieHasher interface's Update method to return an error
  • Updated all test files and internal usages to use the new API

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
trie/trie.go Core trie API refactoring: renamed methods and updated internal method calls
trie/secure_trie.go Updated StateTrie wrapper methods to use new API, removed unused log import
trie/stacktrie.go Swapped Update and MustUpdate implementations to match new convention
trie/errors.go Updated comment to reference new method names (Get, Update, Delete)
trie/trie_test.go Updated all test calls to use MustUpdate/MustGet/MustDelete or error-checking variants
trie/tracer_test.go Updated test calls to use MustUpdate/MustDelete
trie/sync_test.go Updated test calls to use MustUpdate/MustGet
trie/stacktrie_test.go Updated test calls to use new Update method signature
trie/secure_trie_test.go Updated test calls to use MustUpdate/MustGet/MustDelete
trie/proof_test.go Updated test calls to use MustUpdate
trie/proof.go Updated StackTrie.Update calls in proof verification
trie/iterator_test.go Updated test calls to use MustUpdate/MustGet
core/types/hashing.go Updated TrieHasher interface to return error from Update method, added explanatory comment
core/types/hashing_test.go Updated testHasher.Update to return error
core/types/block_test.go Updated testHasher.Update to return error
core/state/sync_test.go Updated trie method calls to use GetNode and MustGet
core/rawdb/accessors_indexes_test.go Updated testHasher.Update to return error
XDCxlending/lendingstate/XDCx_trie.go Updated internal trie method calls to use new API (wrapper maintains TryUpdate/TryGet interface)
XDCx/tradingstate/XDCx_trie.go Updated internal trie method calls to use new API (wrapper maintains TryUpdate/TryGet interface)

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

func (t *Trie) MustGet(key []byte) []byte {
res, err := t.Get(key)
if err != nil {
log.Error("Unhandled trie error in Trie.Get", "err", err)
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

The error message references "Trie.Get" but this is in the MustGet function. The error message should reference "Trie.MustGet" for clarity and consistency with the actual function being called.

Suggested change
log.Error("Unhandled trie error in Trie.Get", "err", err)
log.Error("Unhandled trie error in Trie.MustGet", "err", err)

Copilot uses AI. Check for mistakes.
In this PR, all TryXXX(e.g. TryGet) APIs of trie are renamed to XXX(e.g. Get) with an error returned.

The original XXX(e.g. Get) APIs are renamed to MustXXX(e.g. MustGet) and does not return any error -- they print a log output. A future PR will change the behaviour to panic on errorrs.
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.

2 participants