Skip to content

Commit

Permalink
Merge pull request #9 from ObolNetwork/fixReviews
Browse files Browse the repository at this point in the history
Update types, fix bugs, reviews
  • Loading branch information
sugh01 authored Mar 22, 2024
2 parents ace8ff6 + 7db04d0 commit 489baf0
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 93 deletions.
5 changes: 3 additions & 2 deletions cli/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,10 @@ func valClients(allClients clients.OrderedClients, flags *GenCmdFlags, services
// distributed validator client
if utils.Contains(services, distributedValidator) {
distributedValidatorClient, _ = clients.RandomChoice(allClients[distributedValidator])
// distributedValidatorClient.Name = "charon"
//TODO: Add support for custom images,
distributedValidatorClient.Name = "charon"
distributedValidatorClient.SetImageOrDefault("")
if err = clients.ValidateClient(distributedValidatorClient, validator); err != nil {
if err = clients.ValidateClient(distributedValidatorClient, distributedValidator); err != nil {
return nil, err
}
}
Expand Down
3 changes: 1 addition & 2 deletions cli/sub_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ Additionally, you can use this syntax '<CLIENT>:<DOCKER_IMAGE>' to override the
cmd.Flags().StringVarP(&flags.consensusName, "consensus", "c", "", "Consensus engine client, e.g. teku, lodestar, prysm, lighthouse, Nimbus. Additionally, you can use this syntax '<CLIENT>:<DOCKER_IMAGE>' to override the docker image used for the client. If you want to use the default docker image, just use the client name")
cmd.Flags().StringVarP(&flags.executionName, "execution", "e", "", "Execution engine client, e.g. geth, nethermind, besu, erigon. Additionally, you can use this syntax '<CLIENT>:<DOCKER_IMAGE>' to override the docker image used for the client. If you want to use the default docker image, just use the client name")
cmd.Flags().StringVarP(&flags.validatorName, "validator", "v", "", "Validator engine client, e.g. teku, lodestar, prysm, lighthouse, Nimbus. Additionally, you can use this syntax '<CLIENT>:<DOCKER_IMAGE>' to override the docker image used for the client. If you want to use the default docker image, just use the client name")
// cmd.Flags().StringVarP(&flags.distributedValidatorName, "distributed", "v", "", "Distributed validator client, e.g. Charon. Additionally, you can use this syntax '<CLIENT>:<DOCKER_IMAGE>' to override the docker image used for the client. If you want to use the default docker image, just use the client name")
cmd.Flags().BoolVar(&flags.distributed, "distributed", false, "Deploy with Charon as the distributed validator client. If set, the distributed validator client will be used instead of the regular validator client.")
cmd.Flags().BoolVar(&flags.distributed, "distributed", false, "Deploy a node configured to run as part of a Distributed Validator Cluster.")
cmd.Flags().BoolVar(&flags.latestVersion, "latest", false, "Use the latest version of clients. This sets the \"latest\" tag on the client's docker images. Latest version might not work.")
cmd.Flags().StringVar(&flags.checkpointSyncUrl, "checkpoint-sync-url", "", "Initial state endpoint (trusted synced consensus endpoint) for the consensus client to sync from a finalized checkpoint. Provide faster sync process for the consensus client and protect it from long-range attacks affored by Weak Subjetivity. Each network has a default checkpoint sync url.")
cmd.Flags().StringVar(&flags.feeRecipient, "fee-recipient", "", "Suggested fee recipient. Is a 20-byte Ethereum address which the execution layer might choose to set as the coinbase and the recipient of other fees or rewards. There is no guarantee that an execution node will use the suggested fee recipient to collect fees, it may use any address it chooses. It is assumed that an honest execution node will use the suggested fee recipient, but users should note this trust assumption")
Expand Down
2 changes: 1 addition & 1 deletion configs/client_images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ validator:
distributedValidator:
charon:
name: ghcr.io/obolnetwork/charon
version: v0.19.1
version: v0.19.2
1 change: 1 addition & 0 deletions configs/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var ClientImages struct {
Lodestar Image `yaml:"lodestar"`
Teku Image `yaml:"teku"`
Prysm Image `yaml:"prysm"`
Charon Image `yaml:"charon"`
}
DistributedValidator struct {
Charon Image `yaml:"charon"`
Expand Down
2 changes: 1 addition & 1 deletion configs/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ const (
ConsensusDir = "consensus-data"
ValidatorDir = "validator-data"
KeystoreDir = "keystore"
CharonDir = ".charon"
DistributedValidatorDir = ".charon"
)
3 changes: 3 additions & 0 deletions configs/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ const (
DefaultAdditionalApiPortCL uint16 = 4001
DefaultMetricsPortVL uint16 = 5056
DefaultMevPort uint16 = 18550
DefaultDiscoveryPortDV uint16 = 3610
DefaultMetricsPortDV uint16 = 3620
DefaultApiPortDV uint16 = 3600
)
8 changes: 6 additions & 2 deletions internal/pkg/clients/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ limitations under the License.
*/
package clients

import "github.com/NethermindEth/sedge/configs"
import (
"github.com/NethermindEth/sedge/configs"
)

// Client : Struct Represent a client like geth, prysm, etc
type Client struct {
Expand Down Expand Up @@ -82,6 +84,8 @@ func (c *Client) setDistributedValidatorImage(image string) {
switch c.Name {
case "charon":
c.Image = valueOrDefault(image, configs.ClientImages.DistributedValidator.Charon.String())
default:
c.Image = valueOrDefault(image, configs.ClientImages.DistributedValidator.Charon.String())
}
}

Expand All @@ -92,7 +96,7 @@ func valueOrDefault(value string, defaultValue string) string {
return value
}

// Clients : Struct Represent a combination of execution, consensus and validator clients
// Clients : Struct Represent a combination of execution, consensus, validator and distributed validator clients
type Clients struct {
Execution *Client
Consensus *Client
Expand Down
91 changes: 54 additions & 37 deletions internal/pkg/generate/generate_scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func validateClients(gd *GenData) error {
if err := validateValidator(gd, &c); err != nil {
return err
}
// if err := validateDistributedValidator(gd, &c); err != nil {
// return err
// }
if err := validateDistributedValidator(gd, &c); err != nil {
return err
}
return nil
}

Expand All @@ -78,19 +78,19 @@ func validateValidator(gd *GenData, c *clients.ClientInfo) error {
}

// validateDistributedValidator validates the validator client in GenData
// func validateDistributedValidator(gd *GenData, c *clients.ClientInfo) error {
// if gd.DistributedValidatorClient == nil {
// return nil
// }
// validatorClients, err := c.SupportedClients(distributedValidator)
// if err != nil {
// return ErrUnableToGetClientsInfo
// }
// if !utils.Contains(validatorClients, gd.ValidatorClient.Name) {
// return ErrValidatorClientNotValid
// }
// return nil
// }
func validateDistributedValidator(gd *GenData, c *clients.ClientInfo) error {
if gd.DistributedValidatorClient == nil {
return nil
}
distributedValidatorClients, err := c.SupportedClients(distributedValidator)
if err != nil {
return ErrUnableToGetClientsInfo
}
if !utils.Contains(distributedValidatorClients, gd.DistributedValidatorClient.Name) {
return ErrValidatorClientNotValid
}
return nil
}

// validateExecution validates the execution client in GenData
func validateExecution(gd *GenData, c *clients.ClientInfo) error {
Expand Down Expand Up @@ -158,6 +158,9 @@ func ComposeFile(gd *GenData, at io.Writer) error {
"CLAdditionalApi": configs.DefaultAdditionalApiPortCL,
"VLMetrics": configs.DefaultMetricsPortVL,
"MevPort": configs.DefaultMevPort,
"DVDiscovery": configs.DefaultDiscoveryPortDV,
"DVMetrics": configs.DefaultMetricsPortDV,
"DVApi": configs.DefaultApiPortDV,
}
ports, err := utils.AssignPorts("localhost", defaultsPorts)
if err != nil {
Expand Down Expand Up @@ -316,6 +319,9 @@ func ComposeFile(gd *GenData, at io.Writer) error {
UID: os.Geteuid(),
GID: os.Getegid(),
ContainerTag: gd.ContainerTag,
DVDiscoveryPort: gd.Ports["DVDiscovery"],
DVMetricsPort: gd.Ports["DVMetrics"],
DVApiPort: gd.Ports["DVApi"],
}

// Save to writer
Expand Down Expand Up @@ -434,28 +440,39 @@ func EnvFile(gd *GenData, at io.Writer) error {
gd.CheckpointSyncUrl = configs.NetworksConfigs()[gd.Network].CheckpointSyncURL
}

distributedValidatorApiUrl := gd.DistributedValidatorClient.Endpoint
if gd.Distributed {
// Check for distributed validator
if cls[distributedValidator] != nil {
distributedValidatorApiUrl = fmt.Sprintf("%s:%v", cls[distributedValidator].Endpoint, gd.Ports["DVApi"])
}
}

data := EnvData{
Services: gd.Services,
Mev: networkConfig.SupportsMEVBoost && (gd.MevBoostService || (mevSupported && gd.Mev) || gd.MevBoostOnValidator),
ElImage: imageOrEmpty(cls[execution], gd.LatestVersion),
ElDataDir: "./" + configs.ExecutionDir,
CcImage: imageOrEmpty(cls[consensus], gd.LatestVersion),
CcDataDir: "./" + configs.CharonDir,
VlImage: imageOrEmpty(cls[validator], gd.LatestVersion),
VlDataDir: "./" + configs.ValidatorDir,
ExecutionApiURL: executionApiUrl,
ExecutionAuthURL: executionAuthUrl,
ConsensusApiURL: consensusApiUrl,
ConsensusAdditionalApiURL: consensusAdditionalApiUrl,
FeeRecipient: gd.FeeRecipient,
JWTSecretPath: gd.JWTSecretPath,
ExecutionEngineName: nameOrEmpty(cls[execution]),
ConsensusClientName: nameOrEmpty(cls[consensus]),
KeystoreDir: "./" + configs.KeystoreDir,
Graffiti: graffiti,
RelayURLs: strings.Join(gd.RelayURLs, ","),
CheckpointSyncUrl: gd.CheckpointSyncUrl,
Distributed: gd.Distributed,
Services: gd.Services,
Mev: networkConfig.SupportsMEVBoost && (gd.MevBoostService || (mevSupported && gd.Mev) || gd.MevBoostOnValidator),
ElImage: imageOrEmpty(cls[execution], gd.LatestVersion),
ElDataDir: "./" + configs.ExecutionDir,
CcImage: imageOrEmpty(cls[consensus], gd.LatestVersion),
CcDataDir: "./" + configs.ConsensusDir,
VlImage: imageOrEmpty(cls[validator], gd.LatestVersion),
VlDataDir: "./" + configs.ValidatorDir,
ExecutionApiURL: executionApiUrl,
ExecutionAuthURL: executionAuthUrl,
ConsensusApiURL: consensusApiUrl,
ConsensusAdditionalApiURL: consensusAdditionalApiUrl,
FeeRecipient: gd.FeeRecipient,
JWTSecretPath: gd.JWTSecretPath,
ExecutionEngineName: nameOrEmpty(cls[execution]),
ConsensusClientName: nameOrEmpty(cls[consensus]),
KeystoreDir: "./" + configs.KeystoreDir,
Graffiti: graffiti,
RelayURLs: strings.Join(gd.RelayURLs, ","),
CheckpointSyncUrl: gd.CheckpointSyncUrl,
Distributed: gd.Distributed,
DistributedValidatorApiUrl: distributedValidatorApiUrl,
DvDataDir: "./" + configs.DistributedValidatorDir,
DvImage: imageOrEmpty(cls[distributedValidator], gd.LatestVersion),
}

// Save to writer
Expand Down
66 changes: 36 additions & 30 deletions internal/pkg/generate/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,30 @@ import (

// EnvData : Struct Data object to be applied to the docker-compose script environment (.env) template
type EnvData struct {
Services []string
Mev bool
ElImage string
ElDataDir string
CcImage string
CcDataDir string
VlImage string
VlDataDir string
ExecutionApiURL string
ExecutionAuthURL string
ConsensusApiURL string
ConsensusAdditionalApiURL string
Distributed bool
FeeRecipient string
JWTSecretPath string
ExecutionEngineName string
ConsensusClientName string
KeystoreDir string
Graffiti string
RelayURLs string
CheckpointSyncUrl string
Services []string
Mev bool
ElImage string
ElDataDir string
CcImage string
CcDataDir string
VlImage string
VlDataDir string
ExecutionApiURL string
ExecutionAuthURL string
ConsensusApiURL string
ConsensusAdditionalApiURL string
Distributed bool
FeeRecipient string
JWTSecretPath string
ExecutionEngineName string
ConsensusClientName string
KeystoreDir string
Graffiti string
RelayURLs string
CheckpointSyncUrl string
DistributedValidatorApiUrl string
DvDataDir string
DvImage string
}

// GenData : Struct Data object for script's generation
Expand Down Expand Up @@ -131,6 +134,9 @@ type DockerComposeData struct {
UID int // Needed for teku
GID int // Needed for teku
ContainerTag string
DVDiscoveryPort uint16
DVMetricsPort uint16
DVApiPort uint16
}

// WithConsensusClient returns true if the consensus client is set
Expand Down Expand Up @@ -163,15 +169,15 @@ func (d EnvData) WithMevBoostClient() bool {
return false
}

// WithDistributedValidatorClient returns true if the Mev-Boost client is set
// func (d EnvData) WithDistributedValidatorClient() bool {
// for _, service := range d.Services {
// if service == distributedValidator {
// return true
// }
// }
// return false
// }
// WithDistributedValidatorClient returns true if the DistributedValidator client is set
func (d EnvData) WithDistributedValidatorClient() bool {
for _, service := range d.Services {
if service == distributedValidator {
return true
}
}
return false
}

type ComposeData struct {
Version string `yaml:"version,omitempty"`
Expand Down
11 changes: 6 additions & 5 deletions templates/envs/goerli/distributedValidator/charon.tmpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{{/* charon.tmpl */}}
{{ define "distributedValidator" }}
# --- Charon - distributed validator - configuration ---
DC_LOG_LEVEL=info
DC_LOG_FORMAT=console
DC_INSTANCE_NAME=Charon
DC_DATA_DIR={{.CcDataDir}}
DC_API_URL={{.ConsensusApiURL}}
DV_IMAGE_VERSION={{.DvImage}}
DV_LOG_LEVEL=info
DV_LOG_FORMAT=console
DV_INSTANCE_NAME=charon
DV_DATA_DIR={{.DvDataDir}}
DV_API_URL={{.DistributedValidatorApiUrl}}
{{ end }}
10 changes: 10 additions & 0 deletions templates/envs/holesky/distributedValidator/charon.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{/* charon.tmpl */}}
{{ define "distributedValidator" }}
# --- Charon - distributed validator - configuration ---
DV_IMAGE_VERSION={{.DvImage}}
DV_LOG_LEVEL=info
DV_LOG_FORMAT=console
DV_INSTANCE_NAME=charon
DV_DATA_DIR={{.DvDataDir}}
DV_API_URL={{.DistributedValidatorApiUrl}}
{{ end }}
3 changes: 2 additions & 1 deletion templates/envs/holesky/env_base.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ NETWORK=holesky
FEE_RECIPIENT={{.FeeRecipient}}{{end}}
{{template "execution" .}}
{{template "consensus" .}}
{{template "validator" .}}
{{template "validator" .}}{{if .Distributed}}
{{template "distributedValidator" .}}{{end}}
{{ end }}
22 changes: 11 additions & 11 deletions templates/services/merge/distributedValidator/charon.tmpl
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{{/* charon.tmpl */}}
{{ define "distributedValidator" }}
charon:
image: obolnetwork/charon:${CHARON_VERSION:-v0.19.0}
image: obolnetwork/charon:${DV_IMAGE_VERSION}
environment:
- CHARON_BEACON_NODE_ENDPOINTS=${CC_API_URL}
- CHARON_LOG_LEVEL=${DC_LOG_LEVEL:-info}
- CHARON_LOG_FORMAT=${DC_LOG_FORMAT:-console}
- CHARON_P2P_RELAYS=${DC_P2P_RELAYS:-https://0.relay.obol.tech}
- CHARON_P2P_EXTERNAL_HOSTNAME=${DC_INSTANCE_NAME:-charon}
- CHARON_P2P_TCP_ADDRESS=0.0.0.0:3610
- CHARON_VALIDATOR_API_ADDRESS=0.0.0.0:3600
- CHARON_MONITORING_ADDRESS=0.0.0.0:3620
- CHARON_LOG_LEVEL=${DV_LOG_LEVEL:-info}
- CHARON_LOG_FORMAT=${DV_LOG_FORMAT:-console}
- CHARON_P2P_RELAYS=${DV_P2P_RELAYS:-https://0.relay.obol.tech}
- CHARON_P2P_EXTERNAL_HOSTNAME=${DV_INSTANCE_NAME:-charon}
- CHARON_P2P_TCP_ADDRESS=0.0.0.0:{{.DVDiscoveryPort}}
- CHARON_VALIDATOR_API_ADDRESS=0.0.0.0:{{.DVApiPort}}
- CHARON_MONITORING_ADDRESS=0.0.0.0:{{.DVMetricsPort}}
- CHARON_BUILDER_API={{.MevBoostOnValidator}}
ports:
- ${CHARON_PORT_P2P_TCP:-3610}:${CHARON_PORT_P2P_TCP:-3610}/tcp # P2P TCP libp2p
- ${CHARON_PORT_P2P_TCP:-{{.DVDiscoveryPort}}}:${CHARON_PORT_P2P_TCP:-{{.DVDiscoveryPort}}}/tcp
networks:
- sedge
volumes:
- ${DC_DATA_DIR}:/opt/charon/.charon
- ${DV_DATA_DIR}:/opt/charon/.charon
restart: unless-stopped
healthcheck:
test: wget -qO- http://localhost:3620/readyz
test: wget -qO- http://localhost:{{.DVMetricsPort}}/readyz
{{ end }}
2 changes: 1 addition & 1 deletion templates/services/merge/validator/lighthouse.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- --testnet-dir=/network_config{{end}}
- vc{{if not .CustomConsensusConfigs}}
- --network={{if .SplittedNetwork}}${CL_NETWORK}{{else}}${NETWORK}{{end}}{{end}}
- --beacon-nodes={{if .Distributed}}{{.DistributedValidatorEndpoint}}{{else}}${CC_API_URL}{{end}}
- --beacon-nodes={{if .Distributed}}${DV_API_URL}{{else}}${CC_API_URL}{{end}}
- --graffiti=${GRAFFITI}
- --debug-level=${VL_LOG_LEVEL}
- --validators-dir=/data/validators{{with .FeeRecipient}}
Expand Down

0 comments on commit 489baf0

Please sign in to comment.