Skip to content

refactor(state): common interface and adapters for trie and state#3017

Merged
rodrodros merged 86 commits intomainfrom
maksym/trie-interface
Nov 19, 2025
Merged

refactor(state): common interface and adapters for trie and state#3017
rodrodros merged 86 commits intomainfrom
maksym/trie-interface

Conversation

@MaksymMalicki
Copy link
Copy Markdown
Contributor

@MaksymMalicki MaksymMalicki commented Jul 31, 2025

  1. This PR introduces common state and trie interfaces. Shared methods previously used outside the trie/trie2 packages, the new state package and the old state related .go files have been abstracted into the commontrie and commonstate packages. Adapters have been implemented for the respective structs. The commonstate package includes a StateFactory struct, which is responsible for generating the appropriate version of the state. The new interfaces are called commonstate.State, commonstate.StateReader (used only for read purposes) and commontrie.Trie.

  2. This PR also adds a new testing utility that reads an USE_NEW_STATE environment variable (set from the Makefile) to determine whether unit tests should run with the old or new state. The utility is located in the state_test_utils package. It will be used in the following PR, where the commonstate and commontrie packages are integrated into the project.

  3. Lastly, this PR introduces an experimental boolean CLI flag --new-state, which specifies whether the node should run using the old or new state/trie packages.

All the new packages have been put in the state package, so that they are easy to spot and remove in the future, once the integration is finished.

Breaking changes:

  1. The new common interfaces for the trie and state force the public methods to return by values instead of the references. When integrated, this requires modification throughout Juno, both in utilities and tests. This breaking change has to be thoroughly tested, as it modifies the node behaviour.

Next PR to review: #3277

@MaksymMalicki MaksymMalicki marked this pull request as draft July 31, 2025 09:33
@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 31, 2025

Codecov Report

❌ Patch coverage is 19.38776% with 158 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.17%. Comparing base (18dbb4e) to head (a95a273).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
core/mocks/mock_commonstate_reader.go 0.00% 69 Missing ⚠️
core/state/commonstate/state.go 0.00% 35 Missing ⚠️
core/trie2/triedb/database.go 0.00% 11 Missing ⚠️
rpc/v8/storage.go 43.75% 3 Missing and 6 partials ⚠️
rpc/v9/storage.go 40.00% 3 Missing and 6 partials ⚠️
core/trie/trie.go 0.00% 5 Missing ⚠️
core/state/statetestutils/new_state_flag.go 0.00% 4 Missing ⚠️
core/pending_state.go 0.00% 3 Missing ⚠️
core/state/state.go 72.72% 3 Missing ⚠️
core/state_snapshot.go 0.00% 3 Missing ⚠️
... and 4 more

❌ Your patch status has failed because the patch coverage (19.38%) is below the target coverage (60.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3017      +/-   ##
==========================================
- Coverage   76.47%   76.17%   -0.31%     
==========================================
  Files         323      326       +3     
  Lines       32169    32326     +157     
==========================================
+ Hits        24602    24623      +21     
- Misses       5803     5929     +126     
- Partials     1764     1774      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MaksymMalicki MaksymMalicki marked this pull request as ready for review August 5, 2025 08:53
Copy link
Copy Markdown
Contributor

@rodrodros rodrodros left a comment

Choose a reason for hiding this comment

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

It looks good overall!

I think some other changes might be required, perhaps in a different PR, but I think all the current code should be prefixed with Deprecated. For example, Trie should be now DeprecatedTrie and State should be DeprecatedState.

Their package names should be updated as well. It will be clear for all of us programming in the node that we are using deprecated structures

Comment thread cmd/juno/juno.go Outdated
Comment thread core/state/commontrie/trie.go
Comment thread core/state/commontrie/trie.go Outdated
Comment thread core/state/commontrie/trie.go Outdated
Comment thread core/state/state.go
Comment thread core/state/commonstate/state.go Fixed
Comment thread core/state/commontrie/trie.go Fixed
MaksymMalicki and others added 4 commits August 5, 2025 14:53
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: MaksymMalicki <81577596+MaksymMalicki@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: MaksymMalicki <81577596+MaksymMalicki@users.noreply.github.com>
Base automatically changed from maksym/state-renames to main November 3, 2025 15:16
Signed-off-by: MaksymMalicki <81577596+MaksymMalicki@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@EgeCaner EgeCaner left a comment

Choose a reason for hiding this comment

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

Looks good!

Comment thread core/state/state.go Outdated
@rodrodros rodrodros merged commit ab5542a into main Nov 19, 2025
22 of 29 checks passed
@rodrodros rodrodros deleted the maksym/trie-interface branch November 19, 2025 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants