Handle duplicate keystores in import path without error #7842
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
What does this PR do? Why is it needed?
Currently if you have two keystores for the same validator key in the import folder path, there will be failure during import. This is documented in #7828
In keymanager/imported/import.go:
A map is used to detect duplicate keys and if so, stops progress and returns an error. One initial question that came to my mind was if this de-duplication is needed in this function and whether this is just for logging as there is de-duplication in a function called later. The duplicate-catching aspect of this function is needed as it ends up calling createAccountsKeystore() which will check to see if the importing keys are duplicates of the keys already in the keymanager but not necessarily if the keys being imported are matches of each other (eg. if wallet starts with 0 keys, and you import 10 identical keys, all 10 will make it into the wallet since they are not identical to keys already in the wallet if all you relied on was the downstream function createAccountsKeystore(). This function's de-duplication is needed).
This PR changes that piece of code so that a map is used to collect the keys [which inherently prevents duplicates] and then in the end, conversion is done to [][]byte so that it is in a form that is expected by createAccountsKeystore().
I think the reporting of duplicate keys being detected within the import folder is also good to keep so there is a Warn level message.
Which issues(s) does this PR fix?
Fixes #7828
Other notes for review