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

cmd/createcluster: add --num-validators flag #863

Merged
merged 2 commits into from
Jul 27, 2022
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
13 changes: 5 additions & 8 deletions cmd/createcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type clusterConfig struct {
Threshold int
WithdrawalAddr string
Network string
NumDVs int

SplitKeys bool
SplitKeysDir string
Expand Down Expand Up @@ -86,7 +87,7 @@ func bindClusterFlags(flags *pflag.FlagSet, config *clusterConfig) {
flags.StringVar(&config.WithdrawalAddr, "withdrawal-address", defaultWithdrawalAddr, "Ethereum address to receive the returned stake and accrued rewards.")
flags.StringVar(&config.Network, "network", defaultNetwork, "Ethereum network to create validators for. Options: mainnet, prater, kintsugi, kiln, gnosis.")
flags.BoolVar(&config.Clean, "clean", false, "Delete the cluster directory before generating it.")

flags.IntVar(&config.NumDVs, "num-validators", 1, "The number of distributed validators needed in the cluster.")
flags.BoolVar(&config.SplitKeys, "split-existing-keys", false, "Split an existing validator's private key into a set of distributed validator private key shares. Does not re-create deposit data for this key.")
flags.StringVar(&config.SplitKeysDir, "split-keys-dir", "", "Directory containing keys to split. Expects keys in keystore-*.json and passwords in keystore-*.txt. Requires --split-existing-keys.")
}
Expand All @@ -110,12 +111,8 @@ func runCreateCluster(w io.Writer, conf clusterConfig) error {
return err
}

// Currently, we assume that we create a cluster of ONLY 1 Distributed Validator
// TODO(xenowits): add flag to specify the number of distributed validators in a cluster
numDVs := 1

// Get root bls secrets
secrets, err := getKeys(conf, numDVs)
secrets, err := getKeys(conf)
if err != nil {
return err
}
Expand Down Expand Up @@ -253,7 +250,7 @@ func writeWarning(w io.Writer) {
}

// getKeys fetches secret keys for each distributed validator.
func getKeys(conf clusterConfig, numDVs int) ([]*bls_sig.SecretKey, error) {
func getKeys(conf clusterConfig) ([]*bls_sig.SecretKey, error) {
if conf.SplitKeys {
if conf.SplitKeysDir == "" {
return nil, errors.New("--split-keys-dir required when splitting keys")
Expand All @@ -263,7 +260,7 @@ func getKeys(conf clusterConfig, numDVs int) ([]*bls_sig.SecretKey, error) {
}

var secrets []*bls_sig.SecretKey
for i := 0; i < numDVs; i++ {
for i := 0; i < conf.NumDVs; i++ {
_, secret, err := tbls.KeygenWithSeed(rand.Reader)
if err != nil {
return nil, err
Expand Down