Skip to content

Commit

Permalink
Merge pull request #226 from stader-labs/ssv_mirgration
Browse files Browse the repository at this point in the history
  • Loading branch information
batphonghan authored Oct 26, 2024
2 parents 8252c9c + 72f6611 commit 7507222
Show file tree
Hide file tree
Showing 24 changed files with 151 additions and 76 deletions.
1 change: 0 additions & 1 deletion install/scripts/start-ec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ if [ "$CLIENT" = "besu" ]; then
--rpc-ws-port=${EC_WS_PORT:-8546} \
--host-allowlist=* \
--rpc-http-max-active-connections=1024 \
--data-storage-format=bonsai \
--nat-method=docker \
--p2p-host=$EXTERNAL_IP \
--engine-rpc-enabled \
Expand Down
1 change: 1 addition & 0 deletions shared/services/beacon/client/std-http-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"

"net/http"
"strconv"
"strings"
Expand Down
4 changes: 2 additions & 2 deletions shared/services/config/config-legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package config

import (
"fmt"
"io/ioutil"

"math/big"
"os"
"strconv"
Expand Down Expand Up @@ -301,7 +301,7 @@ func Load(c *cli.Context) (LegacyStaderConfig, error) {
func loadFile(path string, required bool) (LegacyStaderConfig, error) {

// Read file; squelch not found errors if file is optional
bytes, err := ioutil.ReadFile(path)
bytes, err := os.ReadFile(path)
if err != nil {
if required {
return LegacyStaderConfig{}, fmt.Errorf("Could not find config file at %s: %w", path, err)
Expand Down
4 changes: 2 additions & 2 deletions shared/services/config/stader-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package config

import (
"fmt"
"io/ioutil"

"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -149,7 +149,7 @@ func LoadFromFile(path string) (*StaderConfig, error) {
}

// Read the file
configBytes, err := ioutil.ReadFile(path)
configBytes, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("could not read Stader settings file at %s: %w", shellescape.Quote(path), err)
}
Expand Down
24 changes: 24 additions & 0 deletions shared/services/config/stadernode-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ type StaderNodeConfig struct {
// URL for an EC with archive mode, for manual rewards tree generation
ArchiveECUrl config.Parameter `yaml:"archiveEcUrl,omitempty"`

// The path of the data folder where everything is stored
SsvMigration config.Parameter `yaml:"ssvMigration,omitempty"`

///////////////////////////
// Non-editable settings //
///////////////////////////
Expand Down Expand Up @@ -231,6 +234,18 @@ func NewStadernodeConfig(cfg *StaderConfig) *StaderNodeConfig {
OverwriteOnUpgrade: false,
},

SsvMigration: config.Parameter{
ID: "ssvMigration",
Name: "Enable Ssv migration mode",
Description: "Enable this for failsafe mechanisms during Migration to SSV",
Type: config.ParameterType_Bool,
Default: map[config.Network]interface{}{config.Network_All: false},
AffectsContainers: []config.ContainerID{config.ContainerID_Validator},
EnvironmentVariables: []string{},
CanBeBlank: true,
OverwriteOnUpgrade: false,
},

beaconChainUrl: map[config.Network]string{
config.Network_Mainnet: "https://beaconcha.in",
config.Network_Holesky: "https://holesky.beaconcha.in",
Expand Down Expand Up @@ -278,6 +293,7 @@ func (cfg *StaderNodeConfig) GetParameters() []*config.Parameter {
&cfg.PriorityFee,
&cfg.TxFeeCap,
&cfg.ArchiveECUrl,
&cfg.SsvMigration,
}
}

Expand Down Expand Up @@ -356,6 +372,14 @@ func (cfg *StaderNodeConfig) GetValidatorKeychainPath() string {
return filepath.Join(DaemonDataPath, "validators")
}

func (cfg *StaderNodeConfig) GetPresignKeychainPath() string {
if cfg.parent.IsNativeMode {
return filepath.Join(cfg.DataPath.Value.(string), "presign")
}

return filepath.Join(DaemonDataPath, "presign")
}

func (cfg *StaderNodeConfig) GetWalletPathInCLI() string {
return filepath.Join(cfg.DataPath.Value.(string), "wallet")
}
Expand Down
1 change: 1 addition & 0 deletions shared/services/gas/etherchain/etherchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"

"math/big"
"net/http"
)
Expand Down
1 change: 1 addition & 0 deletions shared/services/gas/etherscan/etherscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"

"net/http"
"strconv"
)
Expand Down
8 changes: 4 additions & 4 deletions shared/services/passwords/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package passwords
import (
"errors"
"fmt"
"io/ioutil"

"os"
)

Expand All @@ -46,15 +46,15 @@ func NewPasswordManager(passwordPath string) *PasswordManager {

// Check if the password has been set
func (pm *PasswordManager) IsPasswordSet() bool {
_, err := ioutil.ReadFile(pm.passwordPath)
_, err := os.ReadFile(pm.passwordPath)
return (err == nil)
}

// Get the password
func (pm *PasswordManager) GetPassword() (string, error) {

// Read from disk
password, err := ioutil.ReadFile(pm.passwordPath)
password, err := os.ReadFile(pm.passwordPath)
if err != nil {
return "", fmt.Errorf("Could not read password from disk: %w", err)
}
Expand All @@ -78,7 +78,7 @@ func (pm *PasswordManager) SetPassword(password string) error {
}

// Write to disk
if err := ioutil.WriteFile(pm.passwordPath, []byte(password), FileMode); err != nil {
if err := os.WriteFile(pm.passwordPath, []byte(password), FileMode); err != nil {
return fmt.Errorf("Could not write password to disk: %w", err)
}

Expand Down
30 changes: 24 additions & 6 deletions shared/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,17 +513,35 @@ func getWallet(c *cli.Context, cfg *config.StaderConfig, pm *passwords.PasswordM
return
}

// Keystores
lighthouseKeystore := lhkeystore.NewKeystore(os.ExpandEnv(cfg.StaderNode.GetValidatorKeychainPath()), pm)
nimbusKeystore := nmkeystore.NewKeystore(os.ExpandEnv(cfg.StaderNode.GetValidatorKeychainPath()), pm)
prysmKeystore := prkeystore.NewKeystore(os.ExpandEnv(cfg.StaderNode.GetValidatorKeychainPath()), pm)
tekuKeystore := tkkeystore.NewKeystore(os.ExpandEnv(cfg.StaderNode.GetValidatorKeychainPath()), pm)
lodestarKeystore := lokeystore.NewKeystore(os.ExpandEnv(cfg.StaderNode.GetValidatorKeychainPath()), pm)
validatorPath := os.ExpandEnv(cfg.StaderNode.GetValidatorKeychainPath())

// Keystores in validator
lighthouseKeystore := lhkeystore.NewKeystore(validatorPath, pm)
nimbusKeystore := nmkeystore.NewKeystore(validatorPath, pm)
prysmKeystore := prkeystore.NewKeystore(validatorPath, pm)
tekuKeystore := tkkeystore.NewKeystore(validatorPath, pm)
lodestarKeystore := lokeystore.NewKeystore(validatorPath, pm)

nodeWallet.AddKeystore("lighthouse", lighthouseKeystore)
nodeWallet.AddKeystore("nimbus", nimbusKeystore)
nodeWallet.AddKeystore("prysm", prysmKeystore)
nodeWallet.AddKeystore("teku", tekuKeystore)
nodeWallet.AddKeystore("lodestar", lodestarKeystore)

presignPath := os.ExpandEnv(cfg.StaderNode.GetPresignKeychainPath())

// Keystores in presign
lighthousePresignKeystore := lhkeystore.NewKeystore(presignPath, pm)
nimbusPresignKeystore := nmkeystore.NewKeystore(presignPath, pm)
prysmPresignKeystore := prkeystore.NewKeystore(presignPath, pm)
tekuPresignKeystore := tkkeystore.NewKeystore(presignPath, pm)
lodestarPresignKeystore := lokeystore.NewKeystore(presignPath, pm)

nodeWallet.AddPresignKeystore("lighthouse", lighthousePresignKeystore)
nodeWallet.AddPresignKeystore("nimbus", nimbusPresignKeystore)
nodeWallet.AddPresignKeystore("prysm", prysmPresignKeystore)
nodeWallet.AddPresignKeystore("teku", tekuPresignKeystore)
nodeWallet.AddPresignKeystore("lodestar", lodestarPresignKeystore)
})
return nodeWallet, err
}
Expand Down
45 changes: 24 additions & 21 deletions shared/services/stader/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"math/big"
"net"
Expand Down Expand Up @@ -292,7 +291,7 @@ func (c *Client) UpdatePrometheusConfiguration(settings map[string]string) error
}

// Write the actual Prometheus config file
err = ioutil.WriteFile(prometheusConfigPath, contents, 0664)
err = os.WriteFile(prometheusConfigPath, contents, 0664)
if err != nil {
return fmt.Errorf("Could not write Prometheus config file to %s: %w", shellescape.Quote(prometheusConfigPath), err)
}
Expand Down Expand Up @@ -1421,7 +1420,7 @@ func (c *Client) deployTemplates(cfg *config.StaderConfig, staderDir string, set
return []string{}, fmt.Errorf("error reading and substituting API container template: %w", err)
}
apiComposePath := filepath.Join(runtimeFolder, config.ApiContainerName+composeFileSuffix)
err = ioutil.WriteFile(apiComposePath, contents, 0664)
err = os.WriteFile(apiComposePath, contents, 0664)
if err != nil {
return []string{}, fmt.Errorf("could not write API container file to %s: %w", apiComposePath, err)
}
Expand All @@ -1434,7 +1433,7 @@ func (c *Client) deployTemplates(cfg *config.StaderConfig, staderDir string, set
return []string{}, fmt.Errorf("error reading and substituting node container template: %w", err)
}
nodeComposePath := filepath.Join(runtimeFolder, config.NodeContainerName+composeFileSuffix)
err = ioutil.WriteFile(nodeComposePath, contents, 0664)
err = os.WriteFile(nodeComposePath, contents, 0664)
if err != nil {
return []string{}, fmt.Errorf("could not write node container file to %s: %w", nodeComposePath, err)
}
Expand All @@ -1447,25 +1446,29 @@ func (c *Client) deployTemplates(cfg *config.StaderConfig, staderDir string, set
return []string{}, fmt.Errorf("error reading and substituting guardian container template: %w", err)
}
guardianComposePath := filepath.Join(runtimeFolder, config.GuardianContainerName+composeFileSuffix)
err = ioutil.WriteFile(guardianComposePath, contents, 0664)
err = os.WriteFile(guardianComposePath, contents, 0664)
if err != nil {
return []string{}, fmt.Errorf("could not write guardian container file to %s: %w", guardianComposePath, err)
}
deployedContainers = append(deployedContainers, guardianComposePath)
deployedContainers = append(deployedContainers, filepath.Join(overrideFolder, config.GuardianContainerName+composeFileSuffix))

// Validator
contents, err = envsubst.ReadFile(filepath.Join(templatesFolder, config.ValidatorContainerName+templateSuffix))
if err != nil {
return []string{}, fmt.Errorf("error reading and substituting validator container template: %w", err)
}
validatorComposePath := filepath.Join(runtimeFolder, config.ValidatorContainerName+composeFileSuffix)
err = ioutil.WriteFile(validatorComposePath, contents, 0664)
if err != nil {
return []string{}, fmt.Errorf("could not write validator container file to %s: %w", validatorComposePath, err)

ssvMigration, _ := cfg.StaderNode.SsvMigration.Value.(bool)
if !ssvMigration {
contents, err = envsubst.ReadFile(filepath.Join(templatesFolder, config.ValidatorContainerName+templateSuffix))
if err != nil {
return []string{}, fmt.Errorf("error reading and substituting validator container template: %w", err)
}
validatorComposePath := filepath.Join(runtimeFolder, config.ValidatorContainerName+composeFileSuffix)
err = os.WriteFile(validatorComposePath, contents, 0664)
if err != nil {
return []string{}, fmt.Errorf("could not write validator container file to %s: %w", validatorComposePath, err)
}
deployedContainers = append(deployedContainers, validatorComposePath)
deployedContainers = append(deployedContainers, filepath.Join(overrideFolder, config.ValidatorContainerName+composeFileSuffix))
}
deployedContainers = append(deployedContainers, validatorComposePath)
deployedContainers = append(deployedContainers, filepath.Join(overrideFolder, config.ValidatorContainerName+composeFileSuffix))

// Check the EC mode to see if it needs to be deployed
if cfg.ExecutionClientMode.Value.(cfgtypes.Mode) == cfgtypes.Mode_Local {
Expand All @@ -1474,7 +1477,7 @@ func (c *Client) deployTemplates(cfg *config.StaderConfig, staderDir string, set
return []string{}, fmt.Errorf("error reading and substituting execution client container template: %w", err)
}
eth1ComposePath := filepath.Join(runtimeFolder, config.Eth1ContainerName+composeFileSuffix)
err = ioutil.WriteFile(eth1ComposePath, contents, 0664)
err = os.WriteFile(eth1ComposePath, contents, 0664)
if err != nil {
return []string{}, fmt.Errorf("could not write execution client container file to %s: %w", eth1ComposePath, err)
}
Expand All @@ -1489,7 +1492,7 @@ func (c *Client) deployTemplates(cfg *config.StaderConfig, staderDir string, set
return []string{}, fmt.Errorf("error reading and substituting consensus client container template: %w", err)
}
eth2ComposePath := filepath.Join(runtimeFolder, config.Eth2ContainerName+composeFileSuffix)
err = ioutil.WriteFile(eth2ComposePath, contents, 0664)
err = os.WriteFile(eth2ComposePath, contents, 0664)
if err != nil {
return []string{}, fmt.Errorf("could not write consensus client container file to %s: %w", eth2ComposePath, err)
}
Expand All @@ -1505,7 +1508,7 @@ func (c *Client) deployTemplates(cfg *config.StaderConfig, staderDir string, set
return []string{}, fmt.Errorf("error reading and substituting Grafana container template: %w", err)
}
grafanaComposePath := filepath.Join(runtimeFolder, config.GrafanaContainerName+composeFileSuffix)
err = ioutil.WriteFile(grafanaComposePath, contents, 0664)
err = os.WriteFile(grafanaComposePath, contents, 0664)
if err != nil {
return []string{}, fmt.Errorf("could not write Grafana container file to %s: %w", grafanaComposePath, err)
}
Expand All @@ -1517,7 +1520,7 @@ func (c *Client) deployTemplates(cfg *config.StaderConfig, staderDir string, set
return []string{}, fmt.Errorf("error reading and substituting Node Exporter container template: %w", err)
}
exporterComposePath := filepath.Join(runtimeFolder, config.ExporterContainerName+composeFileSuffix)
err = ioutil.WriteFile(exporterComposePath, contents, 0664)
err = os.WriteFile(exporterComposePath, contents, 0664)
if err != nil {
return []string{}, fmt.Errorf("could not write Node Exporter container file to %s: %w", exporterComposePath, err)
}
Expand All @@ -1530,7 +1533,7 @@ func (c *Client) deployTemplates(cfg *config.StaderConfig, staderDir string, set
return []string{}, fmt.Errorf("error reading and substituting Prometheus container template: %w", err)
}
prometheusComposePath := filepath.Join(runtimeFolder, config.PrometheusContainerName+composeFileSuffix)
err = ioutil.WriteFile(prometheusComposePath, contents, 0664)
err = os.WriteFile(prometheusComposePath, contents, 0664)
if err != nil {
return []string{}, fmt.Errorf("could not write Prometheus container file to %s: %w", prometheusComposePath, err)
}
Expand All @@ -1545,7 +1548,7 @@ func (c *Client) deployTemplates(cfg *config.StaderConfig, staderDir string, set
return []string{}, fmt.Errorf("error reading and substituting MEV-Boost container template: %w", err)
}
mevBoostComposePath := filepath.Join(runtimeFolder, config.MevBoostContainerName+composeFileSuffix)
err = ioutil.WriteFile(mevBoostComposePath, contents, 0664)
err = os.WriteFile(mevBoostComposePath, contents, 0664)
if err != nil {
return []string{}, fmt.Errorf("could not write MEV-Boost container file to %s: %w", mevBoostComposePath, err)
}
Expand Down
6 changes: 3 additions & 3 deletions shared/services/stader/fee-recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package stader
import (
"fmt"
"io/fs"
"io/ioutil"

"os"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -49,7 +49,7 @@ func CheckFeeRecipientFile(feeRecipient common.Address, cfg *config.StaderConfig

// Compare the file contents with the expected string
expectedString := getFeeRecipientFileContents(feeRecipient, cfg)
bytes, err := ioutil.ReadFile(path)
bytes, err := os.ReadFile(path)
if err != nil {
return false, false, fmt.Errorf("error reading fee recipient file: %w", err)
}
Expand All @@ -72,7 +72,7 @@ func UpdateFeeRecipientFile(feeRecipient common.Address, cfg *config.StaderConfi

// Write the file
path := cfg.StaderNode.GetFeeRecipientFilePath()
err := ioutil.WriteFile(path, bytes, FileMode)
err := os.WriteFile(path, bytes, FileMode)
if err != nil {
return fmt.Errorf("error writing fee recipient file: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions shared/services/stader/legacy-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package stader

import (
"fmt"
"io/ioutil"
"os"

"github.com/alessio/shellescape"
"github.com/mitchellh/go-homedir"
Expand Down Expand Up @@ -66,7 +66,7 @@ func (c *Client) loadConfig_Legacy(path string) (config.LegacyStaderConfig, erro
if err != nil {
return config.LegacyStaderConfig{}, err
}
configBytes, err := ioutil.ReadFile(expandedPath)
configBytes, err := os.ReadFile(expandedPath)
if err != nil {
return config.LegacyStaderConfig{}, fmt.Errorf("Could not read Stader config at %s: %w", shellescape.Quote(path), err)
}
Expand Down
5 changes: 2 additions & 3 deletions shared/services/wallet/keystore/lighthouse/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package lighthouse
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -118,7 +117,7 @@ func (ks *Keystore) StoreValidatorKey(key *eth2types.BLSPrivateKey, derivationPa
}

// Write secret to disk
if err := ioutil.WriteFile(secretFilePath, []byte(password), FileMode); err != nil {
if err := os.WriteFile(secretFilePath, []byte(password), FileMode); err != nil {
return fmt.Errorf("Could not write validator secret to disk: %w", err)
}

Expand All @@ -131,7 +130,7 @@ func (ks *Keystore) StoreValidatorKey(key *eth2types.BLSPrivateKey, derivationPa
}

// Write key store to disk
if err := ioutil.WriteFile(keyFilePath, keyStoreBytes, FileMode); err != nil {
if err := os.WriteFile(keyFilePath, keyStoreBytes, FileMode); err != nil {
return fmt.Errorf("Could not write validator key to disk: %w", err)
}

Expand Down
Loading

0 comments on commit 7507222

Please sign in to comment.