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

Migrate data trie #4962

Merged
merged 7 commits into from Mar 8, 2023
Merged

Conversation

BeniaminDrasovean
Copy link
Contributor

Reasoning behind the pull request

  • Trie nodes can have different versions. We need an endpoint for migrating trie nodes from a version to another.

Proposed changes

  • Refactor trackableDataTrie so that it can handle the trie nodes migration process in a generalized manner
  • Add a new trie functionality that will collect nodes that need to be migrated
  • Implement a new built-in function that will trigger the migration (this is done in mx-chain-vm-common-go)

Testing procedure

  • Check that the new built-in function works as expected

Pre-requisites

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?

@codecov-commenter
Copy link

Codecov Report

Base: 70.86% // Head: 70.86% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (44e3633) compared to base (8e75abb).
Patch coverage: 81.09% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@                    Coverage Diff                    @@
##           feat/balance-data-tries    #4962    +/-   ##
=========================================================
  Coverage                    70.86%   70.86%            
=========================================================
  Files                          666      666            
  Lines                        86513    86642   +129     
=========================================================
+ Hits                         61309    61402    +93     
- Misses                       20595    20615    +20     
- Partials                      4609     4625    +16     
Impacted Files Coverage Δ
common/trie.go 38.46% <ø> (ø)
state/baseAccount.go 62.96% <0.00%> (ø)
trie/node.go 84.05% <55.55%> (-1.99%) ⬇️
trie/leafNode.go 76.96% <65.51%> (-1.68%) ⬇️
trie/extensionNode.go 70.76% <73.91%> (-0.40%) ⬇️
trie/branchNode.go 78.22% <78.94%> (-0.29%) ⬇️
trie/patriciaMerkleTrie.go 76.22% <78.94%> (-0.12%) ⬇️
state/trackableDataTrie.go 85.79% <89.56%> (+1.28%) ⬆️
state/journalEntries.go 81.41% <100.00%> (ø)
state/parsers/dataTrieLeafParser.go 83.33% <100.00%> (ø)
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

state/export_test.go Show resolved Hide resolved
state/export_test.go Show resolved Hide resolved
state/trackableDataTrie.go Show resolved Hide resolved
state/trackableDataTrie.go Show resolved Hide resolved
return errors.ErrNilTrieMigrator
}

if newVersion > core.MaxValidTrieNodeVersion || oldVersion > core.MaxValidTrieNodeVersion {
Copy link
Contributor

Choose a reason for hiding this comment

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

this will raise backward-compatible issues when we will have another implementation. Suggestion to completely replace the core.MaxValidTrieNodeVersion with a specialized component that is epoch-aware.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

return fmt.Errorf("%w: newVersion %v, oldVersion %v", errors.ErrInvalidTrieNodeVersion, newVersion, oldVersion)
}

if newVersion == core.NotSpecified && oldVersion == core.AutoBalanceEnabled {
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be a function that will handle all the incompatible values that we might have.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracted all the version checks in a new func.

@@ -28,6 +28,8 @@ type BuiltInCost struct {
ESDTNFTAddUri uint64
ESDTNFTUpdateAttributes uint64
ESDTNFTMultiTransfer uint64
TrieLoad uint64
Copy link
Contributor

Choose a reason for hiding this comment

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

a little bit misleading name. This is actually TrieLoadPerLeaf cost. Also the next Store cost.

Copy link
Contributor

Choose a reason for hiding this comment

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

same for TrieStorePerLeaf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to TrieLoadPerNode and TrieStorePerLoad

@@ -28,6 +28,8 @@ type BuiltInCost struct {
ESDTNFTAddUri uint64
ESDTNFTUpdateAttributes uint64
ESDTNFTMultiTransfer uint64
TrieLoad uint64
Copy link
Contributor

Choose a reason for hiding this comment

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

same for TrieStorePerLeaf

vm/systemSmartContracts/defaults/gasMap.go Outdated Show resolved Hide resolved
vm/gasCost.go Outdated Show resolved Hide resolved
state/trackableDataTrie.go Show resolved Hide resolved
state/trackableDataTrie.go Outdated Show resolved Hide resolved
state/trackableDataTrie.go Outdated Show resolved Hide resolved
# Conflicts:
#	go.mod
#	go.sum
#	testscommon/trie/trieStub.go
#	trie/patriciaMerkleTrie_test.go
@BeniaminDrasovean BeniaminDrasovean merged commit 0bed4d9 into feat/balance-data-tries Mar 8, 2023
@BeniaminDrasovean BeniaminDrasovean deleted the migrate-data-trie branch March 8, 2023 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants