From fedd36fa5a055addd19893801974c12b6247b2d1 Mon Sep 17 00:00:00 2001 From: Dhruv Bodani Date: Tue, 17 May 2022 20:59:34 +0530 Subject: [PATCH] refactor create command --- cmd/cmd.go | 6 +-- cmd/createcluster.go | 21 +---------- cmd/createenr_internal_test.go | 2 +- cmd/genp2pkey.go | 67 ---------------------------------- 4 files changed, 3 insertions(+), 93 deletions(-) delete mode 100644 cmd/genp2pkey.go diff --git a/cmd/cmd.go b/cmd/cmd.go index 8b4c5236d..34d9640e8 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -43,17 +43,13 @@ func New() *cobra.Command { return newRootCmd( newVersionCmd(runVersionCmd), newEnrCmd(runNewENR), - // TODO(dhruv): remove genp2pkey command once charon-docker-compose and docs are updated - newGenP2PKeyCmd(runGenP2PKey), newRunCmd(app.Run), newBootnodeCmd(RunBootnode), - // TODO(dhruv): replace newCreateClusterCmdNew with newCreateClusterCmd once charon-docker-compose and docs are updated - newCreateClusterCmd(runCreateCluster), newDKGCmd(dkg.Run), newCreateCmd( newCreateDKGCmd(runCreateDKG), newCreateEnrCmd(runCreateEnrCmd), - newCreateClusterCmdNew(runCreateCluster), + newCreateClusterCmd(runCreateCluster), ), ) } diff --git a/cmd/createcluster.go b/cmd/createcluster.go index 6ed3c8c45..3be2cd911 100644 --- a/cmd/createcluster.go +++ b/cmd/createcluster.go @@ -98,25 +98,6 @@ type clusterConfig struct { func newCreateClusterCmd(runFunc func(io.Writer, clusterConfig) error) *cobra.Command { var conf clusterConfig - cmd := &cobra.Command{ - Use: "create-cluster", - Short: "Create a local charon cluster [DEPRECATED]", - Long: "Create a local charon cluster including validator keys, charon p2p keys, and a cluster manifest. [DEPRECATED]" + - "See flags for supported features.", - RunE: func(cmd *cobra.Command, args []string) error { - return runFunc(cmd.OutOrStdout(), conf) - }, - } - - bindClusterFlags(cmd.Flags(), &conf) - - return cmd -} - -// TODO(dhruv): replace newCreateClusterCmd with newCreateClusterCmdNew once charon-docker-compose are updated. -func newCreateClusterCmdNew(runFunc func(io.Writer, clusterConfig) error) *cobra.Command { - var conf clusterConfig - cmd := &cobra.Command{ Use: "cluster", Short: "Create private keys and configuration files needed to run a distributed validator cluster locally", @@ -372,7 +353,7 @@ func writeOutput(out io.Writer, conf clusterConfig) { _, _ = sb.WriteString("├─ run_cluster.sh\tConvenience script to run all nodes\n") _, _ = sb.WriteString("├─ teamocil.yml\t\tTeamocil config for splitting logs in tmux panes\n") } - _, _ = sb.WriteString("├─ node[0-3]/\t\tDirectory for each node\n") + _, _ = sb.WriteString(fmt.Sprintf("├─ node[0-%d]/\t\tDirectory for each node\n", conf.NumNodes-1)) _, _ = sb.WriteString("│ ├─ p2pkey\t\tP2P networking private key for node authentication\n") _, _ = sb.WriteString("│ ├─ keystore-*.json\tValidator private share key for duty signing\n") _, _ = sb.WriteString("│ ├─ keystore-*.txt\tKeystore password files for keystore-*.json\n") diff --git a/cmd/createenr_internal_test.go b/cmd/createenr_internal_test.go index 814b42eb5..146fd32e1 100644 --- a/cmd/createenr_internal_test.go +++ b/cmd/createenr_internal_test.go @@ -25,7 +25,7 @@ import ( "github.com/obolnetwork/charon/p2p" ) -func TestRunGenP2P(t *testing.T) { +func TestRunCreateEnr(t *testing.T) { temp, err := os.MkdirTemp("", "") require.NoError(t, err) diff --git a/cmd/genp2pkey.go b/cmd/genp2pkey.go deleted file mode 100644 index 255df7184..000000000 --- a/cmd/genp2pkey.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright © 2022 Obol Labs Inc. -// -// This program is free software: you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the Free -// Software Foundation, either version 3 of the License, or (at your option) -// any later version. -// -// This program is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -// more details. -// -// You should have received a copy of the GNU General Public License along with -// this program. If not, see . - -package cmd - -import ( - "fmt" - "io" - - "github.com/spf13/cobra" - - "github.com/obolnetwork/charon/app/errors" - "github.com/obolnetwork/charon/p2p" -) - -func newGenP2PKeyCmd(runFunc func(io.Writer, p2p.Config, string) error) *cobra.Command { - var ( - config p2p.Config - dataDir string - ) - - cmd := &cobra.Command{ - Use: "gen-p2pkey", - Short: "Generates a new p2p key [DEPRECATED]", - Long: "Generates a new p2p authentication key (ecdsa-k1) and saves it to the data directory [DEPRECATED]", - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - return runFunc(cmd.OutOrStdout(), config, dataDir) - }, - } - - bindDataDirFlag(cmd.Flags(), &dataDir) - bindP2PFlags(cmd.Flags(), &config) - - return cmd -} - -// runGenP2PKey stores a new p2pkey to disk and prints the ENR for the provided config. -func runGenP2PKey(w io.Writer, config p2p.Config, dataDir string) error { - key, err := p2p.NewSavedPrivKey(dataDir) - if err != nil { - return err - } - - localEnode, db, err := p2p.NewLocalEnode(config, key) - if err != nil { - return errors.Wrap(err, "failed to open peer DB") - } - defer db.Close() - - _, _ = fmt.Fprintf(w, "Created key: %s/p2pkey\n", dataDir) - _, _ = fmt.Fprintln(w, localEnode.Node().String()) - - return nil -}