mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Various code inspection resolutions (#7438)
* remove unused code
* remove defer use in loop
* Remove unused methods and constants
* gofmt and gaz
* nilness check
* remove unused args
* Add TODO for refactoring subscribeWithBase to remove unused arg. It seems too involved to include in this sweeping PR. https://github.com/prysmaticlabs/prysm/issues/7437
* replace empty slice declaration
* Remove unnecessary type conversions
* remove redundant type declaration
* rename receivers to be consistent
* Remove bootnode query tool. It is now obsolete by discv5
* Remove relay node. It is no longer used or supported
* Revert "Remove relay node. It is no longer used or supported"
This reverts commit 4bd7717334.
* Delete unused test directory
* Delete unsupported gcp startup script
* Delete old k8s script
* build fixes
* fix build
* go mod tidy
* revert slasher/db/kv/block_header.go
* fix build
* remove redundant nil check
* combine func args
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
This commit is contained in:
@@ -69,7 +69,7 @@ func CreateAccount(ctx context.Context, cfg *CreateAccountConfig) error {
|
||||
if !ok {
|
||||
return errors.New("not a derived keymanager")
|
||||
}
|
||||
startNum := km.NextAccountNumber(ctx)
|
||||
startNum := km.NextAccountNumber()
|
||||
if cfg.NumAccounts == 1 {
|
||||
if _, _, err := km.CreateAccount(ctx); err != nil {
|
||||
return errors.Wrap(err, "could not create account in wallet")
|
||||
|
||||
@@ -72,7 +72,7 @@ type passwordReader struct {
|
||||
}
|
||||
|
||||
// Instead of forwarding the read request to terminal.ReadPassword(), we simply provide a canned response.
|
||||
func (p *passwordReader) passwordReaderFunc(file *os.File) ([]byte, error) {
|
||||
func (p *passwordReader) passwordReaderFunc(_ *os.File) ([]byte, error) {
|
||||
p.counter--
|
||||
if p.counter <= 0 {
|
||||
log.Fatalln("Too many password attempts using passwordReaderFunc()")
|
||||
|
||||
@@ -254,7 +254,7 @@ func importPrivateKeyAsAccount(cliCtx *cli.Context, wallet *wallet.Wallet, keyma
|
||||
return nil
|
||||
}
|
||||
|
||||
func readKeystoreFile(ctx context.Context, keystoreFilePath string) (*v2keymanager.Keystore, error) {
|
||||
func readKeystoreFile(_ context.Context, keystoreFilePath string) (*v2keymanager.Keystore, error) {
|
||||
keystoreBytes, err := ioutil.ReadFile(keystoreFilePath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not read keystore file")
|
||||
|
||||
@@ -128,7 +128,7 @@ func listDerivedKeymanagerAccounts(
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not fetch validating public keys")
|
||||
}
|
||||
nextAccountNumber := keymanager.NextAccountNumber(ctx)
|
||||
nextAccountNumber := keymanager.NextAccountNumber()
|
||||
currentAccountNumber := nextAccountNumber
|
||||
if nextAccountNumber > 0 {
|
||||
currentAccountNumber--
|
||||
|
||||
@@ -27,7 +27,7 @@ type mockRemoteKeymanager struct {
|
||||
opts *remote.KeymanagerOpts
|
||||
}
|
||||
|
||||
func (m *mockRemoteKeymanager) FetchValidatingPublicKeys(ctx context.Context) ([][48]byte, error) {
|
||||
func (m *mockRemoteKeymanager) FetchValidatingPublicKeys(_ context.Context) ([][48]byte, error) {
|
||||
return m.publicKeys, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@ const (
|
||||
SelectAccountsDeletePromptText = "Select the account(s) you would like to delete"
|
||||
// SelectAccountsBackupPromptText --
|
||||
SelectAccountsBackupPromptText = "Select the account(s) you wish to backup"
|
||||
// SelectAccountsDepositPromptText --
|
||||
SelectAccountsDepositPromptText = "Select the validating public keys you wish to submit deposits for"
|
||||
// SelectAccountsVoluntaryExitPromptText --
|
||||
SelectAccountsVoluntaryExitPromptText = "Select the account(s) on which you wish to perform a voluntary exit"
|
||||
)
|
||||
@@ -64,23 +62,6 @@ func InputDirectory(cliCtx *cli.Context, promptText string, flag *cli.StringFlag
|
||||
return fileutil.ExpandPath(inputtedDir)
|
||||
}
|
||||
|
||||
// InputWeakPassword from the cli.
|
||||
func InputWeakPassword(cliCtx *cli.Context, passwordFileFlag *cli.StringFlag, promptText string) (string, error) {
|
||||
if cliCtx.IsSet(passwordFileFlag.Name) {
|
||||
passwordFilePathInput := cliCtx.String(passwordFileFlag.Name)
|
||||
passwordFilePath, err := fileutil.ExpandPath(passwordFilePathInput)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "could not determine absolute path of password file")
|
||||
}
|
||||
return passwordFilePath, nil
|
||||
}
|
||||
walletPasswordFilePath, err := promptutil.PasswordPrompt(promptText, promptutil.NotEmpty)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("could not read account password: %v", err)
|
||||
}
|
||||
return walletPasswordFilePath, nil
|
||||
}
|
||||
|
||||
// InputRemoteKeymanagerConfig via the cli.
|
||||
func InputRemoteKeymanagerConfig(cliCtx *cli.Context) (*remote.KeymanagerOpts, error) {
|
||||
addr := cliCtx.String(flags.GrpcRemoteAddressFlag.Name)
|
||||
|
||||
@@ -56,7 +56,7 @@ func (m *Wallet) SetPassword(newPass string) {
|
||||
}
|
||||
|
||||
// WriteFileAtPath --
|
||||
func (m *Wallet) WriteFileAtPath(ctx context.Context, pathName string, fileName string, data []byte) error {
|
||||
func (m *Wallet) WriteFileAtPath(_ context.Context, pathName, fileName string, data []byte) error {
|
||||
m.lock.Lock()
|
||||
defer m.lock.Unlock()
|
||||
if m.Files[pathName] == nil {
|
||||
@@ -67,7 +67,7 @@ func (m *Wallet) WriteFileAtPath(ctx context.Context, pathName string, fileName
|
||||
}
|
||||
|
||||
// ReadFileAtPath --
|
||||
func (m *Wallet) ReadFileAtPath(ctx context.Context, pathName string, fileName string) ([]byte, error) {
|
||||
func (m *Wallet) ReadFileAtPath(_ context.Context, pathName, fileName string) ([]byte, error) {
|
||||
m.lock.RLock()
|
||||
defer m.lock.RUnlock()
|
||||
for f, v := range m.Files[pathName] {
|
||||
@@ -79,14 +79,14 @@ func (m *Wallet) ReadFileAtPath(ctx context.Context, pathName string, fileName s
|
||||
}
|
||||
|
||||
// ReadEncryptedSeedFromDisk --
|
||||
func (m *Wallet) ReadEncryptedSeedFromDisk(ctx context.Context) (io.ReadCloser, error) {
|
||||
func (m *Wallet) ReadEncryptedSeedFromDisk(_ context.Context) (io.ReadCloser, error) {
|
||||
m.lock.Lock()
|
||||
defer m.lock.Unlock()
|
||||
return ioutil.NopCloser(bytes.NewReader(m.EncryptedSeedFile)), nil
|
||||
}
|
||||
|
||||
// WriteEncryptedSeedToDisk --
|
||||
func (m *Wallet) WriteEncryptedSeedToDisk(ctx context.Context, encoded []byte) error {
|
||||
func (m *Wallet) WriteEncryptedSeedToDisk(_ context.Context, encoded []byte) error {
|
||||
m.lock.Lock()
|
||||
defer m.lock.Unlock()
|
||||
m.EncryptedSeedFile = encoded
|
||||
@@ -94,6 +94,6 @@ func (m *Wallet) WriteEncryptedSeedToDisk(ctx context.Context, encoded []byte) e
|
||||
}
|
||||
|
||||
// InitializeKeymanager --
|
||||
func (m *Wallet) InitializeKeymanager(ctx context.Context, skipMnemonicConfirm bool) (v2keymanager.IKeymanager, error) {
|
||||
func (m *Wallet) InitializeKeymanager(_ context.Context, _ bool) (v2keymanager.IKeymanager, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -55,10 +55,6 @@ var (
|
||||
ErrNoWalletFound = errors.New(
|
||||
"no wallet found at path, please create a new wallet using `./prysm.sh validator wallet-v2 create`",
|
||||
)
|
||||
// ErrWalletExists is an error returned when a wallet already exists in the path provided.
|
||||
ErrWalletExists = errors.New("you already have a wallet at the specified path. You can " +
|
||||
"edit your wallet configuration by running ./prysm.sh validator wallet-v2 edit-config",
|
||||
)
|
||||
// KeymanagerKindSelections as friendly text.
|
||||
KeymanagerKindSelections = map[v2keymanager.Kind]string{
|
||||
v2keymanager.Derived: "HD Wallet (Recommended)",
|
||||
@@ -216,7 +212,7 @@ func OpenWalletOrElseCli(cliCtx *cli.Context, otherwise func(cliCtx *cli.Context
|
||||
// OpenWallet instantiates a wallet from a specified path. It checks the
|
||||
// type of keymanager associated with the wallet by reading files in the wallet
|
||||
// path, if applicable. If a wallet does not exist, returns an appropriate error.
|
||||
func OpenWallet(ctx context.Context, cfg *Config) (*Wallet, error) {
|
||||
func OpenWallet(_ context.Context, cfg *Config) (*Wallet, error) {
|
||||
exists, err := Exists(cfg.WalletDir)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, CheckExistsErrMsg)
|
||||
@@ -350,7 +346,7 @@ func (w *Wallet) InitializeKeymanager(
|
||||
}
|
||||
|
||||
// WriteFileAtPath within the wallet directory given the desired path, filename, and raw data.
|
||||
func (w *Wallet) WriteFileAtPath(ctx context.Context, filePath string, fileName string, data []byte) error {
|
||||
func (w *Wallet) WriteFileAtPath(_ context.Context, filePath, fileName string, data []byte) error {
|
||||
accountPath := filepath.Join(w.accountsPath, filePath)
|
||||
if err := os.MkdirAll(accountPath, os.ModePerm); err != nil {
|
||||
return errors.Wrapf(err, "could not create path: %s", accountPath)
|
||||
@@ -367,7 +363,7 @@ func (w *Wallet) WriteFileAtPath(ctx context.Context, filePath string, fileName
|
||||
}
|
||||
|
||||
// ReadFileAtPath within the wallet directory given the desired path and filename.
|
||||
func (w *Wallet) ReadFileAtPath(ctx context.Context, filePath string, fileName string) ([]byte, error) {
|
||||
func (w *Wallet) ReadFileAtPath(_ context.Context, filePath, fileName string) ([]byte, error) {
|
||||
accountPath := filepath.Join(w.accountsPath, filePath)
|
||||
if err := os.MkdirAll(accountPath, os.ModePerm); err != nil {
|
||||
return nil, errors.Wrapf(err, "could not create path: %s", accountPath)
|
||||
@@ -389,7 +385,7 @@ func (w *Wallet) ReadFileAtPath(ctx context.Context, filePath string, fileName s
|
||||
|
||||
// FileNameAtPath return the full file name for the requested file. It allows for finding the file
|
||||
// with a regex pattern.
|
||||
func (w *Wallet) FileNameAtPath(ctx context.Context, filePath string, fileName string) (string, error) {
|
||||
func (w *Wallet) FileNameAtPath(_ context.Context, filePath, fileName string) (string, error) {
|
||||
accountPath := filepath.Join(w.accountsPath, filePath)
|
||||
if err := os.MkdirAll(accountPath, os.ModePerm); err != nil {
|
||||
return "", errors.Wrapf(err, "could not create path: %s", accountPath)
|
||||
@@ -408,7 +404,7 @@ func (w *Wallet) FileNameAtPath(ctx context.Context, filePath string, fileName s
|
||||
|
||||
// ReadKeymanagerConfigFromDisk opens a keymanager config file
|
||||
// for reading if it exists at the wallet path.
|
||||
func (w *Wallet) ReadKeymanagerConfigFromDisk(ctx context.Context) (io.ReadCloser, error) {
|
||||
func (w *Wallet) ReadKeymanagerConfigFromDisk(_ context.Context) (io.ReadCloser, error) {
|
||||
configFilePath := filepath.Join(w.accountsPath, KeymanagerConfigFileName)
|
||||
if !fileutil.FileExists(configFilePath) {
|
||||
return nil, fmt.Errorf("no keymanager config file found at path: %s", w.accountsPath)
|
||||
@@ -420,7 +416,7 @@ func (w *Wallet) ReadKeymanagerConfigFromDisk(ctx context.Context) (io.ReadClose
|
||||
|
||||
// LockWalletConfigFile lock read and write to wallet file in order to prevent
|
||||
// two validators from using the same keys.
|
||||
func (w *Wallet) LockWalletConfigFile(ctx context.Context) error {
|
||||
func (w *Wallet) LockWalletConfigFile(_ context.Context) error {
|
||||
fileLock := flock.New(w.configFilePath)
|
||||
locked, err := fileLock.TryLock()
|
||||
if err != nil {
|
||||
@@ -444,7 +440,7 @@ func (w *Wallet) UnlockWalletConfigFile() error {
|
||||
|
||||
// WriteKeymanagerConfigToDisk takes an encoded keymanager config file
|
||||
// and writes it to the wallet path.
|
||||
func (w *Wallet) WriteKeymanagerConfigToDisk(ctx context.Context, encoded []byte) error {
|
||||
func (w *Wallet) WriteKeymanagerConfigToDisk(_ context.Context, encoded []byte) error {
|
||||
configFilePath := filepath.Join(w.accountsPath, KeymanagerConfigFileName)
|
||||
// Write the config file to disk.
|
||||
if err := ioutil.WriteFile(configFilePath, encoded, params.BeaconIoConfig().ReadWritePermissions); err != nil {
|
||||
@@ -456,7 +452,7 @@ func (w *Wallet) WriteKeymanagerConfigToDisk(ctx context.Context, encoded []byte
|
||||
|
||||
// ReadEncryptedSeedFromDisk reads the encrypted wallet seed configuration from
|
||||
// within the wallet path.
|
||||
func (w *Wallet) ReadEncryptedSeedFromDisk(ctx context.Context) (io.ReadCloser, error) {
|
||||
func (w *Wallet) ReadEncryptedSeedFromDisk(_ context.Context) (io.ReadCloser, error) {
|
||||
configFilePath := filepath.Join(w.accountsPath, derived.EncryptedSeedFileName)
|
||||
if !fileutil.FileExists(configFilePath) {
|
||||
return nil, fmt.Errorf("no encrypted seed file found at path: %s", w.accountsPath)
|
||||
@@ -466,7 +462,7 @@ func (w *Wallet) ReadEncryptedSeedFromDisk(ctx context.Context) (io.ReadCloser,
|
||||
|
||||
// WriteEncryptedSeedToDisk writes the encrypted wallet seed configuration
|
||||
// within the wallet path.
|
||||
func (w *Wallet) WriteEncryptedSeedToDisk(ctx context.Context, encoded []byte) error {
|
||||
func (w *Wallet) WriteEncryptedSeedToDisk(_ context.Context, encoded []byte) error {
|
||||
seedFilePath := filepath.Join(w.accountsPath, derived.EncryptedSeedFileName)
|
||||
// Write the config file to disk.
|
||||
if err := ioutil.WriteFile(seedFilePath, encoded, params.BeaconIoConfig().ReadWritePermissions); err != nil {
|
||||
@@ -477,7 +473,7 @@ func (w *Wallet) WriteEncryptedSeedToDisk(ctx context.Context, encoded []byte) e
|
||||
}
|
||||
|
||||
// SaveHashedPassword to disk for the wallet.
|
||||
func (w *Wallet) SaveHashedPassword(ctx context.Context) error {
|
||||
func (w *Wallet) SaveHashedPassword(_ context.Context) error {
|
||||
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(w.walletPassword), hashCost)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not generate hashed password")
|
||||
|
||||
@@ -31,8 +31,6 @@ import (
|
||||
|
||||
const (
|
||||
walletDirName = "wallet"
|
||||
passwordDirName = "walletpasswords"
|
||||
exportDirName = "export"
|
||||
passwordFileName = "password.txt"
|
||||
password = "OhWOWthisisatest42!$"
|
||||
mnemonicFileName = "mnemonic.txt"
|
||||
|
||||
Reference in New Issue
Block a user