-
Notifications
You must be signed in to change notification settings - Fork 197
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
@@ -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) |
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.
👍
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) |
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.
👍
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 |
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.
👍
@@ -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) |
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.
could have injected a context 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.
done
close(ch) | ||
}() | ||
close(ch) | ||
}() |
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.
indenting gone wild?
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
@@ -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) |
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.
👍
context.Background()
is correct in this situation
state/accountsDB_test.go
Outdated
GetAllLeavesOnChannelCalled: func(rootHash []byte) (chan core.KeyValueHolder, error) { | ||
getAllLeavesCalled = true | ||
GetAllLeavesOnChannelCalled: func(ch chan core.KeyValueHolder, ctx context.Context, rootHash []byte) error { | ||
getAllLeavesCalled = true |
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.
indentation gone wild?
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.
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) |
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.
👍
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") |
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 unused
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
@@ -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) |
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.
👍
context.Background()
is correct in this situation
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.
System test passed.
… into EN-11730-get-all-leaves-context
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.
System test passed
e43a33d
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.
System test passed.
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