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

Web Backend Revert delete rpc #8681

Merged
merged 29 commits into from
Apr 2, 2021

Conversation

ahadda5
Copy link
Contributor

@ahadda5 ahadda5 commented Mar 28, 2021

What type of PR is this?
Feature #8664

What does this PR do? Why is it needed?
WebUI needs to allow for the deletion of accounts. We will revert back this feature which existed before.

Which issues(s) does this PR fix?
Fixes #8664 The portion about adding back the delete accounts RPC endpoints, previously reverted from Prysm

Other notes for review
On reverting the code the following considerations were accounted for.

  • Added The DeleteAccountRequest and Response with the DeletedPublicKeys in protobuf
  • InitKeymanagerConfig func used in the DeleteAccounts is called with ListenForChanges not SkipMnemonic as before
  • Added back a func createImportedWalletWithAccounts , originally part of wallet_test.go which , as the name implies, creates a wallet and imports a test-generated keystore.

ahadda5 added 3 commits March 28, 2021 15:51
…ys provided and the successful imported account with provided public keys; also brought back the createImportedWalletWithAccounts back in wallet_test.go
@ahadda5 ahadda5 requested a review from a team as a code owner March 28, 2021 14:33
@ahadda5 ahadda5 requested review from farazdagi, 0xKiwi and nisdas March 28, 2021 14:33
Copy link
Contributor

@rkapka rkapka left a comment

Choose a reason for hiding this comment

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

Please run goimports. We should have local imports first, followed by an empty line, followed by external imports. Changes to most pb files' imports are unnecessary.

func (s *Server) DeleteAccounts(
ctx context.Context, req *pb.DeleteAccountsRequest,
) (*pb.DeleteAccountsResponse, error) {
if req.DeletePublicKeys == nil || len(req.DeletePublicKeys) < 1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to also add a test for this precondition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added.

validator/rpc/accounts_test.go Outdated Show resolved Hide resolved
}

func TestServer_DeleteAccounts_OK(t *testing.T) {
ss, pubKeys := createImportedWalletWithAccounts(t, 3)
Copy link
Contributor

Choose a reason for hiding this comment

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

ss is a really bad name. Can we change it to server?

//require.NoError(t, w.SaveHashedPassword(ctx))
km, err := w.InitializeKeymanager(ctx, iface.InitKeymanagerConfig{ListenForChanges: false})
require.NoError(t, err)
ss := &Server{
Copy link
Contributor

Choose a reason for hiding this comment

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

ss is a weird name. Why not s or server?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to s


message DeleteAccountsRequest {
// List of public keys to delete.
repeated bytes delete_public_keys = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

delete_public_keys sounds like a good function name, but parameter names should be nouns. I would prefer simply public_keys.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed. Although, I was trying to be consistent with the accounts.Config . Should i change the protobuf?

type Config struct {
  | Wallet           *wallet.Wallet
  | Keymanager       keymanager.IKeymanager
  | DeletePublicKeys [][]byte
  | }

Copy link
Contributor

@rkapka rkapka Mar 29, 2021

Choose a reason for hiding this comment

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

It's OK if they are not the same. Config's name is also a bit awkward, I think PublicKeysToDelete makes more sense (I would not call it simply PublicKeys because the type Config does not convey any information as to what these public keys are, as opposed to the protobuf type name).

@ahadda5 ahadda5 changed the title Webbackendrevert delete rpc Web Backend Revert delete rpc Mar 29, 2021
@ahadda5
Copy link
Contributor Author

ahadda5 commented Mar 29, 2021

Please run goimports. We should have local imports first, followed by an empty line, followed by external imports. Changes to most pb files' imports are unnecessary.

AFter running goimports on the root proto libs , DeepSource complains about this below. What is that would you know?
var protoReq eth.PeerRequest

@rkapka
Copy link
Contributor

rkapka commented Mar 29, 2021

So it looks like 7348624 removed an import from proto/beacon/rpc/v1_gateway/debug.pb.gw.go that was actually needed. Also the alias in import v1alpha1 "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" in proto/validator/accounts/v2_gateway/web_api.pb.go should be changed to eth (resulting in eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1").

…e deleterequest variable to PublicKeysToDelete
@ahadda5
Copy link
Contributor Author

ahadda5 commented Mar 29, 2021

I think its because i ran update proto scripts before goimports. It is fixed now. Thanks

@rkapka
Copy link
Contributor

rkapka commented Mar 29, 2021

Unfortunately your last commit again mixed up imports. I am not sure why this happens. Can you maybe just revert these changes manually in case the tooling does not work properly?

if s.wallet == nil || s.keymanager == nil {
return nil, status.Error(codes.FailedPrecondition, "No wallet found")
}
if s.wallet.KeymanagerKind() != keymanager.Imported {
Copy link
Contributor

Choose a reason for hiding this comment

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

We have since changed the requirements and now both imported and derived keymanagers can delete keys. Remote cannot, so we should update 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.

How would one test a derived wallet delete? accounts.DeleteAccounts supports both imported and derived but only tests the imported wallets (check here
If i get it to work in rpc , we can update the accounts module as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

A derived wallet is internally implemented as an imported wallet, that's why testing an imported wallet is enough for the most part.

An example of setting up a derived wallet for testing can be found here:

t.Run("Derived keymanager", func(t *testing.T) {

Copy link
Contributor

@rauljordan rauljordan left a comment

Choose a reason for hiding this comment

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

I think you might need to do gofmt -w -s . or goimports to prevent changing all those other unrelated proto files

SkipMnemonicConfirm: true,
})
require.NoError(t, err)
//require.NoError(t, w.SaveHashedPassword(ctx))
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's delete the commented code

@codecov
Copy link

codecov bot commented Mar 31, 2021

Codecov Report

Merging #8681 (3f7e724) into develop (28e4a3b) will increase coverage by 0.03%.
The diff coverage is 77.77%.

❗ Current head 3f7e724 differs from pull request most recent head b9eb9e4. Consider uploading reports for the commit b9eb9e4 to get more accurate results

@@             Coverage Diff             @@
##           develop    #8681      +/-   ##
===========================================
+ Coverage    61.15%   61.18%   +0.03%     
===========================================
  Files          498      498              
  Lines        34711    34729      +18     
===========================================
+ Hits         21227    21250      +23     
+ Misses       10332    10316      -16     
- Partials      3152     3163      +11     

@rauljordan
Copy link
Contributor

PTAL @rkapka

@rkapka rkapka merged commit 8784390 into prysmaticlabs:develop Apr 2, 2021
@ahadda5 ahadda5 deleted the webbackendrevertDeleteRPC branch April 4, 2021 06:19
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.

[Tracking] - Web UI V1 Backend Requirements
3 participants