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

Revert tx that migrates data bugfix #5611

Merged
merged 11 commits into from
Oct 3, 2023
4 changes: 3 additions & 1 deletion state/accountsDB_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3096,7 +3096,9 @@
// save account with data trie that is not migrated
userAcc := acc.(state.UserAccountHandler)
key := []byte("key")
err = userAcc.SaveKeyValue(key, []byte("value"))

Check failure on line 3099 in state/accountsDB_test.go

View workflow job for this annotation

GitHub Actions / golangci linter

ineffectual assignment to err (ineffassign)
err = userAcc.SaveKeyValue([]byte("key1"), []byte("value"))

require.Nil(t, err)
err = adb.SaveAccount(userAcc)
userAccRootHash := userAcc.GetRootHash()
Expand Down Expand Up @@ -3137,7 +3139,7 @@

return nil
}
_, err = adb.Commit()
_, _ = adb.Commit()
require.True(t, markForEvictionCalled)
}

Expand Down
4 changes: 2 additions & 2 deletions state/trackableDataTrie/trackableDataTrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ func (tdt *trackableDataTrie) updateTrie(dtr state.DataTrie) ([]core.TrieData, e

index++

isMigration := oldVal.Version == core.NotSpecified && dataEntry.newVersion == core.AutoBalanceEnabled
if isMigration && len(newKey) != 0 {
isFirstMigration := oldVal.Version == core.NotSpecified && dataEntry.newVersion == core.AutoBalanceEnabled
if isFirstMigration && len(newKey) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

we only have len(newKey) == 0 here in case of deletes right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

oldValues = append(oldValues, core.TrieData{
Key: newKey,
Value: nil,
Expand Down
15 changes: 15 additions & 0 deletions trie/branchNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,8 @@ func (bn *branchNode) setNewChild(childPos byte, newNode node) error {
bn.setVersionForChild(0, childPos)
bn.EncodedChildren[childPos] = nil

bn.revertChildrenVersionSlice()

return nil
}

Expand All @@ -647,10 +649,23 @@ func (bn *branchNode) setNewChild(childPos byte, newNode node) error {
return err
}
bn.setVersionForChild(childVersion, childPos)
if childVersion == core.NotSpecified {
bn.revertChildrenVersionSlice()
}

return nil
}

func (bn *branchNode) revertChildrenVersionSlice() {
Copy link
Contributor

Choose a reason for hiding this comment

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

ca you add unit tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

for i := range bn.ChildrenVersion {
if bn.ChildrenVersion[i] == 1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

hardcoded version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

return
}
}

bn.ChildrenVersion = []byte(nil)
}

func (bn *branchNode) reduceNode(pos int) (node, bool, error) {
newEn, err := newExtensionNode([]byte{byte(pos)}, bn, bn.marsh, bn.hasher)
if err != nil {
Expand Down