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

DV Setup: Charon Integration with Sedge #368

Merged
merged 75 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
c854863
charon poc
sugh01 Feb 28, 2024
c15f541
fix tppo
sugh01 Feb 28, 2024
0caf331
add distributed flag to vc if Distributed
sugh01 Feb 28, 2024
cbafd39
Update configs/client_images.yaml
sugh01 Mar 13, 2024
ea530dc
fix:remove "-"
3235773541 Mar 14, 2024
68fc7d0
fix: validator-blocker
3235773541 Mar 14, 2024
ace8ff6
Merge pull request #5 from ObolNetwork/poc-xin
sugh01 Mar 18, 2024
03dc2ca
add Distributed Client Test
3235773541 Mar 20, 2024
7db04d0
Update types, fix bugs, reviews
sugh01 Mar 22, 2024
489baf0
Merge pull request #9 from ObolNetwork/fixReviews
sugh01 Mar 22, 2024
f34f1e2
fix types for distributed validator image defaults
sugh01 Mar 25, 2024
8ab788f
Merge branch 'poc' into poc-xin
sugh01 Mar 25, 2024
516633a
Merge pull request #7 from ObolNetwork/poc-xin
sugh01 Mar 25, 2024
70ae576
Merge branch 'develop' into poc
sugh01 Mar 25, 2024
df3842f
Update templates/services/merge/distributedValidator/charon.tmpl
sugh01 Mar 25, 2024
ce40cc4
Make DV service generic
sugh01 Mar 26, 2024
da6bb59
fix tests
sugh01 Mar 26, 2024
1a6dfe8
Merge pull request #15 from ObolNetwork/fixReview
sugh01 Mar 26, 2024
8e7ddbf
fix dv tests
sugh01 Mar 26, 2024
c141758
Merge pull request #3 from ObolNetwork/poc
sugh01 Mar 26, 2024
d848341
Merge branch 'develop' into develop
sugh01 May 9, 2024
f68bd7b
allow import of distributed validator keystores
sugh01 Jun 18, 2024
c4a016e
updates to Teku key import
sugh01 Jun 18, 2024
631e9a2
updates to Teku validator init
sugh01 Jun 18, 2024
9cce4fc
Merge pull request #21 from ObolNetwork/feat/importKey
sugh01 Jul 2, 2024
bb7d95f
Merge remote-tracking branch 'upstream/develop' into develop
sugh01 Jul 2, 2024
df81a46
Merge branch 'develop' into develop
sugh01 Jul 8, 2024
d64d6f2
Merge remote-tracking branch 'upstream/develop' into develop
sugh01 Jul 16, 2024
9d8049f
fixed lighthouse imports
sugh01 Jul 29, 2024
52f25a6
use DefaultAbsSedgeDataPath for charon key imports
sugh01 Jul 29, 2024
c84beeb
Merge branch 'NethermindEth:develop' into develop
sugh01 Jul 30, 2024
0528670
Document DV Setup Process with Sedge
sugh01 Jul 30, 2024
b9aede7
Update docs/docs/commands/importKey.mdx
sugh01 Jul 31, 2024
086f599
Update docs/docs/quickstart/charon.mdx
sugh01 Jul 31, 2024
2e73784
Update docs/docs/quickstart/charon.mdx
sugh01 Jul 31, 2024
86311be
Update docs/docs/quickstart/charon.mdx
sugh01 Jul 31, 2024
3a24c5a
Update docs/docs/quickstart/charon.mdx
sugh01 Jul 31, 2024
a7f0aff
Update docs/docs/quickstart/charon.mdx
sugh01 Jul 31, 2024
071f50e
Update docs/docs/quickstart/charon.mdx
sugh01 Jul 31, 2024
cc6537a
Update docs/docs/quickstart/charon.mdx
sugh01 Jul 31, 2024
af33481
Update docs/docs/quickstart/charon.mdx
sugh01 Jul 31, 2024
11c67bf
Update docs/docs/quickstart/charon.mdx
sugh01 Jul 31, 2024
b653d57
Merge pull request #22 from ObolNetwork/docs
sugh01 Jul 31, 2024
df42cd5
Fixed defaultKeystorePath for Charon key imports
sugh01 Aug 5, 2024
c33443f
import key tests from distributed option
sugh01 Aug 5, 2024
0d280e5
bug fixes
sugh01 Aug 8, 2024
ad0fe03
add dv extra flags feature
sugh01 Aug 12, 2024
3fefc3a
Merge pull request #23 from ObolNetwork/dv-extra-flag
sugh01 Aug 14, 2024
2179e31
Allow custom dv images, and few review fixes
sugh01 Aug 20, 2024
2de8523
Resolved merge conflicts with upstream/develop
sugh01 Aug 23, 2024
4fd321d
Add script to fetch and update Charon to the latest version
sugh01 Aug 23, 2024
fb9f310
lighthouse import-key tests
sugh01 Aug 28, 2024
415b72a
teku import-key tests
sugh01 Aug 28, 2024
3973533
run formatter
sugh01 Sep 2, 2024
70ed24c
lodestar import keys test in distributed mode
sugh01 Sep 2, 2024
7d65e98
debug tests
sugh01 Sep 2, 2024
3f28bd1
fix file permissions for distributed key imports
sugh01 Sep 2, 2024
3fa7a22
teku import key tests
sugh01 Sep 2, 2024
d0216d5
skip key-import tests
sugh01 Sep 2, 2024
1558cd3
Revert last commit
sugh01 Sep 2, 2024
082dec6
remove error logs
sugh01 Sep 3, 2024
aa0e335
Merge remote-tracking branch 'upstream/develop' into develop
sugh01 Sep 3, 2024
db2eee2
fix missing test data
sugh01 Sep 3, 2024
1b861b4
Resolved merge conflicts with upstream/develop
sugh01 Sep 13, 2024
6099dca
rebase and fix conflicts
sugh01 Sep 18, 2024
5f67349
Merge remote-tracking branch 'upstream/develop' into develop
sugh01 Sep 26, 2024
f705474
Merge remote-tracking branch 'upstream/develop' into develop
sugh01 Sep 27, 2024
5aea20d
Merge remote-tracking branch 'upstream/develop' into develop
sugh01 Oct 23, 2024
92fdbe6
add Nimbus client to DV
sugh01 Oct 23, 2024
ba654f1
fix conflict
sugh01 Oct 30, 2024
5434d40
remove redundant methods
sugh01 Oct 30, 2024
677c5dd
Merge remote-tracking branch 'upstream/develop' into develop
sugh01 Nov 5, 2024
07dda47
Merge remote-tracking branch 'upstream/develop' into develop
sugh01 Nov 7, 2024
349e54e
Update Changelog
sugh01 Nov 7, 2024
0ab4545
Update CHANGELOG.md
sugh01 Nov 14, 2024
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
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ internal/lido/contracts/csfeedistributor/CSFeeDistributor.go

