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

Conversation

BeniaminDrasovean
Copy link
Contributor

@BeniaminDrasovean BeniaminDrasovean commented Sep 29, 2023

Reasoning behind the pull request

  • There is an edgecase relating to trie pruning + migrate data trie + revert. If a transaction that triggers the migration of a certain data trie value is reverted, the old version of the trie leaf that was migrated is added back to the trie, but the new migrated leaf is not removed. This means that the root hash of the data trie after the revert will not be the same as before.
  • This bug can be noticed only if pruning is enabled because even though the data trie will reload the old rootHash correctly, it will also mark it for eviction.
  • Another edgecase which is fixed in this PR: If a trie branch node migrates only one of it's children and then that child is removed/the migration is reverted, the branch node will have an initialized ChildrenVersion slice instead of a nil byte slice. This will result in a different root hash.

Proposed changes

  • To prevent the eviction of the needed root hash, the data trie needs to have the same root hash after the revert as before. This will mean that the root hash will be present in both oldHashes and newHashes, thus the removal will be canceled.

Testing procedure

  • Start the chain with snapshots disabled and pruning enabled, and after the autoBalanceDataTriesFlag is enabled, send some txs (which will change the existing data trie leaves) that will fail.
  • Normal testing procedure

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?

Copy link
Contributor

@iulianpascalau iulianpascalau left a comment

Choose a reason for hiding this comment

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

👍

state/accountsDB_test.go Outdated Show resolved Hide resolved
state/trackableDataTrie/trackableDataTrie.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 29, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (ac5f985) 80.16% compared to head (6addb23) 80.12%.
Report is 1 commits behind head on rc/v1.6.0.

❗ Current head 6addb23 differs from pull request most recent head 89e77e4. Consider uploading reports for the commit 89e77e4 to get more accurate results

Additional details and impacted files
@@              Coverage Diff              @@
##           rc/v1.6.0    #5611      +/-   ##
=============================================
- Coverage      80.16%   80.12%   -0.04%     
=============================================
  Files            708      708              
  Lines          93860    93875      +15     
=============================================
- Hits           75241    75221      -20     
- Misses         13282    13316      +34     
- Partials        5337     5338       +1     
Files Coverage Δ
trie/branchNode.go 77.94% <100.00%> (+0.29%) ⬆️
state/trackableDataTrie/trackableDataTrie.go 83.85% <91.66%> (+0.61%) ⬆️

... and 5 files with indirect coverage changes

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

@AdoAdoAdo AdoAdoAdo self-requested a review October 2, 2023 08:23

return nil
}

func (bn *branchNode) revertChildrenVersionSlice() {
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.

iulianpascalau
iulianpascalau previously approved these changes Oct 2, 2023

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.

if err != nil {
return nil, err
}

index++

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.

iulianpascalau
iulianpascalau previously approved these changes Oct 2, 2023
AdoAdoAdo
AdoAdoAdo previously approved these changes Oct 3, 2023
iulianpascalau
iulianpascalau previously approved these changes Oct 3, 2023
AdoAdoAdo
AdoAdoAdo previously approved these changes Oct 3, 2023
@@ -1436,7 +1436,7 @@ func TestBranchNode_VerifyChildrenVersionIsSetCorrectlyAfterInsertAndDelete(t *t
}
newBn, _, err := bn.insert(data, &testscommon.MemDbMock{})
assert.Nil(t, err)
assert.Equal(t, 0, len(newBn.(*branchNode).ChildrenVersion))
assert.Equal(t, []byte(nil), newBn.(*branchNode).ChildrenVersion)
Copy link
Contributor

Choose a reason for hiding this comment

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

assert.Nil here and on L1452 & L1492

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.

Copy link
Collaborator

@gabi-vuls gabi-vuls left a comment

Choose a reason for hiding this comment

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

Normal allin test: v1.5.13-dev-config-8c685c8e00 -> reverted-migration-tx-fix-a3cfd08194

--- Specific errors ---

block hash does not match 7771
wrong nonce in block 2861
miniblocks does not match 0
num miniblocks does not match 0
miniblock hash does not match 0
block bodies does not match 0
receipts hash missmatch 0

/------/

--- Statistics ---

Nr. of all ERRORS: 1
Nr. of all WARNS: 216
Nr. of new ERRORS: 1
Nr. of new WARNS: 3
Nr. of PANICS: 0

/------/

@BeniaminDrasovean BeniaminDrasovean merged commit b4df8fd into rc/v1.6.0 Oct 3, 2023
6 checks passed
@BeniaminDrasovean BeniaminDrasovean deleted the reverted-migration-tx-fix branch October 3, 2023 11:24
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