-
Notifications
You must be signed in to change notification settings - Fork 205
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
add custom error for trie get node #4724
add custom error for trie get node #4724
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## feat/sync-missing-trie-nodes #4724 +/- ##
===============================================================
Coverage ? 70.86%
===============================================================
Files ? 674
Lines ? 87714
Branches ? 0
===============================================================
Hits ? 62161
Misses ? 20875
Partials ? 4678 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 in Codecov by Sentry. |
process/sync/metablock.go
Outdated
@@ -180,37 +182,32 @@ func (boot *MetaBootstrap) setLastEpochStartRound() { | |||
func (boot *MetaBootstrap) SyncBlock(ctx context.Context) error { | |||
err := boot.syncBlock() | |||
if errors.IsGetNodeFromDBError(err) { | |||
errSync := boot.syncAccountsDBs() | |||
getNodeErr, ok := err.(*errors.GetNodeFromDBErr) |
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.
Misleading names. We have the if errors.IsGetNodeFromDBError(err) {
instruction and then we can not cast it to a *errors.GetNodeFromDBErr
? Let's refactor this.
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
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.
not done. We have the same function and the same cast. Please refactor.
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 interface here
process/sync/shardblock.go
Outdated
@@ -144,7 +144,12 @@ func (boot *ShardBootstrap) StartSyncingBlocks() { | |||
func (boot *ShardBootstrap) SyncBlock(ctx context.Context) error { | |||
err := boot.syncBlock() | |||
if errors.IsGetNodeFromDBError(err) { | |||
errSync := boot.syncUserAccountsState() | |||
getNodeErr, ok := err.(*errors.GetNodeFromDBErr) |
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.
also here, misleading names, please refactor
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
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.
not done
@@ -1033,6 +1033,11 @@ func (ps *PruningStorer) RangeKeys(_ func(key []byte, val []byte) bool) { | |||
debug.PrintStack() | |||
} | |||
|
|||
// GetIdentifier returns the identifier for storer | |||
func (ps *PruningStorer) GetIdentifier() string { | |||
return ps.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.
I think that if we somehow, change the paths and names for the accounts storers, the whole code will break. We need to find a proper way to use storers identifiers in this case. Perhaps using the trie containers implementation as seen in factory/state/stateComponents.go L151-L178?
This happens because we have 2 sets of constants declared: one in trie/trieFactory/trieFactoryArgs.go and the other one in dataRetriever/unitType.go
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.
from what i've tested, it still seems to work, will think more on the refactoring here
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.
Works for now because the strings from both constant sets are the same. Will need to refactor this somehow. You can refactor now or add a TODO + task.
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 and separate task for this
…s-for-storage-mappers refactor to use storer ids for dataRetriever
# Conflicts: # dataRetriever/factory/resolverscontainer/metaResolversContainerFactory.go # dataRetriever/factory/resolverscontainer/metaResolversContainerFactory_test.go # dataRetriever/factory/resolverscontainer/shardResolversContainerFactory.go # dataRetriever/factory/resolverscontainer/shardResolversContainerFactory_test.go # factory/consensus/consensusComponents.go # factory/processing/blockProcessorCreator_test.go # genesis/process/genesisBlockCreator.go # genesis/process/genesisBlockCreator_test.go # integrationTests/state/stateTrie/stateTrie_test.go # integrationTests/state/stateTrieSync/stateTrieSync_test.go # integrationTests/testProcessorNode.go # node/nodeRunner.go # process/block/shardblock.go # process/coordinator/process.go # process/sync/baseSync.go # process/sync/metablock_test.go # process/sync/shardblock_test.go # testscommon/components/components.go # testscommon/components/default.go # update/genesis/import.go # update/genesis/import_test.go
# Conflicts: # testscommon/components/default.go
@@ -13,13 +13,13 @@ require ( | |||
github.com/google/gops v0.3.18 | |||
github.com/gorilla/websocket v1.5.0 | |||
github.com/mitchellh/mapstructure v1.5.0 | |||
github.com/multiversx/mx-chain-core-go v1.2.0 | |||
github.com/multiversx/mx-chain-core-go v1.2.1-0.20230403113932-916b16d18978 |
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.
proper releases
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 be merged in a feature branch. Will create a release tag when the feature branch will be merged.
process/coordinator/process.go
Outdated
@@ -719,6 +719,11 @@ func (tc *transactionCoordinator) CreateMbsAndProcessCrossShardTransactionsDstMe | |||
"total gas penalized", tc.gasHandler.TotalGasPenalized(), | |||
"error", errProc, | |||
) | |||
|
|||
if core.IsGetNodeFromDBError(errProc) { | |||
return nil, 0, false, 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.
unit test?
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. Also, return errProc
instead of 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.
Actually, removed this check. As discussed, it is not needed here.
process/block/shardblock.go
Outdated
@@ -2026,6 +2026,10 @@ func (sp *shardProcessor) createMiniBlocks(haveTime func() bool, randomness []by | |||
log.Debug("elapsed time to create mbs to me", "time", elapsedTime) | |||
if err != nil { | |||
log.Debug("createAndProcessCrossMiniBlocksDstMe", "error", err.Error()) | |||
|
|||
if core.IsGetNodeFromDBError(err) { | |||
return nil, nil, 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.
unit test?
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.
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.
Removed the check, not needed here.
state/accountsDB.go
Outdated
@@ -524,7 +523,8 @@ func (adb *AccountsDB) loadDataTrie(accountHandler baseAccountHandler, mainTrie | |||
|
|||
dataTrie, err := mainTrie.Recreate(accountHandler.GetRootHash()) | |||
if err != nil { | |||
return fmt.Errorf("trie was not found for hash, rootHash = %s, err = %w", hex.EncodeToString(accountHandler.GetRootHash()), err) | |||
log.Error("trie was not found for hash", "rootHash", accountHandler.GetRootHash(), "err", 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.
log error & return error at the same time? Maybe an error wrap will help?
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.
Reverted the changes, the err is now wrapped before returning. Removed the log print.
trie/node.go
Outdated
dbWithID, ok := db.(dbWriteCacherWithIdentifier) | ||
if !ok { | ||
log.Trace(common.GetNodeFromDBErrorString, "error", err, "key", n, "db type", fmt.Sprintf("%T", db)) | ||
log.Warn("db does not have an identifier", "db type", fmt.Sprintf("%T", db)) |
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.
log warn while returning the error. Why not wrap?
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 log trace if you already return this error in the caller side 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.
Wrapped the err.
trie/patriciaMerkleTrie.go
Outdated
@@ -88,7 +88,7 @@ func (tr *patriciaMerkleTrie) Get(key []byte) ([]byte, uint32, error) { | |||
|
|||
val, depth, err := tr.root.tryGet(hexKey, rootDepthLevel, tr.trieStorage) | |||
if err != nil { | |||
err = fmt.Errorf("trie get error: %w, for key %v", err, hex.EncodeToString(key)) | |||
log.Error("trie get error", "error", err.Error(), "key", key) |
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.
same here, log error while returning. Why not wrap?
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 same here
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.
Reverted the changes, use wrapped err.
@@ -687,6 +687,17 @@ func (tsm *trieStorageManager) GetBaseTrieStorageManager() common.StorageManager | |||
return tsm | |||
} | |||
|
|||
// GetIdentifier returns the identifier of the main storer | |||
func (tsm *trieStorageManager) GetIdentifier() string { | |||
dbWithIdentifier, ok := tsm.mainStorer.(dbWriteCacherWithIdentifier) |
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.
unit test
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.
@@ -1,24 +1,43 @@ | |||
package errors | |||
|
|||
import ( | |||
"strings" | |||
|
|||
"encoding/hex" |
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.
go imports?
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.
errors/missingTrieNodeError.go
Outdated
|
||
if IsClosingError(err) { | ||
return false | ||
// NewGetNodeFromDBErrWithKey will create a new instance of GetNodeFromDBErr |
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.
GetNodeFromDBErrWithKey?
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.
@@ -1090,6 +1089,11 @@ func (txs *transactions) CreateAndProcessMiniBlocks(haveTime func() bool, random | |||
|
|||
if err != nil { | |||
log.Debug("createAndProcessMiniBlocksFromMe", "error", err.Error()) | |||
|
|||
if core.IsGetNodeFromDBError(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.
Will have this change the desired effect? In the caller side, func (tc *transactionCoordinator) CreateMbsAndProcessTransactionsFromMe, there is only a print when this method returns error. I think that the behavior will remain the same.
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.
Right, removed.
process/coordinator/process.go
Outdated
@@ -719,6 +719,11 @@ func (tc *transactionCoordinator) CreateMbsAndProcessCrossShardTransactionsDstMe | |||
"total gas penalized", tc.gasHandler.TotalGasPenalized(), | |||
"error", errProc, | |||
) | |||
|
|||
if core.IsGetNodeFromDBError(errProc) { | |||
return nil, 0, false, 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.
If we want that the execution of miniblocks dest me to continue with other mini blocks (from other shards) we need only to break here. The return will be in format return miniblocks, numTxsAdded, false, nil. Otherwise all the execution dest me will be skipped. Which is the real intention here?
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.
Removed, as discussed.
trie/node.go
Outdated
dbWithID, ok := db.(dbWriteCacherWithIdentifier) | ||
if !ok { | ||
log.Trace(common.GetNodeFromDBErrorString, "error", err, "key", n, "db type", fmt.Sprintf("%T", db)) | ||
log.Warn("db does not have an identifier", "db type", fmt.Sprintf("%T", db)) |
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 log trace if you already return this error in the caller side as well.
trie/patriciaMerkleTrie.go
Outdated
@@ -88,7 +88,7 @@ func (tr *patriciaMerkleTrie) Get(key []byte) ([]byte, uint32, error) { | |||
|
|||
val, depth, err := tr.root.tryGet(hexKey, rootDepthLevel, tr.trieStorage) | |||
if err != nil { | |||
err = fmt.Errorf("trie get error: %w, for key %v", err, hex.EncodeToString(key)) | |||
log.Error("trie get error", "error", err.Error(), "key", key) |
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 same here
update/genesis/import.go
Outdated
@@ -5,6 +5,7 @@ import ( | |||
"encoding/hex" | |||
"encoding/json" | |||
"fmt" | |||
"github.com/multiversx/mx-chain-go/dataRetriever" |
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.
go imports
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.
update/genesis/import.go
Outdated
@@ -292,9 +292,9 @@ func (si *stateImport) getTrie(shardID uint32, accType Type) (common.Trie, error | |||
return trieForShard, nil | |||
} | |||
|
|||
trieStorageManager := si.trieStorageManagers[triesFactory.UserAccountTrie] | |||
trieStorageManager := si.trieStorageManagers[dataRetriever.PeerAccountsUnit.String()] |
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.
UserAccountsUnit?
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. Changed.
@@ -2156,3 +2156,23 @@ func TestShardBootstrap_NilInnerBootstrapperClose(t *testing.T) { | |||
bootstrapper := &sync.ShardBootstrap{} | |||
assert.Nil(t, bootstrapper.Close()) | |||
} | |||
|
|||
func TestUnwrapGetNodeFromDBErr(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.
👍
Reasoning behind the pull request
Proposed changes
Testing procedure
AccountsStatePruningEnabled
andPeerStatePruningEnabled
on falsePre-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
?