Skip to content

Commit

Permalink
refactor(e2e): use seed address book rather than bootstrap peer
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera committed Dec 11, 2024
1 parent 376b714 commit 96786f0
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 7 deletions.
97 changes: 97 additions & 0 deletions cmd/zetae2e/get_zetaclient_bootstrap.go
Original file line number Diff line number Diff line change
@@ -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())

Check failure on line 68 in cmd/zetae2e/get_zetaclient_bootstrap.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var peerId should be peerID (revive)
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/<ip> and doesn't tolerate /dns4/<hostname>
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
}
1 change: 1 addition & 0 deletions cmd/zetae2e/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func NewRootCmd() *cobra.Command {
NewStressTestCmd(),
NewInitCmd(),
NewSetupBitcoinCmd(),
NewGetZetaclientBootstrap(),
)

return cmd
Expand Down
11 changes: 4 additions & 7 deletions contrib/localnet/scripts/start-zetaclientd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]]
Expand All @@ -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}"
Expand Down

0 comments on commit 96786f0

Please sign in to comment.