From 73da862155fee559d1b5150cbbbac00599b2c132 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Tue, 10 Dec 2024 21:00:42 -0800 Subject: [PATCH 1/4] refactor(e2e): use seed address book rather than bootstrap peer --- cmd/zetae2e/get_zetaclient_bootstrap.go | 97 +++++++++++++++++++ cmd/zetae2e/root.go | 1 + contrib/localnet/scripts/start-zetaclientd.sh | 11 +-- 3 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 cmd/zetae2e/get_zetaclient_bootstrap.go diff --git a/cmd/zetae2e/get_zetaclient_bootstrap.go b/cmd/zetae2e/get_zetaclient_bootstrap.go new file mode 100644 index 0000000000..2919c41b06 --- /dev/null +++ b/cmd/zetae2e/get_zetaclient_bootstrap.go @@ -0,0 +1,97 @@ +package main + +import ( + "fmt" + "net" + "strings" + + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/spf13/cobra" + "github.com/zeta-chain/node/pkg/rpc" + "github.com/zeta-chain/node/pkg/sdkconfig" + observertypes "github.com/zeta-chain/node/x/observer/types" + "gitlab.com/thorchain/tss/go-tss/conversion" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" +) + +func NewGetZetaclientBootstrap() *cobra.Command { + var ConfigureZetaclientBootstrapCmd = &cobra.Command{ + Use: "get-zetaclient-bootstrap", + Short: "get bootstrap address book entries for zetaclient", + RunE: getZetaclientBootstrap, + } + + return ConfigureZetaclientBootstrapCmd +} + +func getZetaclientBootstrap(cmd *cobra.Command, _ []string) error { + sdkconfig.SetDefault(true) + rpcClient, err := rpc.NewGRPCClients( + "zetacore0:9090", + grpc.WithTransportCredentials(insecure.NewCredentials()), + grpc.WithBlock(), + ) + if err != nil { + return fmt.Errorf("get zetacore rpc client: %w", err) + } + var res *observertypes.QueryAllNodeAccountResponse + for { + res, err = rpcClient.Observer.NodeAccountAll(cmd.Context(), &observertypes.QueryAllNodeAccountRequest{}) + if err != nil { + return fmt.Errorf("get all node accounts: %w", err) + } + if len(res.NodeAccount) > 1 { + break + } + fmt.Fprintln(cmd.OutOrStderr(), "waiting for node accounts") + } + + // note that we deliberately do not filter ourselfs/localhost + // to mirror the production configuration + for _, account := range res.NodeAccount { + accAddr, err := sdk.AccAddressFromBech32(account.Operator) + if err != nil { + return err + } + valAddr := sdk.ValAddress(accAddr).String() + validatorRes, err := rpcClient.Staking.Validator(cmd.Context(), &stakingtypes.QueryValidatorRequest{ + ValidatorAddr: valAddr, + }) + if err != nil { + return fmt.Errorf("getting validator info for %s: %w", account.Operator, err) + } + // in localnet, moniker is also the hostname + moniker := validatorRes.Validator.Description.Moniker + + peerId, err := conversion.Bech32PubkeyToPeerID(account.GranteePubkey.Secp256k1.String()) + if err != nil { + return fmt.Errorf("conferting pubkey to peerid: %w", err) + } + zetaclientHostname := strings.ReplaceAll(moniker, "zetacore", "zetaclient") + + // resolve the hostname + // something in libp2p/go-tss requires /ip4/ and doesn't tolerate /dns4/ + ipAddresses, err := net.LookupIP(zetaclientHostname) + if err != nil { + return fmt.Errorf("failed to resolve hostname %s: %w", zetaclientHostname, err) + } + if len(ipAddresses) == 0 { + return fmt.Errorf("no IP addresses found for hostname %s", zetaclientHostname) + } + ipv4Address := "" + for _, ip := range ipAddresses { + if ip.To4() != nil { + ipv4Address = ip.String() + break + } + } + if ipv4Address == "" { + return fmt.Errorf("no IPv4 address found for hostname %s", zetaclientHostname) + } + fmt.Printf("/ip4/%s/tcp/6668/p2p/%s\n", ipv4Address, peerId.String()) + } + + return nil +} diff --git a/cmd/zetae2e/root.go b/cmd/zetae2e/root.go index 28b4b0c003..d885b532e2 100644 --- a/cmd/zetae2e/root.go +++ b/cmd/zetae2e/root.go @@ -29,6 +29,7 @@ func NewRootCmd() *cobra.Command { NewStressTestCmd(), NewInitCmd(), NewSetupBitcoinCmd(), + NewGetZetaclientBootstrap(), ) return cmd diff --git a/contrib/localnet/scripts/start-zetaclientd.sh b/contrib/localnet/scripts/start-zetaclientd.sh index 93fa5c2af6..6e909631af 100755 --- a/contrib/localnet/scripts/start-zetaclientd.sh +++ b/contrib/localnet/scripts/start-zetaclientd.sh @@ -68,6 +68,9 @@ echo "operatorAddress: $operatorAddress" RELAYER_KEY_PATH="$HOME/.zetacored/relayer-keys" mkdir -p "${RELAYER_KEY_PATH}" +mkdir -p "$HOME/.tss/" +zetae2e get-zetaclient-bootstrap > "$HOME/.tss/address_book.seed" + echo "Start zetaclientd" # skip initialization if the config file already exists (zetaclientd init has already been run) if [[ $HOSTNAME == "zetaclient0" && ! -f ~/.zetacored/config/zetaclient_config.json ]] @@ -90,13 +93,7 @@ if [[ $HOSTNAME != "zetaclient0" && ! -f ~/.zetacored/config/zetaclient_config.j then num=$(echo $HOSTNAME | tr -dc '0-9') node="zetacore$num" - MYIP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) - SEED="" - while [ -z "$SEED" ] - do - SEED=$(curl --retry 30 --retry-delay 1 --max-time 1 --retry-connrefused -s zetaclient0:8123/p2p) - done - 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 1 --keyring-backend "$BACKEND" --pre-params "$PREPARAMS_PATH" + zetaclientd init --zetacore-url "$node" --chain-id athens_101-1 --operator "$operatorAddress" --log-format=text --public-ip "$MYIP" --log-level 1 --keyring-backend "$BACKEND" --pre-params "$PREPARAMS_PATH" # import relayer private key for zetaclient{$num} import_relayer_key "${num}" From ab29a765640cffd4b31b75ef20051a6f6f90051f Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Wed, 11 Dec 2024 09:07:44 -0800 Subject: [PATCH 2/4] review updates --- cmd/zetae2e/get_zetaclient_bootstrap.go | 13 +++++++------ contrib/localnet/scripts/start-zetaclientd.sh | 3 ++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cmd/zetae2e/get_zetaclient_bootstrap.go b/cmd/zetae2e/get_zetaclient_bootstrap.go index 2919c41b06..97139356f5 100644 --- a/cmd/zetae2e/get_zetaclient_bootstrap.go +++ b/cmd/zetae2e/get_zetaclient_bootstrap.go @@ -8,12 +8,13 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/spf13/cobra" - "github.com/zeta-chain/node/pkg/rpc" - "github.com/zeta-chain/node/pkg/sdkconfig" - observertypes "github.com/zeta-chain/node/x/observer/types" "gitlab.com/thorchain/tss/go-tss/conversion" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" + + "github.com/zeta-chain/node/pkg/rpc" + "github.com/zeta-chain/node/pkg/sdkconfig" + observertypes "github.com/zeta-chain/node/x/observer/types" ) func NewGetZetaclientBootstrap() *cobra.Command { @@ -65,9 +66,9 @@ func getZetaclientBootstrap(cmd *cobra.Command, _ []string) error { // in localnet, moniker is also the hostname moniker := validatorRes.Validator.Description.Moniker - peerId, err := conversion.Bech32PubkeyToPeerID(account.GranteePubkey.Secp256k1.String()) + peerID, err := conversion.Bech32PubkeyToPeerID(account.GranteePubkey.Secp256k1.String()) if err != nil { - return fmt.Errorf("conferting pubkey to peerid: %w", err) + return fmt.Errorf("converting pubkey to peerID: %w", err) } zetaclientHostname := strings.ReplaceAll(moniker, "zetacore", "zetaclient") @@ -90,7 +91,7 @@ func getZetaclientBootstrap(cmd *cobra.Command, _ []string) error { if ipv4Address == "" { return fmt.Errorf("no IPv4 address found for hostname %s", zetaclientHostname) } - fmt.Printf("/ip4/%s/tcp/6668/p2p/%s\n", ipv4Address, peerId.String()) + fmt.Printf("/ip4/%s/tcp/6668/p2p/%s\n", ipv4Address, peerID.String()) } return nil diff --git a/contrib/localnet/scripts/start-zetaclientd.sh b/contrib/localnet/scripts/start-zetaclientd.sh index 6e909631af..fd4c55249b 100755 --- a/contrib/localnet/scripts/start-zetaclientd.sh +++ b/contrib/localnet/scripts/start-zetaclientd.sh @@ -71,11 +71,12 @@ mkdir -p "${RELAYER_KEY_PATH}" mkdir -p "$HOME/.tss/" zetae2e get-zetaclient-bootstrap > "$HOME/.tss/address_book.seed" +MYIP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) + echo "Start zetaclientd" # skip initialization if the config file already exists (zetaclientd init has already been run) if [[ $HOSTNAME == "zetaclient0" && ! -f ~/.zetacored/config/zetaclient_config.json ]] then - 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" --keyring-backend "$BACKEND" --pre-params "$PREPARAMS_PATH" # import relayer private key for zetaclient0 From 5b33f0430e3c30e292a416f8387b491e02c9bc32 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Wed, 11 Dec 2024 09:48:05 -0800 Subject: [PATCH 3/4] move to local --- cmd/zetae2e/{ => local}/get_zetaclient_bootstrap.go | 10 ++++++++-- cmd/zetae2e/local/local.go | 2 ++ cmd/zetae2e/root.go | 1 - contrib/localnet/scripts/start-zetaclientd.sh | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) rename cmd/zetae2e/{ => local}/get_zetaclient_bootstrap.go (93%) diff --git a/cmd/zetae2e/get_zetaclient_bootstrap.go b/cmd/zetae2e/local/get_zetaclient_bootstrap.go similarity index 93% rename from cmd/zetae2e/get_zetaclient_bootstrap.go rename to cmd/zetae2e/local/get_zetaclient_bootstrap.go index 97139356f5..7e346448b4 100644 --- a/cmd/zetae2e/get_zetaclient_bootstrap.go +++ b/cmd/zetae2e/local/get_zetaclient_bootstrap.go @@ -1,4 +1,4 @@ -package main +package local import ( "fmt" @@ -17,6 +17,8 @@ import ( observertypes "github.com/zeta-chain/node/x/observer/types" ) +const grpcURLFlag = "grpc-url" + func NewGetZetaclientBootstrap() *cobra.Command { var ConfigureZetaclientBootstrapCmd = &cobra.Command{ Use: "get-zetaclient-bootstrap", @@ -24,13 +26,17 @@ func NewGetZetaclientBootstrap() *cobra.Command { RunE: getZetaclientBootstrap, } + ConfigureZetaclientBootstrapCmd.Flags(). + String(grpcURLFlag, "zetacore0:9090", "--grpc-url zetacore0:9090") + return ConfigureZetaclientBootstrapCmd } func getZetaclientBootstrap(cmd *cobra.Command, _ []string) error { sdkconfig.SetDefault(true) + grpcURL, _ := cmd.Flags().GetString(grpcURLFlag) rpcClient, err := rpc.NewGRPCClients( - "zetacore0:9090", + grpcURL, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock(), ) diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index 0ebb6244f9..e625b4174a 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -83,6 +83,8 @@ func NewLocalCmd() *cobra.Command { cmd.Flags(). Bool(flagUpgradeContracts, false, "set to true to upgrade Gateways and ERC20Custody contracts during setup for ZEVM and EVM") + cmd.AddCommand(NewGetZetaclientBootstrap()) + return cmd } diff --git a/cmd/zetae2e/root.go b/cmd/zetae2e/root.go index d885b532e2..28b4b0c003 100644 --- a/cmd/zetae2e/root.go +++ b/cmd/zetae2e/root.go @@ -29,7 +29,6 @@ func NewRootCmd() *cobra.Command { NewStressTestCmd(), NewInitCmd(), NewSetupBitcoinCmd(), - NewGetZetaclientBootstrap(), ) return cmd diff --git a/contrib/localnet/scripts/start-zetaclientd.sh b/contrib/localnet/scripts/start-zetaclientd.sh index fd4c55249b..c994f1d2df 100755 --- a/contrib/localnet/scripts/start-zetaclientd.sh +++ b/contrib/localnet/scripts/start-zetaclientd.sh @@ -69,7 +69,7 @@ RELAYER_KEY_PATH="$HOME/.zetacored/relayer-keys" mkdir -p "${RELAYER_KEY_PATH}" mkdir -p "$HOME/.tss/" -zetae2e get-zetaclient-bootstrap > "$HOME/.tss/address_book.seed" +zetae2e local get-zetaclient-bootstrap > "$HOME/.tss/address_book.seed" MYIP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) From 7b43854f27763623e77ca92c2a1b2295127db020 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Thu, 12 Dec 2024 08:43:00 -0800 Subject: [PATCH 4/4] feedback --- cmd/zetae2e/local/get_zetaclient_bootstrap.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/zetae2e/local/get_zetaclient_bootstrap.go b/cmd/zetae2e/local/get_zetaclient_bootstrap.go index 7e346448b4..16cbdcf10c 100644 --- a/cmd/zetae2e/local/get_zetaclient_bootstrap.go +++ b/cmd/zetae2e/local/get_zetaclient_bootstrap.go @@ -20,16 +20,16 @@ import ( const grpcURLFlag = "grpc-url" func NewGetZetaclientBootstrap() *cobra.Command { - var ConfigureZetaclientBootstrapCmd = &cobra.Command{ + var cmd = &cobra.Command{ Use: "get-zetaclient-bootstrap", Short: "get bootstrap address book entries for zetaclient", RunE: getZetaclientBootstrap, } - ConfigureZetaclientBootstrapCmd.Flags(). + cmd.Flags(). String(grpcURLFlag, "zetacore0:9090", "--grpc-url zetacore0:9090") - return ConfigureZetaclientBootstrapCmd + return cmd } func getZetaclientBootstrap(cmd *cobra.Command, _ []string) error {