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

Make Interop keys functional for accounts-v2, use v2 for E2E #7103

Merged
merged 7 commits into from
Aug 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions shared/featureconfig/flags.go
Original file line number Diff line number Diff line change
@@ -631,8 +631,6 @@ var SlasherFlags = append(deprecatedFlags, []cli.Flag{
// E2EValidatorFlags contains a list of the validator feature flags to be tested in E2E.
var E2EValidatorFlags = []string{
"--wait-for-synced",
"--enable-local-protection",
"--disable-accounts-v2",
}

// BeaconChainFlags contains a list of all the feature flags that apply to the beacon-chain client.
1 change: 1 addition & 0 deletions validator/keymanager/v2/direct/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ go_library(
"//shared/bytesutil:go_default_library",
"//shared/depositutil:go_default_library",
"//shared/fileutil:go_default_library",
"//shared/interop:go_default_library",
"//shared/petnames:go_default_library",
"//shared/promptutil:go_default_library",
"//validator/accounts/v2/iface:go_default_library",
29 changes: 26 additions & 3 deletions validator/keymanager/v2/direct/direct.go
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ import (
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/depositutil"
"github.com/prysmaticlabs/prysm/shared/fileutil"
"github.com/prysmaticlabs/prysm/shared/interop"
"github.com/prysmaticlabs/prysm/shared/petnames"
"github.com/prysmaticlabs/prysm/shared/promptutil"
"github.com/prysmaticlabs/prysm/validator/accounts/v2/iface"
@@ -132,6 +133,26 @@ func NewKeymanager(ctx *cli.Context, wallet iface.Wallet, cfg *Config) (*Keymana
return k, nil
}

// NewInteropKeymanager instantiates a new direct keymanager with the deterministically generated interop keys.
func NewInteropKeymanager(ctx *cli.Context, offset uint64, numValidatorKeys uint64) (*Keymanager, error) {
k := &Keymanager{
keysCache: make(map[[48]byte]bls.SecretKey),
}
if numValidatorKeys == 0 {
return k, nil
}

secretKeys, publicKeys, err := interop.DeterministicallyGenerateKeys(offset, numValidatorKeys)
if err != nil {
return nil, errors.Wrap(err, "could not generate interop keys")
}

for i := 0; i < len(publicKeys); i++ {
k.keysCache[bytesutil.ToBytes48(publicKeys[i].Marshal())] = secretKeys[i]
}
return k, nil
}

// UnmarshalConfigFile attempts to JSON unmarshal a direct keymanager
// configuration file into the *Config{} struct.
func UnmarshalConfigFile(r io.ReadCloser) (*Config, error) {
@@ -180,9 +201,11 @@ func (dr *Keymanager) AccountsPassword() string {

// ValidatingAccountNames for a direct keymanager.
func (dr *Keymanager) ValidatingAccountNames() ([]string, error) {
names := make([]string, len(dr.accountsStore.PublicKeys))
for i, pubKey := range dr.accountsStore.PublicKeys {
names[i] = petnames.DeterministicName(pubKey, "-")
names := make([]string, len(dr.keysCache))
index := 0
for pubKey := range dr.keysCache {
names[index] = petnames.DeterministicName(pubKey[:], "-")
index++
}
return names, nil
}
1 change: 1 addition & 0 deletions validator/node/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ go_library(
"//validator/flags:go_default_library",
"//validator/keymanager/v1:go_default_library",
"//validator/keymanager/v2:go_default_library",
"//validator/keymanager/v2/direct:go_default_library",
"//validator/rpc:go_default_library",
"//validator/rpc/gateway:go_default_library",
"//validator/slashing-protection:go_default_library",
46 changes: 29 additions & 17 deletions validator/node/node.go
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ import (
"github.com/prysmaticlabs/prysm/validator/flags"
v1 "github.com/prysmaticlabs/prysm/validator/keymanager/v1"
v2 "github.com/prysmaticlabs/prysm/validator/keymanager/v2"
"github.com/prysmaticlabs/prysm/validator/keymanager/v2/direct"
"github.com/prysmaticlabs/prysm/validator/rpc"
"github.com/prysmaticlabs/prysm/validator/rpc/gateway"
slashing_protection "github.com/prysmaticlabs/prysm/validator/slashing-protection"
@@ -86,21 +87,30 @@ func NewValidatorClient(cliCtx *cli.Context) (*ValidatorClient, error) {
var keyManagerV1 v1.KeyManager
var keyManagerV2 v2.IKeymanager
if featureconfig.Get().EnableAccountsV2 {
// Read the wallet from the specified path.
wallet, err := accountsv2.OpenWallet(cliCtx)
if err != nil {
log.Fatalf("Could not open wallet: %v", err)
}
ValidatorClient.wallet = wallet
ctx := context.Background()
keyManagerV2, err = wallet.InitializeKeymanager(
cliCtx, false, /* skipMnemonicConfirm */
)
if err != nil {
log.Fatalf("Could not read existing keymanager for wallet: %v", err)
}
if err := wallet.LockConfigFile(ctx); err != nil {
log.Fatalf("Could not get a lock on wallet file. Please check if you have another validator instance running and using the same wallet: %v", err)
if cliCtx.IsSet(flags.InteropNumValidators.Name) {
numValidatorKeys := cliCtx.Uint64(flags.InteropNumValidators.Name)
offset := cliCtx.Uint64(flags.InteropStartIndex.Name)
keyManagerV2, err = direct.NewInteropKeymanager(cliCtx, offset, numValidatorKeys)
if err != nil {
log.Fatalf("Could not generate interop keys: %v", err)
}
} else {
// Read the wallet from the specified path.
wallet, err := accountsv2.OpenWallet(cliCtx)
if err != nil {
log.Fatalf("Could not open wallet: %v", err)
}
ValidatorClient.wallet = wallet
ctx := context.Background()
keyManagerV2, err = wallet.InitializeKeymanager(
cliCtx, false, /* skipMnemonicConfirm */
)
if err != nil {
log.Fatalf("Could not read existing keymanager for wallet: %v", err)
}
if err := wallet.LockConfigFile(ctx); err != nil {
log.Fatalf("Could not get a lock on wallet file. Please check if you have another validator instance running and using the same wallet: %v", err)
}
}
} else {
keyManagerV1, err = selectV1Keymanager(cliCtx)
@@ -212,8 +222,10 @@ func (s *ValidatorClient) Close() {

s.services.StopAll()
log.Info("Stopping Prysm validator")
if err := s.wallet.UnlockWalletConfigFile(); err != nil {
log.WithError(err).Errorf("Failed to unlock wallet config file.")
if !s.cliCtx.IsSet(flags.InteropNumValidators.Name) {
if err := s.wallet.UnlockWalletConfigFile(); err != nil {
log.WithError(err).Errorf("Failed to unlock wallet config file.")
}
}
close(s.stop)
}