Skip to content
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

chore(trie): Add support for trie V1 #3433

Merged
merged 164 commits into from
Nov 21, 2023
Merged

Conversation

dimartiro
Copy link
Contributor

@dimartiro dimartiro commented Aug 10, 2023

Changes

Basically the thing that I changed is the way we encode the trie, when we are using v1 we can have hashed values for both branches and leaves.

What I did is to keep our trie as it is storing the value in the way we were doing it but I only change the encode / decode method to, for example, hash the values (greater than 32bytes) to be hashed in the encoded representation.
Since we are using the encoded node to calculate the hash I had to modify those methods too.

I also I added the IsHashedValue flag in Node structure for those cases where we are decoding nodes and they are encoded with the v1 format (usually used when verifying merkle proofs)

Summary of changes

  • Trie versions
    • Calculate root hash based on state trie version
    • Add default version
  • Update runtime functions to use new trie versions when calculating hashes
  • Get trie version from runtime when needed
  • Added state-version arg in import state command
  • Update tests
    • Set V0 or DefaultVersion (V1) when needed
    • Add test cases for both versions
  • Add new test cases

Tests

make test

Issues

close #2418

Primary Reviewer

@timwu20

@codecov
Copy link

codecov bot commented Aug 10, 2023

Codecov Report

Merging #3433 (2ce26f7) into development (41e9c1d) will decrease coverage by 0.11%.
The diff coverage is 68.05%.

Additional details and impacted files
@@               Coverage Diff               @@
##           development    #3433      +/-   ##
===============================================
- Coverage        50.17%   50.07%   -0.11%     
===============================================
  Files              229      229              
  Lines            28518    28604      +86     
===============================================
+ Hits             14310    14323      +13     
- Misses           12703    12753      +50     
- Partials          1505     1528      +23     

Copy link
Member

@EclesioMeloJunior EclesioMeloJunior left a comment

Choose a reason for hiding this comment

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

LGTM, just small observations

lib/trie/proof/generate.go Outdated Show resolved Hide resolved
@dimartiro dimartiro added the trie label Nov 15, 2023
@dimartiro dimartiro self-assigned this Nov 15, 2023
lib/runtime/wazero/imports.go Outdated Show resolved Hide resolved
lib/runtime/wazero/imports.go Outdated Show resolved Hide resolved
lib/runtime/wazero/imports.go Outdated Show resolved Hide resolved
lib/runtime/wazero/imports.go Outdated Show resolved Hide resolved
lib/runtime/wazero/imports.go Outdated Show resolved Hide resolved
dot/core/service.go Outdated Show resolved Hide resolved
lib/trie/version.go Outdated Show resolved Hide resolved
lib/trie/trie.go Show resolved Hide resolved
internal/trie/node/header.go Show resolved Hide resolved
internal/trie/node/header_test.go Outdated Show resolved Hide resolved
lib/trie/version.go Outdated Show resolved Hide resolved
Copy link
Contributor

@kanishkatn kanishkatn left a comment

Choose a reason for hiding this comment

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

Great job!

cmd/gossamer/commands/import_state.go Outdated Show resolved Hide resolved
cmd/gossamer/commands/import_state.go Outdated Show resolved Hide resolved
cmd/gossamer/commands/import_state.go Outdated Show resolved Hide resolved
@dimartiro dimartiro merged commit 26f1611 into development Nov 21, 2023
24 checks passed
@dimartiro dimartiro deleted the diego/trieV1/versioning branch November 21, 2023 19:26
Copy link

🎉 This PR is included in version 0.8.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@dimartiro dimartiro removed their assignment Jan 18, 2024
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.

Implement storage trie version 1
7 participants