Skip to content

Commit

Permalink
Change jdk release accordingly to system specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolmin committed Aug 2, 2023
1 parent 2cb0e06 commit bd30a73
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 24 deletions.
24 changes: 6 additions & 18 deletions commands/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,16 @@ func ListValidator(ctx *cli.Context) (err error) {
func ExitValidator(ctx *cli.Context) (err error) {
err = cfg.Read()
if err != nil {
return utils.Exit(fmt.Sprintf("❌ There was an error while reading config file: %v", err), 1)
}

var (
selectedValidator clients.ValidatorBinaryDependency
selectedConsensus clients.ClientBinaryDependency
)

switch cfg.Validator() {
case clients.PrysmValidator.Name():
selectedValidator = clients.PrysmValidator
selectedConsensus = clients.Prysm
case clients.LighthouseValidator.Name():
selectedValidator = clients.LighthouseValidator
selectedConsensus = clients.Lighthouse
return utils.Exit("❌ There was an error while reading config file", 1)
}

if !selectedConsensus.IsRunning() {
return utils.Exit("⚠️ Please make sure that your validator client is running before exiting", 1)
selectedValidator := cfg.Validator()
validatorClient, ok := clients.AllClients[selectedValidator].(clients.ValidatorBinaryDependency)
if !ok {
return utils.Exit(errors.SelectedClientsNotFound, 1)
}

err = selectedValidator.Exit(ctx)
err = validatorClient.Exit(ctx)
if err != nil {
return utils.Exit(fmt.Sprintf("❌ There was an error while exiting validator: %v", err), 1)
}
Expand Down
24 changes: 21 additions & 3 deletions dependencies/clients/teku.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (
tekuDepsFolder = "teku" // folder in which both teku and JDK are stored
tekuFolder = "teku" // folder in which teku is stored (in tekuDepsFolder)
jdkFolder = "jdk" // folder in which JDK is stored (in tekuDepsFolder)
jdkInstallURL = "https://download.java.net/java/GA/jdk20.0.2/6e380f22cbe7469fa75fb448bd903d8e/9/GPL/openjdk-20.0.2_linux-x64_bin.tar.gz"
jdkInstallURL = "https://download.java.net/java/GA/jdk20.0.2/6e380f22cbe7469fa75fb448bd903d8e/9/GPL/openjdk-20.0.2_|OS|-|ARCH|_bin.tar.gz"
)

type TekuClient struct {
Expand Down Expand Up @@ -92,7 +92,7 @@ func (t *TekuClient) Install(url string, isUpdate bool) (err error) {
return
}

err = setupJava(jdkInstallURL)
err = setupJava()
if err != nil {
return
}
Expand Down Expand Up @@ -242,9 +242,27 @@ func untarDir(dst string, t *tar.Reader) error {
return nil
}

func setupJava(jdkURL string) (err error) {
func setupJava() (err error) {
log.Info("⬇️ Downloading JDK...")

var systemOs, arch string
switch system.Os {
case system.Ubuntu:
systemOs = "linux"
case system.Macos:
systemOs = "macos"
}

switch system.Arch {
case "x86_64":
arch = "x64"
case "aarch64":
arch = "aarch64"
}

jdkURL := strings.Replace(jdkInstallURL, "|OS|", systemOs, -1)

Check failure on line 263 in dependencies/clients/teku.go

View workflow job for this annotation

GitHub Actions / Lint Test / lint_test

ineffectual assignment to jdkURL (ineffassign)
jdkURL = strings.Replace(jdkInstallURL, "|ARCH|", arch, -1)

err = installAndUntarFromURL(jdkURL)
if err != nil {
return err
Expand Down
31 changes: 28 additions & 3 deletions dependencies/clients/teku_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ func (t *TekuValidatorClient) Import(ctx *cli.Context) (err error) {

func (t *TekuValidatorClient) List(ctx *cli.Context) (err error) {
walletDir := ctx.String(flags.ValidatorWalletDirFlag)
if walletDir == "" {
return utils.Exit("❌ Wallet directory not provided - please provide a --validator-wallet-dir flag containing your keys directory", 1)
}

validatorIndex := 0

walkFunc := func(path string, d fs.DirEntry, entryError error) (err error) {
Expand Down Expand Up @@ -268,7 +272,28 @@ func (t *TekuValidatorClient) List(ctx *cli.Context) (err error) {
return
}

func (t *TekuValidatorClient) Exit(ctx *cli.Context) error {
//TODO implement me
panic("implement me")
func (t *TekuValidatorClient) Exit(ctx *cli.Context) (err error) {
wallet := ctx.String(flags.ValidatorWalletDirFlag)
if wallet == "" {
return utils.Exit("❌ Wallet directory not provided - please provide a --validator-wallet-dir flag containing your keys directory", 1)
}

if !utils.FileExists(wallet) {
return utils.Exit("❌ Wallet directory missing - please provide a --validator-wallet-dir flag containing your keys directory or use a network flag", 1)
}

args := []string{"voluntary-exit", "--validator-keys", fmt.Sprintf("%s:%s", wallet, wallet)}

exitCommand := exec.Command(fmt.Sprintf("./%s/%s/bin/teku", tekuDepsFolder, tekuFolder), args...)

exitCommand.Stdout = os.Stdout
exitCommand.Stderr = os.Stderr
exitCommand.Stdin = os.Stdin

err = exitCommand.Run()
if err != nil {
return utils.Exit(fmt.Sprintf("❌ There was an error while exiting validator: %v", err), 1)
}

return
}

0 comments on commit bd30a73

Please sign in to comment.