From a187424954a3fdac8262ccc322bd9990ca9c746b Mon Sep 17 00:00:00 2001 From: kevinssgh Date: Tue, 15 Aug 2023 14:39:26 -0400 Subject: [PATCH] removed public-ip from zetaclient config and enforced env var to be set. --- cmd/zetaclientd/init.go | 3 --- cmd/zetaclientd/start.go | 7 +++++-- cmd/zetaclientd/start_utils.go | 15 ++++++--------- .../localnet/scripts/start-zetaclientd-genesis.sh | 8 ++++---- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/cmd/zetaclientd/init.go b/cmd/zetaclientd/init.go index d48722ee52..d6801350e4 100644 --- a/cmd/zetaclientd/init.go +++ b/cmd/zetaclientd/init.go @@ -18,7 +18,6 @@ var initArgs = initArguments{} type initArguments struct { peer string - publicIP string logFormat string logSampler bool preParamsPath string @@ -40,7 +39,6 @@ func init() { RootCmd.AddCommand(VersionCmd) InitCmd.Flags().StringVar(&initArgs.peer, "peer", "", "peer address, e.g. /dns/tss1/tcp/6668/ipfs/16Uiu2HAmACG5DtqmQsHtXg4G2sLS65ttv84e7MrL4kapkjfmhxAp") - InitCmd.Flags().StringVar(&initArgs.publicIP, "public-ip", "", "public ip address") InitCmd.Flags().StringVar(&initArgs.preParamsPath, "pre-params", "~/preParams.json", "pre-params file path") InitCmd.Flags().StringVar(&initArgs.chainID, "chain-id", "athens_7001-1", "chain id") InitCmd.Flags().StringVar(&initArgs.zetacoreURL, "zetacore-url", "127.0.0.1", "zetacore node URL") @@ -73,7 +71,6 @@ func Initialize(_ *cobra.Command, _ []string) error { //Populate new struct with cli arguments configData.Peer = initArgs.peer - configData.PublicIP = initArgs.publicIP configData.PreParamsPath = initArgs.preParamsPath configData.ChainID = initArgs.chainID configData.ZetaCoreURL = initArgs.zetacoreURL diff --git a/cmd/zetaclientd/start.go b/cmd/zetaclientd/start.go index 2ba51229a4..e94748c203 100644 --- a/cmd/zetaclientd/start.go +++ b/cmd/zetaclientd/start.go @@ -54,7 +54,10 @@ func start(_ *cobra.Command, _ []string) error { masterLogger := log.Logger startLogger := masterLogger.With().Str("module", "startup").Logger() - setMYIP(cfg, startLogger) + publicIP, err := getMYIP(startLogger) + if err != nil { + return err + } waitForZetaCore(cfg, startLogger) startLogger.Info().Msgf("ZetaCore is ready , Trying to connect to %s", cfg.Peer) @@ -116,7 +119,7 @@ func start(_ *cobra.Command, _ []string) error { } }() - telemetryServer.SetIPAddress(cfg.PublicIP) + telemetryServer.SetIPAddress(publicIP) tss, err := GenerateTss(masterLogger, cfg, zetaBridge, peers, priKey, telemetryServer) if err != nil { return err diff --git a/cmd/zetaclientd/start_utils.go b/cmd/zetaclientd/start_utils.go index c6ee5ad0c4..c630ff353d 100644 --- a/cmd/zetaclientd/start_utils.go +++ b/cmd/zetaclientd/start_utils.go @@ -12,16 +12,13 @@ import ( "time" ) -func setMYIP(cfg *config.Config, logger zerolog.Logger) { - if os.Getenv("MYIP") == "" { - if cfg.PublicIP == "" { - logger.Fatal().Msg("Please set MYIP environment variable or use the PublicIP flag") - } - err := os.Setenv("MYIP", cfg.PublicIP) - if err != nil { - logger.Fatal().Err(err).Msg("Error setting MYIP") - } +func getMYIP(logger zerolog.Logger) (string, error) { + ip := os.Getenv("MYIP") + if ip == "" { + logger.Fatal().Msg("Please set MYIP environment variable") + return "", errors.New("empty ip address") } + return ip, nil } func waitForZetaCore(configData *config.Config, logger zerolog.Logger) { diff --git a/contrib/localnet/scripts/start-zetaclientd-genesis.sh b/contrib/localnet/scripts/start-zetaclientd-genesis.sh index c3e7eaece8..90ce66679b 100755 --- a/contrib/localnet/scripts/start-zetaclientd-genesis.sh +++ b/contrib/localnet/scripts/start-zetaclientd-genesis.sh @@ -19,15 +19,15 @@ echo "Start zetaclientd" if [ $HOSTNAME == "zetaclient0" ] then rm ~/.tss/* - MYIP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) - zetaclientd init --zetacore-url zetacore0 --chain-id athens_101-1 --operator "$operatorAddress" --log-format=text --public-ip "$MYIP" + export MYIP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) + zetaclientd init --zetacore-url zetacore0 --chain-id athens_101-1 --operator "$operatorAddress" --log-format=text zetaclientd start else num=$(echo $HOSTNAME | tr -dc '0-9') node="zetacore$num" - MYIP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) + export MYIP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) SEED=$(curl --retry 10 --retry-delay 5 --retry-connrefused -s zetaclient0:8123/p2p) rm ~/.tss/* - zetaclientd init --peer /ip4/172.20.0.21/tcp/6668/p2p/"$SEED" --zetacore-url "$node" --chain-id athens_101-1 --operator "$operatorAddress" --log-format=text --public-ip "$MYIP" --log-level 0 + zetaclientd init --peer /ip4/172.20.0.21/tcp/6668/p2p/"$SEED" --zetacore-url "$node" --chain-id athens_101-1 --operator "$operatorAddress" --log-format=text --log-level 0 zetaclientd start fi