From e9a22a51c48b0ba3c2886a730a9e5dd9de480af9 Mon Sep 17 00:00:00 2001 From: Carlos Bermudez Porto Date: Thu, 20 Jul 2023 16:30:35 -0400 Subject: [PATCH 1/7] feat: create custom class for client types --- cli/actions/generation_test.go | 8 +-- cli/cli.go | 2 +- cli/generate.go | 6 +-- cli/listClients.go | 20 +++++--- internal/pkg/clients/clients.go | 8 +-- internal/pkg/clients/clients_test.go | 74 ++++++++++++++-------------- internal/pkg/clients/init.go | 8 +-- internal/pkg/clients/types.go | 27 ++++++++-- 8 files changed, 91 insertions(+), 62 deletions(-) diff --git a/cli/actions/generation_test.go b/cli/actions/generation_test.go index 7af59de28..eb4d165bf 100644 --- a/cli/actions/generation_test.go +++ b/cli/actions/generation_test.go @@ -444,11 +444,11 @@ func TestFolderCreationOnCompose(t *testing.T) { log.SetOutput(io.Discard) samplePath := t.TempDir() + "test" c := clients.ClientInfo{Network: "mainnet"} - clientsMap, _ := c.Clients([]string{"execution", "consensus"}) + clientsMap, _ := c.Clients([]clients.ClientType{clients.ExecutionClientType, clients.ConsensusClientType}) sampleData := generate.GenData{ - ExecutionClient: clientsMap["execution"]["nethermind"], - ConsensusClient: clientsMap["consensus"]["lighthouse"], - ValidatorClient: clientsMap["consensus"]["lighthouse"], + ExecutionClient: clientsMap[clients.ExecutionClientType]["nethermind"], + ConsensusClient: clientsMap[clients.ConsensusClientType]["lighthouse"], + ValidatorClient: clientsMap[clients.ConsensusClientType]["lighthouse"], Services: []string{"execution", "consensus", "validator"}, Network: "mainnet", JWTSecretPath: samplePath, diff --git a/cli/cli.go b/cli/cli.go index 4a9096e11..f1c20a118 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -659,7 +659,7 @@ func selectExecutionClient(p ui.Prompter, o *CliCmdOptions) (err error) { } o.genData.ExecutionClient = &clients.Client{ Name: selectedExecutionClient, - Type: "execution", + Type: clients.ExecutionClientType, } o.genData.ExecutionClient.SetImageOrDefault("") // Patch Geth image if network needs TTD to be set diff --git a/cli/generate.go b/cli/generate.go index 5c30a866c..73efc7f74 100644 --- a/cli/generate.go +++ b/cli/generate.go @@ -406,11 +406,11 @@ func valClients(allClients clients.OrderedClients, flags *GenCmdFlags, services }, err } -func onlyClients(services []string) []string { - newServices := make([]string, 0) +func onlyClients(services []string) []clients.ClientType { + newServices := make([]clients.ClientType, 0) for _, service := range services { if service != mevBoost { - newServices = append(newServices, service) + newServices = append(newServices, clients.ClientType(service)) } } return newServices diff --git a/cli/listClients.go b/cli/listClients.go index e1e364fcc..31e140dc7 100644 --- a/cli/listClients.go +++ b/cli/listClients.go @@ -74,22 +74,30 @@ Table data b. error Error if any */ -func buildData(getClients func(string) ([]string, error)) (*ui.ListClientsTable, error) { - executionClients, err := getClients("execution") +func buildData(getClients func(clients.ClientType) ([]string, error)) (*ui.ListClientsTable, error) { + executionClients, err := getClients(clients.ExecutionClientType) if err != nil { return nil, err } - consensusClients, err := getClients("consensus") + consensusClients, err := getClients(clients.ConsensusClientType) if err != nil { return nil, err } - validatorClients, err := getClients("validator") + validatorClients, err := getClients(clients.ExecutionClientType) if err != nil { return nil, err } return &ui.ListClientsTable{ - ClientTypes: []string{"Execution", "Consensus", "Validator"}, - Clients: [][]string{executionClients, consensusClients, validatorClients}, + ClientTypes: []string{ + clients.ExecutionClientType.ToTitle(), + clients.ConsensusClientType.ToTitle(), + clients.ValidatorClientType.ToTitle(), + }, + Clients: [][]string{ + executionClients, + consensusClients, + validatorClients, + }, }, nil } diff --git a/internal/pkg/clients/clients.go b/internal/pkg/clients/clients.go index b1634a953..ec1b75ef4 100644 --- a/internal/pkg/clients/clients.go +++ b/internal/pkg/clients/clients.go @@ -44,8 +44,8 @@ List of supported clients names of type b. error Error if any */ -func (c ClientInfo) SupportedClients(clientType string) (clientsNames []string, err error) { - files, err := templates.Envs.ReadDir(strings.Join([]string{"envs", c.Network, clientType}, "/")) +func (c ClientInfo) SupportedClients(clientType ClientType) (clientsNames []string, err error) { + files, err := templates.Envs.ReadDir(strings.Join([]string{"envs", c.Network, clientType.ToString()}, "/")) if err != nil { return } @@ -80,7 +80,7 @@ Map of : map of : Client b. []error List of errors */ -func (c ClientInfo) Clients(clientTypes []string) (clients OrderedClients, errs []error) { +func (c ClientInfo) Clients(clientTypes []ClientType) (clients OrderedClients, errs []error) { clients = make(OrderedClients) for _, clientType := range clientTypes { @@ -113,7 +113,7 @@ returns :- a. error Error if client is not supported or configured */ -func ValidateClient(client *Client, currentType string) error { +func ValidateClient(client *Client, currentType ClientType) error { if client == nil { return nil } diff --git a/internal/pkg/clients/clients_test.go b/internal/pkg/clients/clients_test.go index fbd185682..3502b9cfc 100644 --- a/internal/pkg/clients/clients_test.go +++ b/internal/pkg/clients/clients_test.go @@ -25,16 +25,16 @@ import ( func TestSupportedClients(t *testing.T) { inputs := [...]struct { - clientType string + clientType ClientType network string want []string isErr bool }{ - {"execution", "gnosis", []string{"nethermind"}, false}, - {"consensus", "gnosis", utils.Filter(AllClients["consensus"], func(c string) bool { return c != "prysm" }), false}, - {"execution", "mainnet", AllClients["execution"], false}, - {"consensus", "mainnet", AllClients["consensus"], false}, - {"validator", "mainnet", AllClients["validator"], false}, + {ExecutionClientType, "gnosis", []string{"nethermind"}, false}, + {ConsensusClientType, "gnosis", utils.Filter(AllClients[ConsensusClientType], func(c string) bool { return c != "prysm" }), false}, + {ExecutionClientType, "mainnet", AllClients[ExecutionClientType], false}, + {ConsensusClientType, "mainnet", AllClients[ConsensusClientType], false}, + {ValidatorClientType, "mainnet", AllClients[ValidatorClientType], false}, {"random", "mainnet", []string{}, true}, } @@ -55,8 +55,8 @@ func TestSupportedClients(t *testing.T) { } type clientsTestCase struct { - configClientsTypes map[string][]string - query []string + configClientsTypes map[ClientType][]string + query []ClientType network string isErr bool } @@ -90,51 +90,51 @@ Loop1: func TestClients(t *testing.T) { inputs := [...]clientsTestCase{ { - map[string][]string{ - "consensus": {"lighthouse", "prysm", "teku", "lodestar"}, - "validator": {"lighthouse", "prysm", "teku", "lodestar"}, - "execution": {"nethermind", "geth", "besu", "erigon"}, + map[ClientType][]string{ + ConsensusClientType: {"lighthouse", "prysm", "teku", "lodestar"}, + ValidatorClientType: {"lighthouse", "prysm", "teku", "lodestar"}, + ExecutionClientType: {"nethermind", "geth", "besu", "erigon"}, }, - []string{"consensus"}, + []ClientType{ConsensusClientType}, "mainnet", false, }, { - map[string][]string{ - "consensus": {"lighthouse"}, - "execution": {"nethermind"}, - "validator": {"lighthouse"}, + map[ClientType][]string{ + ConsensusClientType: {"lighthouse"}, + ExecutionClientType: {"nethermind"}, + ValidatorClientType: {"lighthouse"}, }, - []string{"other"}, + []ClientType{"other"}, "mainnet", true, }, { - map[string][]string{ - "validator": {"lighthouse", "prysm", "teku", "lodestar"}, - "execution": {"nethermind", "geth", "besu", "erigon"}, + map[ClientType][]string{ + ValidatorClientType: {"lighthouse", "prysm", "teku", "lodestar"}, + ExecutionClientType: {"nethermind", "geth", "besu", "erigon"}, }, - []string{"execution", "validator"}, + []ClientType{ExecutionClientType, ValidatorClientType}, "mainnet", false, }, { - map[string][]string{ - "validator": {"lighthouse", "prysm", "teku", "lodestar"}, - "consensus": {"lighthouse", "prysm", "teku", "lodestar"}, - "execution": {"nethermind", "geth", "besu", "erigon"}, + map[ClientType][]string{ + ValidatorClientType: {"lighthouse", "prysm", "teku", "lodestar"}, + ConsensusClientType: {"lighthouse", "prysm", "teku", "lodestar"}, + ExecutionClientType: {"nethermind", "geth", "besu", "erigon"}, }, - []string{"consensus", "other"}, + []ClientType{ConsensusClientType, "other"}, "mainnet", true, }, { - map[string][]string{ - "validator": {"lighthouse", "teku", "lodestar"}, - "consensus": {"lighthouse", "teku", "lodestar"}, - "execution": {"nethermind"}, + map[ClientType][]string{ + ValidatorClientType: {"lighthouse", "teku", "lodestar"}, + ConsensusClientType: {"lighthouse", "teku", "lodestar"}, + ExecutionClientType: {"nethermind"}, }, - []string{"consensus", "execution", "validator"}, + []ClientType{ConsensusClientType, ExecutionClientType, ValidatorClientType}, "gnosis", false, }, @@ -161,7 +161,7 @@ func TestClients(t *testing.T) { func TestValidateClient(t *testing.T) { inputs := [...]struct { client Client - clientType string + clientType ClientType isErr bool }{ { @@ -172,19 +172,19 @@ func TestValidateClient(t *testing.T) { { client: Client{ Name: "nethermind", - Type: "execution", + Type: ExecutionClientType, Supported: true, }, - clientType: "execution", + clientType: ExecutionClientType, isErr: false, }, { client: Client{ Name: "nethermind", - Type: "execution", + Type: ExecutionClientType, Supported: false, }, - clientType: "execution", + clientType: ExecutionClientType, isErr: true, }, } diff --git a/internal/pkg/clients/init.go b/internal/pkg/clients/init.go index e5e06ea77..44c0f4c1f 100644 --- a/internal/pkg/clients/init.go +++ b/internal/pkg/clients/init.go @@ -15,20 +15,20 @@ limitations under the License. */ package clients -var AllClients map[string][]string = map[string][]string{ - "execution": { +var AllClients map[ClientType][]string = map[ClientType][]string{ + ExecutionClientType: { "nethermind", "geth", "erigon", "besu", }, - "consensus": { + ConsensusClientType: { "lighthouse", "prysm", "teku", "lodestar", }, - "validator": { + ValidatorClientType: { "lighthouse", "prysm", "teku", diff --git a/internal/pkg/clients/types.go b/internal/pkg/clients/types.go index edbc58830..f4183a8b6 100644 --- a/internal/pkg/clients/types.go +++ b/internal/pkg/clients/types.go @@ -15,12 +15,33 @@ limitations under the License. */ package clients -import "github.com/NethermindEth/sedge/configs" +import ( + "github.com/NethermindEth/sedge/configs" + "golang.org/x/text/cases" + "golang.org/x/text/language" +) + +type ClientType string + +func (ct ClientType) ToString() string { + return string(ct) +} + +func (ct ClientType) ToTitle() string { + caser := cases.Title(language.English) + return caser.String(ct.ToString()) +} + +const ( + ExecutionClientType = ClientType("execution") + ConsensusClientType = ClientType("consensus") + ValidatorClientType = ClientType("validator") +) // Client : Struct Represent a client like geth, prysm, etc type Client struct { Name string - Type string + Type ClientType Image string Endpoint string Supported bool @@ -92,4 +113,4 @@ type Clients struct { type ClientMap map[string]*Client -type OrderedClients map[string]ClientMap +type OrderedClients map[ClientType]ClientMap From dab8b607a6343ba7906192a2e5b448f5de750bf2 Mon Sep 17 00:00:00 2001 From: Carlos Bermudez Porto Date: Thu, 20 Jul 2023 17:11:07 -0400 Subject: [PATCH 2/7] fix: issue when generating sedge data without sudo --- cli/actions/generation.go | 32 +++++++++++++++++++ cli/actions/generation_test.go | 27 ++++++++++++++-- .../services/merge/consensus/lighthouse.tmpl | 3 +- .../services/merge/consensus/lodestar.tmpl | 3 +- templates/services/merge/consensus/prysm.tmpl | 3 +- templates/services/merge/execution/besu.tmpl | 3 +- .../services/merge/execution/erigon.tmpl | 3 +- templates/services/merge/execution/geth.tmpl | 3 +- .../services/merge/execution/nethermind.tmpl | 3 +- .../services/merge/validator/lighthouse.tmpl | 3 +- .../services/merge/validator/lodestar.tmpl | 3 +- templates/services/merge/validator/prysm.tmpl | 3 +- 12 files changed, 77 insertions(+), 12 deletions(-) diff --git a/cli/actions/generation.go b/cli/actions/generation.go index c5357663a..4fa29849b 100644 --- a/cli/actions/generation.go +++ b/cli/actions/generation.go @@ -86,5 +86,37 @@ func (s *sedgeActions) Generate(options GenerateOptions) (generate.GenData, erro } log.Info(configs.CleanedGeneratedFiles) + // create datadir folders + datadirs := []struct { + path string + createIf bool + }{ + { + path: filepath.Join(options.GenerationPath, configs.ExecutionDir), + createIf: options.GenerationData.ExecutionClient != nil && + options.GenerationData.ExecutionClient.Supported, + }, + { + path: filepath.Join(options.GenerationPath, configs.ConsensusDir), + createIf: options.GenerationData.ConsensusClient != nil && + options.GenerationData.ConsensusClient.Supported, + }, + { + path: filepath.Join(options.GenerationPath, configs.ValidatorDir), + createIf: options.GenerationData.ValidatorClient != nil && + options.GenerationData.ValidatorClient.Supported, + }, + } + for _, datadir := range datadirs { + if datadir.createIf { + if _, err := os.Stat(datadir.path); os.IsNotExist(err) { + err = os.MkdirAll(datadir.path, 0o755) + if err != nil { + return options.GenerationData, err + } + } + } + } + return options.GenerationData, nil } diff --git a/cli/actions/generation_test.go b/cli/actions/generation_test.go index eb4d165bf..ce203fb31 100644 --- a/cli/actions/generation_test.go +++ b/cli/actions/generation_test.go @@ -263,16 +263,26 @@ func TestGenerateDockerCompose(t *testing.T) { // Always set the JWT secret path tc.genData.JWTSecretPath = samplePath + datadirs := make([]datadirsValidation, 0) // Setup client images if tc.genData.ExecutionClient != nil { tc.genData.ExecutionClient.SetImageOrDefault("") + datadirs = append(datadirs, datadirsValidation{path: configs.ExecutionDir, shouldExist: true}) + } else { + datadirs = append(datadirs, datadirsValidation{path: configs.ExecutionDir, shouldExist: false}) } if tc.genData.ConsensusClient != nil { tc.genData.ConsensusClient.SetImageOrDefault("") + datadirs = append(datadirs, datadirsValidation{path: configs.ConsensusDir, shouldExist: true}) + } else { + datadirs = append(datadirs, datadirsValidation{path: configs.ConsensusDir, shouldExist: false}) } if tc.genData.ValidatorClient != nil { tc.genData.ValidatorClient.SetImageOrDefault("") + datadirs = append(datadirs, datadirsValidation{path: configs.ValidatorDir, shouldExist: true}) + } else { + datadirs = append(datadirs, datadirsValidation{path: configs.ValidatorDir, shouldExist: false}) } _, err := sedgeAction.Generate(actions.GenerateOptions{ @@ -284,7 +294,7 @@ func TestGenerateDockerCompose(t *testing.T) { return } - validateGeneration(t, samplePath) + validateGeneration(t, samplePath, datadirs...) cmpData, err := generate.ParseCompose(filepath.Join(samplePath, configs.DefaultDockerComposeScriptName)) require.Nil(t, err) envData, err := utils.ParseEnv(filepath.Join(samplePath, configs.DefaultEnvFileName)) @@ -475,7 +485,12 @@ func TestFolderCreationOnCompose(t *testing.T) { assert.NoDirExists(t, samplePath) } -func validateGeneration(t *testing.T, samplePath string) { +type datadirsValidation struct { + path string + shouldExist bool +} + +func validateGeneration(t *testing.T, samplePath string, datadirs ...datadirsValidation) { t.Helper() // Check that the folder was created @@ -484,6 +499,14 @@ func validateGeneration(t *testing.T, samplePath string) { assert.FileExists(t, filepath.Join(samplePath, configs.DefaultDockerComposeScriptName)) // Check that .env file exist assert.FileExists(t, filepath.Join(samplePath, configs.DefaultEnvFileName)) + // Check datadirs are correclty generated + for _, datadir := range datadirs { + if datadir.shouldExist { + assert.DirExists(t, filepath.Join(samplePath, datadir.path)) + } else { + assert.NoDirExists(t, filepath.Join(samplePath, datadir.path)) + } + } // Check compose file correctness err := utils.ValidateCompose(filepath.Join(samplePath, configs.DefaultDockerComposeScriptName)) require.NoError(t, err, "generated compose file is not valid") diff --git a/templates/services/merge/consensus/lighthouse.tmpl b/templates/services/merge/consensus/lighthouse.tmpl index eac17f87d..1d3c2861f 100644 --- a/templates/services/merge/consensus/lighthouse.tmpl +++ b/templates/services/merge/consensus/lighthouse.tmpl @@ -1,6 +1,7 @@ {{/* lighthouse.tmpl */}} {{ define "consensus" }} - consensus: + consensus:{{if and (ge .UID 0) (ge .GID 0)}} + user: "{{.UID}}:{{.GID}}"{{end}} stop_grace_period: 30s container_name: sedge-consensus-client{{if .ContainerTag}}-{{.ContainerTag}}{{end}} restart: unless-stopped diff --git a/templates/services/merge/consensus/lodestar.tmpl b/templates/services/merge/consensus/lodestar.tmpl index 86a074abb..ba37bacfd 100644 --- a/templates/services/merge/consensus/lodestar.tmpl +++ b/templates/services/merge/consensus/lodestar.tmpl @@ -1,6 +1,7 @@ {{/* lodestar.tmpl */}} {{ define "consensus" }} - consensus: + consensus:{{if and (ge .UID 0) (ge .GID 0)}} + user: "{{.UID}}:{{.GID}}"{{end}} stop_grace_period: 30s container_name: sedge-consensus-client{{if .ContainerTag}}-{{.ContainerTag}}{{end}} restart: unless-stopped diff --git a/templates/services/merge/consensus/prysm.tmpl b/templates/services/merge/consensus/prysm.tmpl index c41a45545..49ff75bb9 100644 --- a/templates/services/merge/consensus/prysm.tmpl +++ b/templates/services/merge/consensus/prysm.tmpl @@ -1,6 +1,7 @@ {{/* prysm.tmpl */}} {{ define "consensus" }} - consensus: + consensus:{{if and (ge .UID 0) (ge .GID 0)}} + user: "{{.UID}}:{{.GID}}"{{end}} stop_grace_period: 30s container_name: sedge-consensus-client{{if .ContainerTag}}-{{.ContainerTag}}{{end}} restart: unless-stopped diff --git a/templates/services/merge/execution/besu.tmpl b/templates/services/merge/execution/besu.tmpl index 4d7084927..34827ddf3 100644 --- a/templates/services/merge/execution/besu.tmpl +++ b/templates/services/merge/execution/besu.tmpl @@ -1,6 +1,7 @@ {{/* besu.tmpl */}} {{ define "execution" }} - execution: + execution:{{if and (ge .UID 0) (ge .GID 0)}} + user: "{{.UID}}:{{.GID}}"{{end}} stop_grace_period: 30m container_name: sedge-execution-client{{if .ContainerTag}}-{{.ContainerTag}}{{end}} restart: unless-stopped diff --git a/templates/services/merge/execution/erigon.tmpl b/templates/services/merge/execution/erigon.tmpl index 46e159ec7..4c4a56069 100644 --- a/templates/services/merge/execution/erigon.tmpl +++ b/templates/services/merge/execution/erigon.tmpl @@ -1,6 +1,7 @@ {{/* erigon.tmpl */}} {{ define "execution" }} - execution: + execution:{{if and (ge .UID 0) (ge .GID 0)}} + user: "{{.UID}}:{{.GID}}"{{end}} stop_grace_period: 30m container_name: sedge-execution-client{{if .ContainerTag}}-{{.ContainerTag}}{{end}} restart: unless-stopped diff --git a/templates/services/merge/execution/geth.tmpl b/templates/services/merge/execution/geth.tmpl index 4d0db7f60..5bc01fa12 100644 --- a/templates/services/merge/execution/geth.tmpl +++ b/templates/services/merge/execution/geth.tmpl @@ -1,6 +1,7 @@ {{/* geth.tmpl */}} {{ define "execution" }} - execution: + execution:{{if and (ge .UID 0) (ge .GID 0)}} + user: "{{.UID}}:{{.GID}}"{{end}} stop_grace_period: 30m container_name: sedge-execution-client{{if .ContainerTag}}-{{.ContainerTag}}{{end}} restart: unless-stopped diff --git a/templates/services/merge/execution/nethermind.tmpl b/templates/services/merge/execution/nethermind.tmpl index 1440240c9..dba7163cb 100644 --- a/templates/services/merge/execution/nethermind.tmpl +++ b/templates/services/merge/execution/nethermind.tmpl @@ -1,6 +1,7 @@ {{/* nethermind.tmpl */}} {{ define "execution" }} - execution: + execution:{{if and (ge .UID 0) (ge .GID 0)}} + user: "{{.UID}}:{{.GID}}"{{end}} tty: true environment: - TERM=xterm-256color diff --git a/templates/services/merge/validator/lighthouse.tmpl b/templates/services/merge/validator/lighthouse.tmpl index c815c1718..13681197b 100644 --- a/templates/services/merge/validator/lighthouse.tmpl +++ b/templates/services/merge/validator/lighthouse.tmpl @@ -1,6 +1,7 @@ {{/* lighthouse.tmpl */}} {{ define "validator" }} - validator: + validator:{{if and (ge .UID 0) (ge .GID 0)}} + user: "{{.UID}}:{{.GID}}"{{end}} container_name: sedge-validator-client{{if .ContainerTag}}-{{.ContainerTag}}{{end}} image: ${VL_IMAGE_VERSION} depends_on: diff --git a/templates/services/merge/validator/lodestar.tmpl b/templates/services/merge/validator/lodestar.tmpl index e5855ebfb..b1de1266e 100644 --- a/templates/services/merge/validator/lodestar.tmpl +++ b/templates/services/merge/validator/lodestar.tmpl @@ -1,6 +1,7 @@ {{/* lodestar.tmpl */}} {{ define "validator" }} - validator: + validator:{{if and (ge .UID 0) (ge .GID 0)}} + user: "{{.UID}}:{{.GID}}"{{end}} container_name: sedge-validator-client{{if .ContainerTag}}-{{.ContainerTag}}{{end}} image: ${VL_IMAGE_VERSION} depends_on: diff --git a/templates/services/merge/validator/prysm.tmpl b/templates/services/merge/validator/prysm.tmpl index 9f2ca8680..1bb37cc6e 100644 --- a/templates/services/merge/validator/prysm.tmpl +++ b/templates/services/merge/validator/prysm.tmpl @@ -1,6 +1,7 @@ {{/* prysm.tmpl */}} {{ define "validator" }} - validator: + validator:{{if and (ge .UID 0) (ge .GID 0)}} + user: "{{.UID}}:{{.GID}}"{{end}} container_name: sedge-validator-client{{if .ContainerTag}}-{{.ContainerTag}}{{end}} image: ${VL_IMAGE_VERSION} depends_on: From 600fd51f48e003c08ef1df9e694ee9eb67e5bc21 Mon Sep 17 00:00:00 2001 From: Carlos Bermudez Porto Date: Thu, 20 Jul 2023 17:13:23 -0400 Subject: [PATCH 3/7] chore: update changelog --- CHANGELOG.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1593a2d38..4ac726b54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed + +- Issue when running `sedge` without sudo. + ## [v1.2.0] - 2023-06-06 ### Added @@ -20,9 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Change validator blocker container image to [busybox](https://hub.docker.com/_/busybox). -- Erigon command line flags. - -## [Unreleased] +- Erigon command line flags. ## [v1.1.0] - 2023-04-07 From 31b34cbd1c583acb95d29b41cf1a400bec0aba94 Mon Sep 17 00:00:00 2001 From: Carlos Bermudez Porto Date: Thu, 20 Jul 2023 17:16:39 -0400 Subject: [PATCH 4/7] chore: update go mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index e199967e2..5434d8834 100644 --- a/go.mod +++ b/go.mod @@ -27,6 +27,7 @@ require ( github.com/wealdtech/go-eth2-types/v2 v2.8.0 github.com/wealdtech/go-eth2-util v1.8.0 golang.org/x/sync v0.1.0 + golang.org/x/text v0.7.0 gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v3 v3.0.1 gotest.tools/v3 v3.4.0 @@ -75,7 +76,6 @@ require ( golang.org/x/net v0.7.0 // indirect golang.org/x/sys v0.5.0 // indirect golang.org/x/term v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect golang.org/x/tools v0.6.0 // indirect ) From 48e570603a8127d16d351cf8873b4283018a2e81 Mon Sep 17 00:00:00 2001 From: Carlos Bermudez Porto Date: Thu, 20 Jul 2023 17:40:47 -0400 Subject: [PATCH 5/7] fix: wrong check when creating datadirs --- cli/actions/generation.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/cli/actions/generation.go b/cli/actions/generation.go index 4fa29849b..30ed3c122 100644 --- a/cli/actions/generation.go +++ b/cli/actions/generation.go @@ -92,19 +92,16 @@ func (s *sedgeActions) Generate(options GenerateOptions) (generate.GenData, erro createIf bool }{ { - path: filepath.Join(options.GenerationPath, configs.ExecutionDir), - createIf: options.GenerationData.ExecutionClient != nil && - options.GenerationData.ExecutionClient.Supported, + path: filepath.Join(options.GenerationPath, configs.ExecutionDir), + createIf: options.GenerationData.ExecutionClient != nil, }, { - path: filepath.Join(options.GenerationPath, configs.ConsensusDir), - createIf: options.GenerationData.ConsensusClient != nil && - options.GenerationData.ConsensusClient.Supported, + path: filepath.Join(options.GenerationPath, configs.ConsensusDir), + createIf: options.GenerationData.ConsensusClient != nil, }, { - path: filepath.Join(options.GenerationPath, configs.ValidatorDir), - createIf: options.GenerationData.ValidatorClient != nil && - options.GenerationData.ValidatorClient.Supported, + path: filepath.Join(options.GenerationPath, configs.ValidatorDir), + createIf: options.GenerationData.ValidatorClient != nil, }, } for _, datadir := range datadirs { From cd20000fecc1969522bf7e774ba139945b82c7b4 Mon Sep 17 00:00:00 2001 From: Carlos Bermudez Porto <43155355+cbermudez97@users.noreply.github.com> Date: Tue, 25 Jul 2023 11:06:20 -0400 Subject: [PATCH 6/7] fix: typo in cli/actions/generation_test.go Co-authored-by: Miguel Tenorio <46824157+AntiD2ta@users.noreply.github.com> --- cli/actions/generation_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/actions/generation_test.go b/cli/actions/generation_test.go index ce203fb31..4ff6519a8 100644 --- a/cli/actions/generation_test.go +++ b/cli/actions/generation_test.go @@ -499,7 +499,7 @@ func validateGeneration(t *testing.T, samplePath string, datadirs ...datadirsVal assert.FileExists(t, filepath.Join(samplePath, configs.DefaultDockerComposeScriptName)) // Check that .env file exist assert.FileExists(t, filepath.Join(samplePath, configs.DefaultEnvFileName)) - // Check datadirs are correclty generated + // Check datadirs are correctly generated for _, datadir := range datadirs { if datadir.shouldExist { assert.DirExists(t, filepath.Join(samplePath, datadir.path)) From 1741c7fb72189f23933f99ef0e8c1657ee643598 Mon Sep 17 00:00:00 2001 From: Carlos Bermudez Porto Date: Tue, 25 Jul 2023 12:15:19 -0400 Subject: [PATCH 7/7] fix: github pr comments --- CHANGELOG.md | 2 +- cli/actions/generation.go | 5 ++++- internal/pkg/clients/clients.go | 2 +- internal/pkg/clients/types.go | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ac726b54..79d8963ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Issue when running `sedge` without sudo. +- Issue when `sedge` generates clients datadirs without sudo. ## [v1.2.0] - 2023-06-06 diff --git a/cli/actions/generation.go b/cli/actions/generation.go index 30ed3c122..429fdc9b8 100644 --- a/cli/actions/generation.go +++ b/cli/actions/generation.go @@ -106,11 +106,14 @@ func (s *sedgeActions) Generate(options GenerateOptions) (generate.GenData, erro } for _, datadir := range datadirs { if datadir.createIf { - if _, err := os.Stat(datadir.path); os.IsNotExist(err) { + _, err := os.Stat(datadir.path) + if os.IsNotExist(err) { err = os.MkdirAll(datadir.path, 0o755) if err != nil { return options.GenerationData, err } + } else { + return options.GenerationData, err } } } diff --git a/internal/pkg/clients/clients.go b/internal/pkg/clients/clients.go index ec1b75ef4..ab85489c2 100644 --- a/internal/pkg/clients/clients.go +++ b/internal/pkg/clients/clients.go @@ -45,7 +45,7 @@ b. error Error if any */ func (c ClientInfo) SupportedClients(clientType ClientType) (clientsNames []string, err error) { - files, err := templates.Envs.ReadDir(strings.Join([]string{"envs", c.Network, clientType.ToString()}, "/")) + files, err := templates.Envs.ReadDir(strings.Join([]string{"envs", c.Network, clientType.String()}, "/")) if err != nil { return } diff --git a/internal/pkg/clients/types.go b/internal/pkg/clients/types.go index f4183a8b6..0ccdfa4fb 100644 --- a/internal/pkg/clients/types.go +++ b/internal/pkg/clients/types.go @@ -23,13 +23,13 @@ import ( type ClientType string -func (ct ClientType) ToString() string { +func (ct ClientType) String() string { return string(ct) } func (ct ClientType) ToTitle() string { caser := cases.Title(language.English) - return caser.String(ct.ToString()) + return caser.String(ct.String()) } const (