internal/lido/contracts/csmodule/CSModule.go

internal/lido/contracts/mevboostrelaylist/MEVBoostRelayAllowedList.go
internal/lido/contracts/mevboostrelaylist/MEVBoostRelayAllowedList.go
cluster/

.charon/
node*/

keystore*
!cli/actions/testdata/charon/validator_keys/keystore*
37 changes: 37 additions & 0 deletions cli/actions/generation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ func TestGenerateDockerCompose(t *testing.T) {
if err != nil {
t.Errorf("SupportedClients(\"validator\") failed: %v", err)
}
var distributedValidatorClients []string
if network == "holesky" {
distributedValidatorClients, err = c.SupportedClients("distributedValidator")
if err != nil {
t.Errorf("SupportedClients(\"distributedValidator\") failed: %v", err)
}
}

rNum, err := rand.Int(rand.Reader, big.NewInt(int64(100)))
if err != nil {
Expand Down Expand Up @@ -265,6 +272,25 @@ func TestGenerateDockerCompose(t *testing.T) {
},
)
}

// For distributedValidator
if utils.Contains(distributedValidatorClients, "charon") {
tests = append(tests,
genTestData{
name: fmt.Sprintf("execution: %s, consensus: %s, validator: %s,distributedValidator: %s, network: %s, all, with distributedValidator", executionCl, consensusCl, consensusCl, distributedValidatorClients, network),
genData: generate.GenData{
Distributed: true,
DistributedValidatorClient: &clients.Client{Name: "charon", Type: "distributedValidator"},
ExecutionClient: &clients.Client{Name: executionCl, Type: "execution"},
ConsensusClient: &clients.Client{Name: consensusCl, Type: "consensus"},
ValidatorClient: &clients.Client{Name: consensusCl, Type: "validator"},
Services: []string{"execution", "consensus", "validator", "distributedValidator"},
Network: network,
},
},
)
}

}
}
}
Expand All @@ -287,6 +313,9 @@ func TestGenerateDockerCompose(t *testing.T) {
if tc.genData.ValidatorClient != nil {
tc.genData.ValidatorClient.SetImageOrDefault("")
}
if tc.genData.DistributedValidatorClient != nil {
tc.genData.DistributedValidatorClient.SetImageOrDefault("")
}

_, err := sedgeAction.Generate(actions.GenerateOptions{
GenerationData: tc.genData,
Expand Down Expand Up @@ -470,6 +499,14 @@ func TestGenerateDockerCompose(t *testing.T) {
}
}

// Validate that Distributed Validator Client info matches the sample data
if tc.genData.DistributedValidatorClient != nil {
// Check that the distributed-validator service is set.
assert.NotNil(t, cmpData.Services.DistributedValidator)
// Check that the distributed-validator container Volume is set.
assert.Equal(t, "${DV_DATA_DIR}:/opt/charon/.charon", cmpData.Services.DistributedValidator.Volumes[0])
}

if tc.genData.ValidatorClient == nil {
// Check validator blocker is not set if validator is not set
assert.Nil(t, cmpData.Services.ValidatorBlocker)
Expand Down
173 changes: 162 additions & 11 deletions cli/actions/importKeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/NethermindEth/sedge/configs"
"github.com/NethermindEth/sedge/internal/images/validator-import/lighthouse"
"github.com/NethermindEth/sedge/internal/images/validator-import/prysm"
"github.com/NethermindEth/sedge/internal/images/validator-import/teku"
"github.com/NethermindEth/sedge/internal/pkg/commands"
"github.com/NethermindEth/sedge/internal/pkg/services"
Expand All @@ -48,6 +49,7 @@ type ImportValidatorKeysOptions struct {
GenerationPath string
ContainerTag string
CustomConfig ImportValidatorKeysCustomOptions
Distributed bool
}
type ImportValidatorKeysCustomOptions struct {
NetworkConfigPath string
Expand Down Expand Up @@ -97,19 +99,95 @@ func (s *sedgeActions) ImportValidatorKeys(options ImportValidatorKeysOptions) e
options.GenerationPath = absGenerationPath

if !isDefaultKeysPath(options.GenerationPath, options.From) {
defaultKeystorePath := filepath.Join(options.GenerationPath, "keystore")
log.Warnf("The keys path is not the default one, copying the keys to the default path %s", defaultKeystorePath)
copy.Copy(options.From, defaultKeystorePath)
if !options.Distributed {
defaultKeystorePath := filepath.Join(options.GenerationPath, "keystore")
log.Warnf("The keys path is not the default one, copying the keys to the default path %s", defaultKeystorePath)
copy.Copy(options.From, defaultKeystorePath)
}
}

if options.Distributed {
cwd, _ := os.Getwd()
charonPath := filepath.Join(cwd, ".charon")

if !isDefaultKeysPath(options.GenerationPath, options.From) {
charonPath = options.From
log.Infof("Copying the keys from %s", charonPath)
options.From = filepath.Join(options.GenerationPath, "keystore")
}
defaultCharonPath := filepath.Join(configs.DefaultAbsSedgeDataPath, ".charon")
// Copy the folder from charonPath to defaultCharonPath
log.Infof("Copying Charon contents to the default path %s", defaultCharonPath)
if err := os.MkdirAll(defaultCharonPath, 0o755); err != nil {
return err
}
if err := copy.Copy(charonPath, defaultCharonPath); err != nil {
return err
}
charonValidatorKeysPath := filepath.Join(charonPath, "validator_keys")
defaultKeystorePath := filepath.Join(configs.DefaultAbsSedgeDataPath, "keystore")
log.Infof("Copying the keys to the default path %s", defaultKeystorePath)
if err := os.MkdirAll(defaultKeystorePath, 0o755); err != nil {
return err
}

validatorKeysPath := filepath.Join(defaultKeystorePath, "validator_keys")
if err := os.MkdirAll(validatorKeysPath, 0o755); err != nil {
return err
}

depositDataPath := filepath.Join(charonPath, "deposit-data.json")
depositDataPathDest := filepath.Join(defaultKeystorePath, "deposit-data.json")
if err := copy.Copy(depositDataPath, depositDataPathDest); err != nil {
return err
}

files, err := os.ReadDir(charonValidatorKeysPath)
if err != nil {
log.Fatal(err)
}
len := len(files)
for i := 0; i < len/2; i++ {
keystorePath := filepath.Join(charonValidatorKeysPath, fmt.Sprintf("keystore-%d.json", i))
validatorPath := filepath.Join(validatorKeysPath, fmt.Sprintf("keystore-%d.json", i))
if err := copy.Copy(keystorePath, validatorPath); err != nil {
return err
}

keystoreTxtPath := filepath.Join(charonValidatorKeysPath, fmt.Sprintf("keystore-%d.txt", i))
keystorePasswordPath := filepath.Join(defaultKeystorePath, fmt.Sprintf("keystore-%d.txt", i))
if err := copy.Copy(keystoreTxtPath, keystorePasswordPath); err != nil {
return err
}
}
if options.ValidatorClient == "prysm" {
keystorePasswordPath := filepath.Join(defaultKeystorePath, "keystore_password.txt")
f, err := os.Create(keystorePasswordPath)
if err != nil {
return err
}
f.WriteString("prysm-validator-secret")
defer f.Close()
}
}

var ctID string
switch options.ValidatorClient {
case "prysm":
prysmCtID, err := setupPrysmValidatorImportContainer(s.dockerClient, s.dockerServiceManager, options)
if err != nil {
return err
prysmCtID := ""
if options.Distributed {
prysmCtID, err = setupPrysmValidatorImportContainerDV(s.dockerClient, s.commandRunner, s.dockerServiceManager, options)
if err != nil {
return err
}
ctID = prysmCtID
} else {
prysmCtID, err := setupPrysmValidatorImportContainer(s.dockerClient, s.dockerServiceManager, options)
if err != nil {
return err
}
ctID = prysmCtID
}
ctID = prysmCtID
case "lodestar":
lodestarCtID, err := setupLodestarValidatorImport(s.dockerClient, s.dockerServiceManager, options)
if err != nil {
Expand Down Expand Up @@ -253,11 +331,33 @@ func setupLodestarValidatorImport(dockerClient client.APIClient, dockerServiceMa
cmd = append(cmd, "--preset", preset)
}
log.Debugf("Creating %s container", validatorImportCtName)
ct, err := dockerClient.ContainerCreate(context.Background(),
&container.Config{
containerConfig := &container.Config{
Image: validatorImage,
Cmd: cmd,
}
if options.Distributed {
containerConfig = &container.Config{
Image: validatorImage,
Cmd: cmd,
},
Entrypoint: []string{
"sh", "-c", `
#!/bin/sh
set -e
for f in /keystore/validator_keys/keystore-*.json; do
echo "Importing key ${f}"
pwdfile="/keystore/$(basename "$f" .json).txt"
echo "Using password file ${pwdfile}"
# Import keystore with password.
node /usr/app/packages/cli/bin/lodestar validator import \
--dataDir="/data" \
--importKeystores="$f" \
--importKeystoresPassword="${pwdfile}"
done
`,
},
}
}
ct, err := dockerClient.ContainerCreate(context.Background(),
containerConfig,
&container.HostConfig{
Mounts: mounts,
VolumesFrom: []string{validatorCtName},
Expand Down Expand Up @@ -437,3 +537,54 @@ func runAndWaitImportKeys(dockerClient client.APIClient, dockerServiceManager Do
}
}
}

func setupPrysmValidatorImportContainerDV(dockerClient client.APIClient, commandRunner commands.CommandRunner, serviceManager DockerServiceManager, options ImportValidatorKeysOptions) (string, error) {
var (
validatorCtName = services.ContainerNameWithTag(services.DefaultSedgeValidatorClient, options.ContainerTag)
validatorImportCtName = services.ContainerNameWithTag(services.ServiceCtValidatorImport, options.ContainerTag)
)
// Init build context
contextDir, err := prysm.InitContext()
if err != nil {
return "", err
}
// Build image
buildCmd := commandRunner.BuildDockerBuildCMD(commands.DockerBuildOptions{
Path: contextDir,
Tag: "sedge/prysm-import-teku",
Args: map[string]string{
"NETWORK": options.Network,
"PRYSM_VERSION": configs.ClientImages.Validator.Prysm.String(),
},
})
log.Infof(configs.RunningCommand, buildCmd.Cmd)
if _, _, err := commandRunner.RunCMD(buildCmd); err != nil {
return "", err
}
// Mounts
mounts := []mount.Mount{
{
Type: mount.TypeBind,
Source: options.From,
Target: "/keystore",
},
}
log.Debugf("Creating %s container", validatorImportCtName)
containerConfig := &container.Config{
Image: "sedge/prysm-import-teku",
}
ct, err := dockerClient.ContainerCreate(context.Background(),
containerConfig,
&container.HostConfig{
Mounts: mounts,
VolumesFrom: []string{validatorCtName},
},
&network.NetworkingConfig{},
&v1.Platform{},
validatorImportCtName,
)
if err != nil {
return "", err
}
return ct.ID, nil
}
Loading
Loading