Skip to content

Commit

Permalink
removed public-ip from zetaclient config and enforced env var to be set.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinssgh committed Aug 15, 2023
1 parent c7a9bff commit a187424
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
3 changes: 0 additions & 3 deletions cmd/zetaclientd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ var initArgs = initArguments{}

type initArguments struct {
peer string
publicIP string
logFormat string
logSampler bool
preParamsPath string
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
15 changes: 6 additions & 9 deletions cmd/zetaclientd/start_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions contrib/localnet/scripts/start-zetaclientd-genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a187424

Please sign in to comment.