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

EN-11730: use a context + predefined channel for get all leaves operations #3900

Merged
merged 15 commits into from
Mar 18, 2022

Conversation

bogdan-rosianu
Copy link
Contributor

@bogdan-rosianu bogdan-rosianu commented Mar 14, 2022

Refactor GetAllLeaves / GetAllLeavesOnChannel functions so they receive the channel instead of creating it + they receive a context as well that can trigger an early exit on the processing.

Implemented a timeout mechanism for node's API endpoints that called that function

@codecov
Copy link

codecov bot commented Mar 15, 2022

Codecov Report

Merging #3900 (0d9245d) into development (a35ed26) will increase coverage by 0.00%.
The diff coverage is 81.88%.

@@             Coverage Diff              @@
##           development    #3900   +/-   ##
============================================
  Coverage        74.88%   74.88%           
============================================
  Files              614      614           
  Lines            81804    81864   +60     
============================================
+ Hits             61255    61305   +50     
- Misses           15889    15900   +11     
+ Partials          4660     4659    -1     
Impacted Files Coverage Δ
factory/processComponents.go 64.81% <0.00%> (-0.07%) ⬇️
trie/leafNode.go 79.04% <0.00%> (-0.89%) ⬇️
trie/branchNode.go 78.81% <20.00%> (-0.45%) ⬇️
trie/extensionNode.go 71.39% <20.00%> (-0.51%) ⬇️
trie/patriciaMerkleTrie.go 73.96% <80.00%> (ø)
facade/nodeFacade.go 68.88% <81.81%> (+1.27%) ⬆️
node/node.go 72.77% <92.00%> (+0.20%) ⬆️
epochStart/metachain/systemSCs.go 71.59% <100.00%> (+0.03%) ⬆️
node/external/nodeApiResolver.go 59.79% <100.00%> (ø)
node/trieIterators/delegatedListProcessor.go 85.18% <100.00%> (+4.23%) ⬆️
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c563557...0d9245d. Read the comment docs.

@bogdan-rosianu bogdan-rosianu marked this pull request as ready for review March 15, 2022 15:09
@iulianpascalau iulianpascalau self-requested a review March 15, 2022 15:10
@@ -1128,7 +1129,8 @@ func (s *systemSCProcessor) getArgumentsForSetOwnerFunctionality(userValidatorAc
return nil, err
}

chLeaves, err := userValidatorAccount.DataTrie().GetAllLeavesOnChannel(rootHash)
chLeaves := make(chan core.KeyValueHolder, common.TrieLeavesChannelDefaultCapacity)
err = userValidatorAccount.DataTrie().GetAllLeavesOnChannel(chLeaves, context.Background(), rootHash)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍
context.Background() is correct in this situation

@@ -781,7 +782,8 @@ func (pcf *processComponentsFactory) indexGenesisAccounts() error {
return err
}

leavesChannel, err := pcf.state.AccountsAdapter().GetAllLeaves(rootHash)
leavesChannel := make(chan core.KeyValueHolder, common.TrieLeavesChannelDefaultCapacity)
err = pcf.state.AccountsAdapter().GetAllLeaves(leavesChannel, context.Background(), rootHash)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍
context.Background() is correct in this situation

go.mod Outdated
replace github.com/libp2p/go-libp2p-pubsub v0.5.5 => github.com/ElrondNetwork/go-libp2p-pubsub v0.5.5-gamma
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -124,7 +126,8 @@ func (dlp *delegatedListProcessor) getDelegatorsList(delegationSC []byte) ([][]b
return nil, fmt.Errorf("%w for delegationSC %s", err, hex.EncodeToString(delegationSC))
}

chLeaves, err := delegatorAccount.DataTrie().GetAllLeavesOnChannel(rootHash)
chLeaves := make(chan core.KeyValueHolder, common.TrieLeavesChannelDefaultCapacity)
err = delegatorAccount.DataTrie().GetAllLeavesOnChannel(chLeaves, context.Background(), rootHash)
Copy link
Contributor

Choose a reason for hiding this comment

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

could have injected a context here

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

close(ch)
}()
close(ch)
}()
Copy link
Contributor

Choose a reason for hiding this comment

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

indenting gone wild?

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

@@ -572,7 +573,8 @@ func (vs *validatorStatistics) GetValidatorInfoForRootHash(rootHash []byte) (map
log.Debug("GetValidatorInfoForRootHash", sw.GetMeasurements()...)
}()

leavesChannel, err := vs.peerAdapter.GetAllLeaves(rootHash)
leavesChannel := make(chan core.KeyValueHolder, common.TrieLeavesChannelDefaultCapacity)
err := vs.peerAdapter.GetAllLeaves(leavesChannel, context.Background(), rootHash)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍
context.Background() is correct in this situation

GetAllLeavesOnChannelCalled: func(rootHash []byte) (chan core.KeyValueHolder, error) {
getAllLeavesCalled = true
GetAllLeavesOnChannelCalled: func(ch chan core.KeyValueHolder, ctx context.Context, rootHash []byte) error {
getAllLeavesCalled = true
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation gone wild?

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

@@ -211,7 +211,8 @@ func (u *userAccountsSyncer) syncAccountDataTries(
return err
}

leavesChannel, err := mainTrie.GetAllLeavesOnChannel(mainRootHash)
leavesChannel := make(chan core.KeyValueHolder, common.TrieLeavesChannelDefaultCapacity)
err = mainTrie.GetAllLeavesOnChannel(leavesChannel, context.Background(), mainRootHash)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍
context.Background() is correct in this situation

trie/errors.go Outdated
@@ -105,3 +105,6 @@ var ErrKeyNotFound = errors.New("key not found")

// ErrNilEpochNotifier signals that the provided EpochNotifier is nil
var ErrNilEpochNotifier = errors.New("nil EpochNotifier")

// ErrContextDeadlineExceeded signals that a context has exceeded it's deadline
var ErrContextDeadlineExceeded = errors.New("context deadline exceeded")
Copy link
Contributor

Choose a reason for hiding this comment

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

this is unused

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

@@ -269,7 +270,8 @@ func (se *stateExport) exportTrie(key string, trie common.Trie) error {
return err
}

leavesChannel, err := trie.GetAllLeavesOnChannel(rootHash)
leavesChannel := make(chan core.KeyValueHolder, common.TrieLeavesChannelDefaultCapacity)
err = trie.GetAllLeavesOnChannel(leavesChannel, context.Background(), rootHash)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍
context.Background() is correct in this situation

@bogdan-rosianu bogdan-rosianu self-assigned this Mar 15, 2022
gabi-vuls
gabi-vuls previously approved these changes Mar 16, 2022
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.

System test passed.

facade/nodeFacade.go Outdated Show resolved Hide resolved
iulianpascalau
iulianpascalau previously approved these changes Mar 17, 2022
gabi-vuls
gabi-vuls previously approved these changes Mar 17, 2022
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.

System test passed

miiu96
miiu96 previously approved these changes Mar 18, 2022
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.

System test passed.

@gabi-vuls gabi-vuls merged commit d5b958a into development Mar 18, 2022
@gabi-vuls gabi-vuls deleted the EN-11730-get-all-leaves-context branch March 18, 2022 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants