mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
Report on duplicate validator keys during imports (#7459)
* Fix #7393 * fix go fmt * Add a test * Convert to map of strings * @terencechain fixes * Update validator/keymanager/v2/direct/import.go Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
This commit is contained in:
parent
d98a6dda8f
commit
c4e64afd07
@ -39,6 +39,14 @@ func (dr *Keymanager) ImportKeystores(
|
||||
return errors.Wrap(err, "could not add to progress bar")
|
||||
}
|
||||
}
|
||||
foundKey := map[string]bool{}
|
||||
for i := range pubKeys {
|
||||
strKey := string(pubKeys[i])
|
||||
if foundKey[strKey] {
|
||||
return fmt.Errorf("duplicated key found: %#x", pubKeys[i])
|
||||
}
|
||||
foundKey[strKey] = true
|
||||
}
|
||||
// Write the accounts to disk into a single keystore.
|
||||
accountsKeystore, err := dr.createAccountsKeystore(ctx, privKeys, pubKeys)
|
||||
if err != nil {
|
||||
|
@ -100,18 +100,25 @@ func TestDirectKeymanager_ImportKeystores(t *testing.T) {
|
||||
accountsStore: &AccountStore{},
|
||||
}
|
||||
|
||||
// Create several keystores and attempt to import them.
|
||||
// Create a duplicate keystore and attempt to import it.
|
||||
numAccounts := 5
|
||||
keystores := make([]*v2keymanager.Keystore, numAccounts)
|
||||
for i := 0; i < numAccounts; i++ {
|
||||
keystores := make([]*v2keymanager.Keystore, numAccounts+1)
|
||||
for i := 1; i < numAccounts+1; i++ {
|
||||
keystores[i] = createRandomKeystore(t, password)
|
||||
}
|
||||
keystores[0] = keystores[1]
|
||||
ctx := context.Background()
|
||||
require.NoError(t, dr.ImportKeystores(
|
||||
require.ErrorContains(t, "duplicated key found:", dr.ImportKeystores(
|
||||
ctx,
|
||||
keystores,
|
||||
password,
|
||||
))
|
||||
// Import them correctly without the duplicate.
|
||||
require.NoError(t, dr.ImportKeystores(
|
||||
ctx,
|
||||
keystores[1:],
|
||||
password,
|
||||
))
|
||||
|
||||
// Ensure the single, all-encompassing accounts keystore was written
|
||||
// to the wallet and ensure we can decrypt it using the EIP-2335 standard.
|
||||
|
Loading…
Reference in New Issue
Block a user