Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue when running Sedge with a non root user #303

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `sedge` generates clients datadirs without sudo.

## [v1.2.0] - 2023-06-06

### Added
Expand All @@ -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

Expand Down
32 changes: 32 additions & 0 deletions cli/actions/generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
{
path: filepath.Join(options.GenerationPath, configs.ConsensusDir),
createIf: options.GenerationData.ConsensusClient != nil,
},
{
path: filepath.Join(options.GenerationPath, configs.ValidatorDir),
createIf: options.GenerationData.ValidatorClient != nil,
},
}
for _, datadir := range datadirs {
if datadir.createIf {
_, 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
}
}
}

return options.GenerationData, nil
}
35 changes: 29 additions & 6 deletions cli/actions/generation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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))
Expand Down Expand Up @@ -444,11 +454,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,
Expand All @@ -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
Expand All @@ -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 correctly 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")
Expand Down
2 changes: 1 addition & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions cli/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 14 additions & 6 deletions cli/listClients.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
8 changes: 4 additions & 4 deletions internal/pkg/clients/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ List of supported clients names of type <clientType>
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.String()}, "/"))
if err != nil {
return
}
Expand Down Expand Up @@ -80,7 +80,7 @@ Map of <clientType>: map of <clientName>: 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 {
Expand Down Expand Up @@ -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
}
Expand Down
74 changes: 37 additions & 37 deletions internal/pkg/clients/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}

Expand All @@ -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
}
Expand Down Expand Up @@ -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,
},
Expand All @@ -161,7 +161,7 @@ func TestClients(t *testing.T) {
func TestValidateClient(t *testing.T) {
inputs := [...]struct {
client Client
clientType string
clientType ClientType
isErr bool
}{
{
Expand All @@ -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,
},
}
Expand Down
Loading