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

Import Keystores Standard API Implementation #9924

Merged
merged 30 commits into from
Nov 24, 2021
Merged

Conversation

rauljordan
Copy link
Contributor

@rauljordan rauljordan commented Nov 22, 2021

This PR implements the ImportKeystores standard API endpoint defined in here as a POST request. It allows for importing slashing protection, keystores with different passwords, and aligns with the specification. We already had an API endpoint named ImportKeystores as part of the Prysm endpoints. This is only used by the web interface, and we are safe to rename it to something more-specific to Prysm.

  • Rename current Prysm endpoint to ImportAccounts to reserve ImportKeystores for the standard API
  • Define an Importer interface that both the derived and imported keymanager implement
  • Amend the keymanager logic to support multiple passwords per keystore
  • Implement the API endpoint for ImportKeystores according to specification, ensuring it works as expected with necessary tests

Note: Diff large due to protobuf regeneration.

@rauljordan rauljordan requested a review from a team as a code owner November 22, 2021 17:53
@@ -131,33 +131,6 @@ func TestImport_DuplicateKeys(t *testing.T) {
assert.Equal(t, 1, len(keys))
}

// TestImport_NonImportedWallet is a regression test that ensures non-silent failure when importing to non-imported wallets
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Derived wallets should be able to import keystores as they are merely wrappers over imported wallets

@@ -311,30 +311,7 @@ func TestServer_WalletConfig(t *testing.T) {
})
}

func TestServer_ImportKeystores_FailedPreconditions_WrongKeymanagerKind(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Derived wallets should be able to import keystores as they are merely wrappers over imported wallets

k := &keymanager.Keystore{}
if err := json.Unmarshal([]byte(req.Keystores[i]), k); err != nil {
return nil, status.Errorf(
codes.Internal, "Invalid keystore at index %d in request: %v", i, err,
Copy link
Contributor

Choose a reason for hiding this comment

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

wondering if it returns bad request if any keystore is malformed or if there should be returning it with error status

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for bad request

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The API spec only allows for returning a few error codes, 200, 401, 403, and 500 and nothing else, unfortunately

if err != nil {
return nil, status.Errorf(codes.Internal, "Could not import keystores: %v", err)
}
return &ethpbservice.ImportKeystoresResponse{Statuses: statuses}, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

we can also include the message with the status, but I need to ask about including the public key here too in the response...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's revisit in a future PR

validator/accounts/accounts_import.go Outdated Show resolved Hide resolved
validator/accounts/accounts_import.go Outdated Show resolved Hide resolved
validator/accounts/accounts_import.go Outdated Show resolved Hide resolved
validator/keymanager/imported/import.go Outdated Show resolved Hide resolved
validator/keymanager/imported/import.go Outdated Show resolved Hide resolved
@rkapka
Copy link
Contributor

rkapka commented Nov 24, 2021

One side-question: What happens when the user abruptly stops the import in the middle, e.g. by pressing Ctrl+C? Will the keystore become corrupted?

@rauljordan
Copy link
Contributor Author

One side-question: What happens when the user abruptly stops the import in the middle, e.g. by pressing Ctrl+C? Will the keystore become corrupted?

Probably, but that risk exists anywhere we are writing to the DB, so there is no real good way to prevent this if a user forcefully kills a process

@rauljordan rauljordan dismissed a stale review via a89776d November 24, 2021 15:10
@rauljordan rauljordan merged commit 4ae7513 into develop Nov 24, 2021
@delete-merged-branch delete-merged-branch bot deleted the import-keystores branch November 24, 2021 15:40
potuz pushed a commit that referenced this pull request Nov 30, 2021
* begin

* rem deleted code

* delete keystores all tests

* surface errors to user

* add in changes

* del

* tests

* slice

* begin import process

* add import keystores logic

* unit tests for import

* tests for all import keystores keymanager issues

* change proto

* pbs

* renaming works

* use proper request

* pb

* comment

* gaz

* fix up cli cmd

* test

* add gw

* precond

* tests

* radek comments
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.

3 participants