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

refactor dataTrieTracker #4491

Merged
merged 8 commits into from
Sep 26, 2022
Merged

Conversation

BeniaminDrasovean
Copy link
Contributor

@BeniaminDrasovean BeniaminDrasovean commented Sep 21, 2022

Description of the reasoning behind the pull request (what feature was missing / how the problem was manifesting itself / what was the motive behind the refactoring)

  • There were some duplicated mocks
  • TrackableDataTrie was exported

Proposed Changes

  • Remove duplicated mocks
  • Unexport trackableDataTrie and make in inaccessible form outside the account

Testing procedure

  • Normal test

@@ -50,6 +50,13 @@ type KeyBuilder interface {
Clone() KeyBuilder
}

// DataTrie is an interface that declares the methods used for dataTries
type DataTrie interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

DataTrieHandler ?

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.

@@ -187,16 +188,21 @@ func NewJournalEntryDataTrieUpdates(trieUpdates map[string][]byte, account baseA

// Revert applies undo operation
func (jedtu *journalEntryDataTrieUpdates) Revert() (vmcommon.AccountHandler, error) {
trie, ok := jedtu.account.DataTrie().(common.Trie)
Copy link
Contributor

Choose a reason for hiding this comment

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

why does the account.DataTrie() method returns a subset of the Trie interface but we have the code swarming with casts like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are only 2 casts in productive code (the rest are in tests). The idea behind this was to not give access directly to the trie (although this is possible through casting).

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, as agreed, we will keep this as it is

if check.IfNil(tdaw.tr) {
newDataTrie, err := mainTrie.Recreate(make([]byte, 0))
if err != nil {
return map[string][]byte{}, err
Copy link
Contributor

Choose a reason for hiding this comment

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

please return nil, err here to keep the consistency across the project

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.

}

tdaw.dirtyData = make(map[string][]byte)
return oldValues, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

we return the old data for jurnalizing purposes, I guess. Can you please check where do we use this?

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, this is used only for journalizing. (accountsDB -> saveDataTrie())

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, will remain as it is

tr: tr,
dirtyData: make(map[string][]byte),
identifier: identifier,
}
}

// ClearDataCaches empties the dirtyData map and original map
func (tdaw *TrackableDataTrie) ClearDataCaches() {
Copy link
Contributor

Choose a reason for hiding this comment

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

this doesn't need to be called anymore due to this refactoring

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. It is called inside SaveDirtyData(), but we don't need a method for this.

go.mod Outdated
@@ -7,8 +7,8 @@ require (
github.com/ElrondNetwork/arwen-wasm-vm/v1_3 v1.3.42-0.20220729115131-85ecca868e90
github.com/ElrondNetwork/arwen-wasm-vm/v1_4 v1.4.59-0.20220729115431-a6c93119bdda
github.com/ElrondNetwork/covalent-indexer-go v1.0.6
github.com/ElrondNetwork/elastic-indexer-go v1.2.41
github.com/ElrondNetwork/elrond-go-core v1.1.19
github.com/ElrondNetwork/elastic-indexer-go v1.2.42-0.20220921110140-860b4b8c7fc3
Copy link
Contributor

Choose a reason for hiding this comment

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

do not forget about proper releases

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do.


if check.IfNil(adb.dataTries.Get(accountHandler.AddressBytes())) {
adb.dataTries.Put(accountHandler.AddressBytes(), accountHandler.DataTrie())
trie, ok := accountHandler.DataTrie().(common.Trie)
Copy link
Contributor

Choose a reason for hiding this comment

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

another cast

Copy link
Contributor

Choose a reason for hiding this comment

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

will remain as it is

…refactor

# Conflicts:
#	factory/consensus/consensusComponents_test.go
#	factory/state/stateComponentsHandler_test.go
#	go.mod
@bogdan-rosianu bogdan-rosianu self-requested a review September 22, 2022 09:04
@@ -1172,7 +1172,7 @@ func (n *Node) getAccountRootHashAndVal(address []byte, accBytes []byte, key []b
return nil, nil, fmt.Errorf("empty dataTrie rootHash")
}

retrievedVal, err := userAccount.RetrieveValueFromDataTrieTracker(key)
retrievedVal, err := userAccount.RetrieveValue(key)
Copy link
Contributor

Choose a reason for hiding this comment

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

when system-testing this branch, please make sure you test the /address/erd1.../esdt endpoint. it should validate that the affected functionalities (save key value, retrieve value) work the same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It works as expected.

@codecov-commenter
Copy link

Codecov Report

Base: 71.18% // Head: 71.16% // Decreases project coverage by -0.01% ⚠️

Coverage data is based on head (01bdd33) compared to base (534f082).
Patch coverage: 70.00% of modified lines in pull request are covered.

Additional details and impacted files
@@              Coverage Diff              @@
##           rc/v1.4.0    #4491      +/-   ##
=============================================
- Coverage      71.18%   71.16%   -0.02%     
=============================================
  Files            662      662              
  Lines          85839    85842       +3     
=============================================
- Hits           61106    61092      -14     
- Misses         20242    20249       +7     
- Partials        4491     4501      +10     
Impacted Files Coverage Δ
process/smartContract/process.go 65.94% <0.00%> (ø)
state/accountsDB.go 77.12% <50.00%> (-1.01%) ⬇️
state/journalEntries.go 80.73% <60.00%> (-1.35%) ⬇️
state/baseAccount.go 70.37% <63.63%> (-1.06%) ⬇️
state/trackableDataTrie.go 85.96% <76.92%> (-9.28%) ⬇️
epochStart/metachain/baseRewards.go 94.25% <100.00%> (ø)
epochStart/metachain/systemSCs.go 70.48% <100.00%> (ø)
node/node.go 73.30% <100.00%> (ø)
process/rewardTransaction/process.go 96.55% <100.00%> (ø)
process/scToProtocol/stakingToPeer.go 62.44% <100.00%> (ø)
... and 4 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.

gabi-vuls
gabi-vuls previously approved these changes Sep 23, 2022
Copy link
Contributor

@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.

System test passed.

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.

Just the proper release comment remains

Copy link
Contributor

@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.

System test passed.

@BeniaminDrasovean BeniaminDrasovean merged commit 5b8eb89 into rc/v1.4.0 Sep 26, 2022
@BeniaminDrasovean BeniaminDrasovean deleted the dataTrieTracker-refactor branch September 26, 2022 08:56
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.

5 participants