-
Notifications
You must be signed in to change notification settings - Fork 201
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
State changes collector #5585
State changes collector #5585
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feat/light-client-support #5585 +/- ##
===========================================================
Coverage 80.17% 80.17%
===========================================================
Files 752 753 +1
Lines 97907 98035 +128
===========================================================
+ Hits 78493 78601 +108
- Misses 14043 14056 +13
- Partials 5371 5378 +7 ☔ View full report in Codecov by Sentry. |
…t-client-support Merge rc/v1.7.0 in feat/light client support
…llector # Conflicts: # epochStart/metachain/systemSCs_test.go # factory/api/apiResolverFactory.go # factory/processing/blockProcessorCreator_test.go # factory/state/stateComponents.go # genesis/process/memoryComponents.go # integrationTests/state/stateTrie/stateTrie_test.go # integrationTests/testInitializer.go # process/transaction/metaProcess.go # state/accountsDB.go # state/accountsDB_test.go # state/errors.go # state/factory/accountsAdapterAPICreator_test.go # state/interface.go # state/storagePruningManager/storagePruningManager_test.go # state/trackableDataTrie/trackableDataTrie.go # state/trackableDataTrie/trackableDataTrie_test.go # testscommon/integrationtests/factory.go # testscommon/state/accountsAdapterStub.go # update/genesis/import.go
…n-feat/light-client-support
…-client-support Merge rc/1.7.0 in feat/light client support
# Conflicts: # cmd/node/config/config.toml # state/accountsDB_test.go # state/errors.go # state/interface.go # state/trackableDataTrie/trackableDataTrie.go
stateChanges []StateChangeDTO | ||
stateChangesForTx []StateChangesForTx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need lock protection for these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file was removed in your PR. Will leave like this so it won't generate any more conflicts.
} | ||
}) | ||
|
||
t.Run("getStateChanges without tx hash", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a test case for these 2 scenarios combined?
AddStateChange
-> AddTxHashToCollectedStateChanges
-> AddStateChange
and then GetStateChanges
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file was removed in your PR. Will leave like this so it won't generate any more conflicts.
adb.stateChangesCollector.AddTxHashToCollectedStateChanges(txHash) | ||
} | ||
|
||
func (adb *AccountsDB) ResetStateChangesCollector() []StateChangesForTx { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe rename to FetchAndReset...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this function will be used if we want to collect and save state changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This func was removed in your PR. Will leave like this so it won't generate any more conflicts.
if len(scc.stateChanges) > 0 { | ||
scc.AddTxHashToCollectedStateChanges([]byte{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so if GetStateChanges
will be called after several AddStateChange
without AddTxHashToCollectedStateChanges
those state changes will remain with empty tx hash, does it help to reference state changes without an identifier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was addressed in your PR.
@@ -913,6 +913,7 @@ func createAccountsDB( | |||
StoragePruningManager: spm, | |||
AddressConverter: &testscommon.PubkeyConverterMock{}, | |||
SnapshotsManager: disabledState.NewDisabledSnapshotsManager(), | |||
StateChangesCollector: state.NewStateChangesCollector(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use the disabled collector
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -205,6 +205,7 @@ func createAccountAdapter( | |||
StoragePruningManager: disabled.NewDisabledStoragePruningManager(), | |||
AddressConverter: &testscommon.PubkeyConverterMock{}, | |||
SnapshotsManager: disabledState.NewDisabledSnapshotsManager(), | |||
StateChangesCollector: state.NewStateChangesCollector(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use the disabled collector, and only in the specific test use a real state collector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -228,6 +235,11 @@ func (scf *stateComponentsFactory) createPeerAdapter(triesContainer common.Tries | |||
return nil, err | |||
} | |||
|
|||
stateChangesCollector := disabled.NewDisabledStateChangesCollector() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should have the state changes collected since the genesis if we only use these to export the data and index it.
Then use a flag for when we add the changes to the block.
There can also be a config flag (not enable epoch), if we want it to be exported from the node (through the outport driver) or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was refactored in the PR from Darius
@@ -172,6 +172,16 @@ func (r *simulationAccountsDB) GetStackDebugFirstEntry() []byte { | |||
return nil | |||
} | |||
|
|||
// SetTxHashForLatestStateChanges - | |||
func (r *simulationAccountsDB) SetTxHashForLatestStateChanges(txHash []byte) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will not affect also the collected changes during processing right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it will not affect
state/accountsDB.go
Outdated
} | ||
adb.stateChangesCollector.AddStateChange(stateChange) | ||
|
||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe return nil? as err!=nil was already returned at 273
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -195,6 +195,8 @@ func (txProc *txProcessor) ProcessTransaction(tx *transaction.Transaction) (vmco | |||
txProc.pubkeyConv, | |||
) | |||
|
|||
defer txProc.accounts.SetTxHashForLatestStateChanges(txHash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the defer would call this method after return, and I see processing happens before, shouldn't the set happen before the processing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was to link all the changes triggered by a tx to the txHash after the tx was executed. It can be refactored as you say, but I would do that in the next PR to avoid generating more conflicts with @ssd04's PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added TODO
@@ -217,7 +222,8 @@ func (adb *AccountsDB) ImportAccount(account vmcommon.AccountHandler) error { | |||
} | |||
|
|||
mainTrie := adb.getMainTrie() | |||
return adb.saveAccountToTrie(account, mainTrie) | |||
_, err := adb.saveAccountToTrie(account, mainTrie) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what was the purpose of this save?
also does it affect the trie state? if it does then we should collect the data as state change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used only on the old hardFork component, which will be removed.
state/accountsDBApi.go
Outdated
|
||
// ResetStateChangesCollector returns nil | ||
func (accountsDB *accountsDBApi) ResetStateChangesCollector() []StateChangesForTx { | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't seem to reset anything but for the setTxHashForLatestStateChanges a txhash seems to be registered.
so is this empty reset ok and should setTxHashForLatestStateChanges do nothing as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed for consistency. This component uses a disabledStateChangesCollector, so it would not do anything.
@@ -66,7 +66,7 @@ func (jea *journalEntryCode) revertOldCodeEntry() error { | |||
return nil | |||
} | |||
|
|||
err := saveCodeEntry(jea.oldCodeHash, jea.oldCodeEntry, jea.trie, jea.marshalizer) | |||
_, err := saveCodeEntry(jea.oldCodeHash, jea.oldCodeEntry, jea.trie, jea.marshalizer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I have seen any treatment for the revert in the state collector, I guess that is on another PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is treated in the PR from @ssd04
} | ||
|
||
type stateChangesCollector struct { | ||
stateChanges []StateChangeDTO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are the separate state changes not linked to a txhash for?
I guess they should still be linked to a reason of the change, even if there is no tx for that - e.g rating change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. This will be done in the next PR
# Conflicts: # testscommon/state/accountsAdapterStub.go
Reasoning behind the pull request
Proposed changes
stateChangesCollector
will save all the changes made to that account. This includes code changes, data trie changes, data trie migration, etc. No extra processing is needed, the new data is already available in thetrackableDataTrie
stateChangesCollector
so that it will be ready for the next tx execution.CollectStateChangesEnabled
which is disabled by default.Testing procedure
Pre-requisites
Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:
feat
branch created?feat
branch merging, do all satellite projects have a proper tag insidego.mod
?