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

Web3signer: persistent public keys #13682

Merged
merged 119 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
c1ce331
WIP
james-prysm Mar 1, 2024
b1ae1c6
broken and still wip
james-prysm Mar 1, 2024
298dad3
more wip improving saving
james-prysm Mar 1, 2024
bba48fc
Merge branch 'develop' into persistent-web3signer
james-prysm Mar 5, 2024
6cbf248
Merge branch 'develop' into persistent-web3signer
james-prysm Mar 12, 2024
10d68b6
Merge branch 'develop' into persistent-web3signer
james-prysm Mar 22, 2024
7d9dc12
wip
james-prysm Mar 25, 2024
7839c7e
Merge branch 'develop' into persistent-web3signer
james-prysm Mar 26, 2024
8e6e807
removing cyclic dependency
james-prysm Mar 26, 2024
9a28ce1
gaz
james-prysm Mar 26, 2024
f593585
fixes
james-prysm Mar 26, 2024
41ee265
fixing more tests and how files load
james-prysm Mar 27, 2024
88dd412
Merge branch 'develop' into persistent-web3signer
james-prysm Mar 27, 2024
649b85b
fixing wallet tests
james-prysm Mar 27, 2024
6836cb4
Merge branch 'develop' into persistent-web3signer
james-prysm Mar 28, 2024
bb0b19f
fixing test
james-prysm Mar 28, 2024
79fdecb
updating keymanager tests
james-prysm Mar 29, 2024
195db90
Merge branch 'develop' into persistent-web3signer
james-prysm Mar 29, 2024
b9fbdc0
Merge branch 'develop' into persistent-web3signer
james-prysm Mar 29, 2024
164057e
improving how the web3signer keymanager works
james-prysm Mar 29, 2024
aa5e389
WIP
james-prysm Mar 29, 2024
34bd671
updated keymanager to read from file
james-prysm Apr 1, 2024
cb8d1a9
gaz
james-prysm Apr 1, 2024
9fe695a
reuse readkeyfile function and add in duplicate keys check
james-prysm Apr 1, 2024
e72c7ee
adding in locks to increase safety
james-prysm Apr 1, 2024
769c660
Merge branch 'develop' into persistent-web3signer
james-prysm Apr 1, 2024
ef5f310
Merge branch 'develop' into persistent-web3signer
james-prysm Apr 1, 2024
94976cd
refactored how saving keys work, more tests needed:
james-prysm Apr 2, 2024
45e68fe
Merge branch 'develop' into persistent-web3signer
james-prysm Apr 2, 2024
92487b1
fix test
james-prysm Apr 2, 2024
331bc0d
fix tests
james-prysm Apr 2, 2024
07b83c9
adding unit tests and cleaning up locks
james-prysm Apr 3, 2024
ca40bc8
Merge branch 'develop' into persistent-web3signer
james-prysm Apr 3, 2024
afd57da
fixing tests
james-prysm Apr 3, 2024
e802cb1
tests were not fixed properly
james-prysm Apr 3, 2024
db6cc41
removing unneeded files
james-prysm Apr 3, 2024
f758edb
Merge branch 'develop' into persistent-web3signer
james-prysm Apr 3, 2024
cd657d1
Merge branch 'develop' into persistent-web3signer
james-prysm Apr 4, 2024
ccda2dc
Update cmd/validator/accounts/wallet_utils.go
james-prysm Apr 4, 2024
c7057da
Update validator/accounts/wallet/wallet.go
james-prysm Apr 4, 2024
de8607a
review feedback
james-prysm Apr 4, 2024
d483c85
Merge branch 'develop' into persistent-web3signer
james-prysm Apr 16, 2024
bc2ced5
updating flags and e2e
james-prysm Apr 17, 2024
eb145a3
deepsource fix
james-prysm Apr 17, 2024
83117ea
Merge branch 'develop' into persistent-web3signer
james-prysm Apr 23, 2024
f523670
Merge branch 'develop' into persistent-web3signer
james-prysm Apr 23, 2024
4918498
Merge branch 'develop' into persistent-web3signer
james-prysm Apr 24, 2024
490b2c2
Merge branch 'develop' into persistent-web3signer
james-prysm Apr 29, 2024
e219a6e
Merge branch 'develop' into persistent-web3signer
james-prysm May 30, 2024
4139e10
resolving feedback
james-prysm May 30, 2024
d20d0fa
removing fatal test for now
james-prysm May 30, 2024
5c9a6e3
Merge branch 'develop' into persistent-web3signer
james-prysm May 31, 2024
89f3517
Merge branch 'develop' into persistent-web3signer
james-prysm May 31, 2024
d9ba22a
addressing manu's feedback
james-prysm May 31, 2024
ea49fb8
Merge branch 'develop' into persistent-web3signer
james-prysm May 31, 2024
c021a87
gofmt
james-prysm May 31, 2024
34e3655
fixing tests
james-prysm May 31, 2024
304a0b8
fixing unit tests
james-prysm May 31, 2024
0abf03a
more idomatic feedback
james-prysm May 31, 2024
94b8cca
updating log files
james-prysm May 31, 2024
cc3688f
Merge branch 'develop' into persistent-web3signer
james-prysm Jun 3, 2024
847be70
Merge branch 'develop' into persistent-web3signer
james-prysm Jun 3, 2024
f887357
updating based on preston's suggestion
james-prysm Jun 3, 2024
f86aa24
improving logs and event triggers
james-prysm Jun 4, 2024
854136d
addressing comments from manu
james-prysm Jun 7, 2024
5f1d4cc
Merge branch 'develop' into persistent-web3signer
james-prysm Jun 7, 2024
34855b9
truncating was not triggering key file reload
james-prysm Jun 10, 2024
38fd716
fixing unit test
james-prysm Jun 10, 2024
3889213
removing wrong dependency
james-prysm Jun 10, 2024
b851ed2
fix another broken unit test
james-prysm Jun 10, 2024
8d597eb
fixing bad pathing on file
james-prysm Jun 10, 2024
e9b0b14
handle errors in test
james-prysm Jun 10, 2024
f1496d1
Merge branch 'develop' into persistent-web3signer
james-prysm Jun 10, 2024
3a75ece
fixing testdata dependency
james-prysm Jun 10, 2024
ee43c00
resolving deepsource and comment around logs
james-prysm Jun 11, 2024
97b93fc
Merge branch 'develop' into persistent-web3signer
james-prysm Jun 11, 2024
286eaf4
Merge branch 'develop' into persistent-web3signer
james-prysm Jun 12, 2024
0f8646e
removing unneeded buffer
james-prysm Jun 12, 2024
3af81ee
Merge branch 'develop' into persistent-web3signer
james-prysm Jun 12, 2024
c9d384e
Merge branch 'develop' into persistent-web3signer
james-prysm Jun 14, 2024
0e16b23
reworking ux of web3signer file, unit tests to come
james-prysm Jun 17, 2024
3bb8e1e
adding unit tests for file change retries
james-prysm Jun 17, 2024
39dfb70
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jun 20, 2024
928b7f4
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jun 20, 2024
923b2f6
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jun 20, 2024
9ea7020
Merge branch 'develop' into persistent-web3signer
james-prysm Jun 20, 2024
62ee999
Merge branch 'develop' into persistent-web3signer
james-prysm Jun 21, 2024
d447fcf
updating based on review feedback
james-prysm Jun 21, 2024
b7a285f
missed err check
james-prysm Jun 21, 2024
23e0a8f
adding some aliases to make running easier
james-prysm Jun 21, 2024
dd9eefb
Update validator/keymanager/remote-web3signer/log.go
james-prysm Jun 24, 2024
915070c
Merge branch 'develop' into persistent-web3signer
james-prysm Jun 24, 2024
3b7521e
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jun 24, 2024
eb12be5
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jun 24, 2024
beab34d
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jun 24, 2024
3faab52
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jun 24, 2024
87fc54c
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jun 24, 2024
edd7480
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jun 24, 2024
560c9c7
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jun 24, 2024
309d6ba
Merge branch 'develop' into persistent-web3signer
james-prysm Jun 24, 2024
0b44203
Merge branch 'develop' into persistent-web3signer
james-prysm Jun 24, 2024
05b37af
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jun 24, 2024
bb8da2f
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jun 24, 2024
a1cb673
radek's review
james-prysm Jun 24, 2024
eb99087
Update validator/keymanager/remote-web3signer/internal/client.go
james-prysm Jun 25, 2024
7e188f3
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jun 25, 2024
c506d8c
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jun 25, 2024
d759d88
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jun 25, 2024
9b5b78b
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jun 25, 2024
698889e
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jun 25, 2024
d76793d
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jun 25, 2024
ac4b063
Update validator/keymanager/remote-web3signer/keymanager.go
james-prysm Jun 25, 2024
70d279a
Merge branch 'develop' into persistent-web3signer
james-prysm Jun 25, 2024
fe90f8f
addressing more review feedback and linting
james-prysm Jun 25, 2024
1078f47
fixing tests
james-prysm Jun 25, 2024
0470257
Merge branch 'develop' into persistent-web3signer
james-prysm Jun 25, 2024
7bf0cab
adding log
james-prysm Jun 26, 2024
a35f9bf
adding 1 more test
james-prysm Jun 26, 2024
ce1565d
improving logs
james-prysm Jun 26, 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
4 changes: 2 additions & 2 deletions cmd/validator/accounts/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Exit(c *cli.Context, r io.Reader) error {
beaconRPCProvider := c.String(flags.BeaconRPCProviderFlag.Name)
if !c.IsSet(flags.Web3SignerURLFlag.Name) && !c.IsSet(flags.WalletDirFlag.Name) && !c.IsSet(flags.InteropNumValidators.Name) {
return errors.Errorf("No validators found, please provide a prysm wallet directory via flag --%s "+
"or a web3signer location with corresponding public keys via flags --%s and --%s ",
"or a remote signer location with corresponding public keys via flags --%s and --%s ",
flags.WalletDirFlag.Name,
flags.Web3SignerURLFlag.Name,
flags.Web3SignerPublicValidatorKeysFlag,
Expand Down Expand Up @@ -62,7 +62,7 @@ func Exit(c *cli.Context, r io.Reader) error {
}
config, err := node.Web3SignerConfig(c)
if err != nil {
return errors.Wrapf(err, "could not configure web3signer")
return errors.Wrapf(err, "could not configure remote signer")
}
config.GenesisValidatorsRoot = resp.GenesisValidatorsRoot
w, km, err = walletWithWeb3SignerKeymanager(c, config)
Expand Down
2 changes: 1 addition & 1 deletion cmd/validator/accounts/wallet_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func walletWithKeymanager(c *cli.Context) (*wallet.Wallet, keymanager.IKeymanage
}

func walletWithWeb3SignerKeymanager(c *cli.Context, config *remote_web3signer.SetupConfig) (*wallet.Wallet, keymanager.IKeymanager, error) {
w := wallet.NewWalletForWeb3Signer()
w := wallet.NewWalletForWeb3Signer(c)
km, err := w.InitializeKeymanager(c.Context, iface.InitKeymanagerConfig{ListenForChanges: false, Web3SignerConfig: config})
if err != nil {
return nil, nil, err
Expand Down
22 changes: 17 additions & 5 deletions cmd/validator/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,18 +288,30 @@ var (
// example:--validators-external-signer-url=http://localhost:9000
// web3signer documentation can be found in Consensys' web3signer project docs
Web3SignerURLFlag = &cli.StringFlag{
Name: "validators-external-signer-url",
Usage: "URL for consensys' web3signer software to use with the Prysm validator client.",
Value: "",
Name: "validators-external-signer-url",
Usage: "URL for consensys' web3signer software to use with the Prysm validator client.",
Value: "",
Aliases: []string{"remote-signer-url"},
}
// Web3SignerPublicValidatorKeysFlag defines a comma-separated list of hex string public keys or external url for web3signer to use for validator signing.
// example with external url: --validators-external-signer-public-keys= https://web3signer.com/api/v1/eth2/publicKeys
// example with public key: --validators-external-signer-public-keys=0xa99a...e44c,0xb89b...4a0b
// web3signer documentation can be found in Consensys' web3signer project docs```
Web3SignerPublicValidatorKeysFlag = &cli.StringSliceFlag{
Name: "validators-external-signer-public-keys",
Usage: "Comma separated list of public keys OR an external url endpoint for the validator to retrieve public keys from for usage with web3signer.",
Name: "validators-external-signer-public-keys",
Usage: "Comma separated list of public keys OR an external url endpoint for the validator to retrieve public keys from for usage with web3signer.",
Aliases: []string{"remote-signer-keys"},
}

// Web3SignerKeyFileFlag defines a file for keys to persist to.
// example:--validators-external-signer-key-file=./path/to/keys.txt
Web3SignerKeyFileFlag = &cli.StringFlag{
Name: "validators-external-signer-key-file",
Usage: "A file path used to load remote public validator keys and persist them through restarts.",
Value: "",
Aliases: []string{"remote-signer-keys-file"},
james-prysm marked this conversation as resolved.
Show resolved Hide resolved
}

// KeymanagerKindFlag defines the kind of keymanager desired by a user during wallet creation.
KeymanagerKindFlag = &cli.StringFlag{
Name: "keymanager-kind",
Expand Down
1 change: 1 addition & 0 deletions cmd/validator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ var appFlags = []cli.Flag{
// Consensys' Web3Signer flags
flags.Web3SignerURLFlag,
flags.Web3SignerPublicValidatorKeysFlag,
flags.Web3SignerKeyFileFlag,
flags.SuggestedFeeRecipientFlag,
flags.ProposerSettingsURLFlag,
flags.ProposerSettingsFlag,
Expand Down
1 change: 1 addition & 0 deletions cmd/validator/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ var appHelpFlagGroups = []flagGroup{
Flags: []cli.Flag{
flags.Web3SignerURLFlag,
flags.Web3SignerPublicValidatorKeysFlag,
flags.Web3SignerKeyFileFlag,
},
},
{
Expand Down
6 changes: 5 additions & 1 deletion io/file/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = ["fileutil.go"],
srcs = [
"fileutil.go",
"log.go",
],
importpath = "github.com/prysmaticlabs/prysm/v5/io/file",
visibility = ["//visibility:public"],
deps = [
"//config/params:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],
)

Expand Down
24 changes: 24 additions & 0 deletions io/file/fileutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,27 @@ func DirFiles(dir string) ([]string, error) {
}
return files, nil
}

// WriteLinesToFile writes a slice of strings to a file, each string on a new line.
func WriteLinesToFile(lines []string, filename string) error {
// Open the file for writing. If the file does not exist, create it, or truncate it if it does.
f, err := os.Create(filepath.Clean(filename))
if err != nil {
return fmt.Errorf("error creating file: %w", err)
}
defer func(file *os.File) {
err := file.Close()
if err != nil {
log.Error(err.Error())
}
}(f)

// Iterate through all lines in the slice and write them to the file
for _, line := range lines {
if _, err := f.WriteString(line + "\n"); err != nil {
return fmt.Errorf("error writing line to file: %w", err)
}
}

return nil
}
35 changes: 35 additions & 0 deletions io/file/fileutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os/user"
"path/filepath"
"sort"
"strings"
"testing"

"github.com/prysmaticlabs/prysm/v5/config/params"
Expand Down Expand Up @@ -567,3 +568,37 @@ func TestHasReadWritePermissions(t *testing.T) {
})
}
}

func TestWriteLinesToFile(t *testing.T) {
filename := filepath.Join(t.TempDir(), "testfile.txt")
t.Run("write to a new file", func(t *testing.T) {
lines := []string{"line1", "line2", "line3"}
require.NoError(t, file.WriteLinesToFile(lines, filename))
// Check file content
content, err := os.ReadFile(filepath.Clean(filename))
if err != nil {
t.Fatalf("failed to read file: %v", err)
}

// Join lines with newline for comparison
expectedContent := strings.Join(lines, "\n") + "\n"
if string(content) != expectedContent {
t.Errorf("file content = %q, want %q", string(content), expectedContent)
}
})
t.Run("overwrite existing file", func(t *testing.T) {
lines := []string{"line4", "line5"}
require.NoError(t, file.WriteLinesToFile(lines, filename))
// Check file content
content, err := os.ReadFile(filepath.Clean(filename))
if err != nil {
t.Fatalf("failed to read file: %v", err)
}

// Join lines with newline for comparison
expectedContent := strings.Join(lines, "\n") + "\n"
if string(content) != expectedContent {
t.Errorf("file content = %q, want %q", string(content), expectedContent)
}
})
}
5 changes: 5 additions & 0 deletions io/file/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package file

import "github.com/sirupsen/logrus"

var log = logrus.WithField("prefix", "fileutil")
15 changes: 12 additions & 3 deletions testing/endtoend/components/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (v *ValidatorNode) Start(ctx context.Context) error {
beaconRPCPort = e2e.TestParams.Ports.PrysmBeaconNodeRPCPort
}

file, err := helpers.DeleteAndCreateFile(e2e.TestParams.LogPath, fmt.Sprintf(e2e.ValidatorLogFileName, index))
logFile, err := helpers.DeleteAndCreateFile(e2e.TestParams.LogPath, fmt.Sprintf(e2e.ValidatorLogFileName, index))
if err != nil {
return err
}
Expand All @@ -223,7 +223,7 @@ func (v *ValidatorNode) Start(ctx context.Context) error {
}
args := []string{
fmt.Sprintf("--%s=%s/eth2-val-%d", cmdshared.DataDirFlag.Name, e2e.TestParams.TestPath, index),
fmt.Sprintf("--%s=%s", cmdshared.LogFileName.Name, file.Name()),
fmt.Sprintf("--%s=%s", cmdshared.LogFileName.Name, logFile.Name()),
fmt.Sprintf("--%s=%s", flags.GraffitiFileFlag.Name, gFile),
fmt.Sprintf("--%s=%d", flags.MonitoringPortFlag.Name, e2e.TestParams.Ports.ValidatorMetricsPort+index),
fmt.Sprintf("--%s=%d", flags.GRPCGatewayPort.Name, e2e.TestParams.Ports.ValidatorGatewayPort+index),
Expand Down Expand Up @@ -258,7 +258,16 @@ func (v *ValidatorNode) Start(ctx context.Context) error {
// See: https://docs.teku.consensys.net/en/latest/HowTo/External-Signer/Use-External-Signer/
args = append(args,
fmt.Sprintf("--%s=http://localhost:%d", flags.Web3SignerURLFlag.Name, Web3RemoteSignerPort),
fmt.Sprintf("--%s=%s", flags.Web3SignerPublicValidatorKeysFlag.Name, strings.Join(validatorHexPubKeys, ",")))
)
if v.config.UsePersistentKeyFile {
keysPath := filepath.Join(e2e.TestParams.TestPath, "proposer-settings", fmt.Sprintf("validator_%d", index), "keys.txt")
if err := file.WriteLinesToFile(validatorHexPubKeys, keysPath); err != nil {
return err
}
args = append(args, fmt.Sprintf("--%s=%s", flags.Web3SignerKeyFileFlag.Name, keysPath))
} else {
args = append(args, fmt.Sprintf("--%s=%s", flags.Web3SignerPublicValidatorKeysFlag.Name, strings.Join(validatorHexPubKeys, ",")))
}
} else {
// When not using remote key signer, use interop keys.
args = append(args,
Expand Down
4 changes: 4 additions & 0 deletions testing/endtoend/minimal_scenario_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func TestEndToEnd_MinimalConfig_Web3Signer(t *testing.T) {
e2eMinimal(t, types.InitForkCfg(version.Phase0, version.Deneb, params.E2ETestConfig()), types.WithRemoteSigner()).run()
}

func TestEndToEnd_MinimalConfig_Web3Signer_PersistentKeys(t *testing.T) {
e2eMinimal(t, types.InitForkCfg(version.Phase0, version.Deneb, params.E2ETestConfig()), types.WithRemoteSignerAndPersistentKeysFile()).run()
}

func TestEndToEnd_MinimalConfig_ValidatorRESTApi(t *testing.T) {
e2eMinimal(t, types.InitForkCfg(version.Phase0, version.Deneb, params.E2ETestConfig()), types.WithCheckpointSync(), types.WithValidatorRESTApi()).run()
}
Expand Down
8 changes: 8 additions & 0 deletions testing/endtoend/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ func WithRemoteSigner() E2EConfigOpt {
}
}

func WithRemoteSignerAndPersistentKeysFile() E2EConfigOpt {
return func(cfg *E2EConfig) {
cfg.UseWeb3RemoteSigner = true
cfg.UsePersistentKeyFile = true
}
}

func WithCheckpointSync() E2EConfigOpt {
return func(cfg *E2EConfig) {
cfg.TestCheckpointSync = true
Expand Down Expand Up @@ -58,6 +65,7 @@ type E2EConfig struct {
UsePrysmShValidator bool
UsePprof bool
UseWeb3RemoteSigner bool
UsePersistentKeyFile bool
TestDeposits bool
UseFixedPeerIDs bool
UseValidatorCrossClient bool
Expand Down
4 changes: 4 additions & 0 deletions validator/accounts/iface/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ type InitKeymanagerConfig struct {
type Wallet interface {
// Methods to retrieve wallet and accounts metadata.
AccountsDir() string
// Method to retrieve wallet directory.
Dir() string
james-prysm marked this conversation as resolved.
Show resolved Hide resolved
Password() string
// Read methods for important wallet and accounts-related files.
ReadFileAtPath(ctx context.Context, filePath string, fileName string) ([]byte, error)
// Write methods to persist important wallet and accounts-related files to disk.
WriteFileAtPath(ctx context.Context, pathName string, fileName string, data []byte) (bool, error)
// Method for initializing a new keymanager.
InitializeKeymanager(ctx context.Context, cfg InitKeymanagerConfig) (keymanager.IKeymanager, error)
// Method for returning keymanager kind.
KeymanagerKind() keymanager.Kind
james-prysm marked this conversation as resolved.
Show resolved Hide resolved
}
12 changes: 12 additions & 0 deletions validator/accounts/testing/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type Wallet struct {
UnlockAccounts bool
lock sync.RWMutex
HasWriteFileError bool
WalletDir string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the word Wallet needed in WalletDir?
We already know it's a wallet, and writing wallet.Dir is more natural than wallet.WalletDir.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good point i will change this I think I was just following naming of other parts of the code

Kind keymanager.Kind
}

// AccountNames --
Expand All @@ -47,6 +49,16 @@ func (w *Wallet) AccountsDir() string {
return w.InnerAccountsDir
}

// Dir for the wallet.
func (w *Wallet) Dir() string {
return w.WalletDir
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WalletDir is already accessible from outside. Why an accessor method is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to follow the interface

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted I left it as is, I don't think renaming to Directory helps, Dir is needed for the interface, and should be fixed as part of a greater wallet refactoring.

}

// KeymanagerKind --
func (w *Wallet) KeymanagerKind() keymanager.Kind {
return w.Kind
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind is already accessible from outside. Why an accessor method is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to follow the interface for wallet

}

// Exists --
func (w *Wallet) Exists() (bool, error) {
return len(w.Directories) > 0, nil
Expand Down
10 changes: 8 additions & 2 deletions validator/accounts/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,11 @@ func OpenOrCreateNewWallet(cliCtx *cli.Context) (*Wallet, error) {
}

// NewWalletForWeb3Signer returns a new wallet for web3 signer which is temporary and not stored locally.
func NewWalletForWeb3Signer() *Wallet {
func NewWalletForWeb3Signer(cliCtx *cli.Context) *Wallet {
walletDir := cliCtx.String(flags.WalletDirFlag.Name)
// wallet is just a temporary wallet for web3 signer used to call initialize keymanager.
return &Wallet{
walletDir: "",
walletDir: walletDir, // it's ok if there's an existing wallet
accountsPath: "",
keymanagerKind: keymanager.Web3Signer,
walletPassword: "",
Expand Down Expand Up @@ -318,6 +319,11 @@ func (w *Wallet) AccountsDir() string {
return w.accountsPath
}

// Dir for the wallet.
func (w *Wallet) Dir() string {
return w.walletDir
}

// Password for the wallet.
func (w *Wallet) Password() string {
return w.walletPassword
Expand Down
13 changes: 10 additions & 3 deletions validator/accounts/wallet/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ func Test_IsValid_RandomFiles(t *testing.T) {
}

func TestWallet_InitializeKeymanager_web3Signer_HappyPath(t *testing.T) {
w := wallet.NewWalletForWeb3Signer()
app := cli.App{}
set := flag.NewFlagSet("test", 0)
newDir := filepath.Join(t.TempDir(), "new")
set.String(flags.WalletDirFlag.Name, newDir, "")
w := wallet.NewWalletForWeb3Signer(cli.NewContext(&app, set, nil))
ctx := context.Background()
root, err := hexutil.Decode("0x270d43e74ce340de4bca2b1936beca0f4f5408d9e78aec4850920baf659d5b69")
require.NoError(t, err)
Expand All @@ -70,7 +74,6 @@ func TestWallet_InitializeKeymanager_web3Signer_HappyPath(t *testing.T) {
Web3SignerConfig: &remoteweb3signer.SetupConfig{
BaseEndpoint: "http://localhost:8545",
GenesisValidatorsRoot: root,
PublicKeysURL: "http://localhost:8545/public_keys",
},
}
km, err := w.InitializeKeymanager(ctx, config)
Expand All @@ -79,7 +82,11 @@ func TestWallet_InitializeKeymanager_web3Signer_HappyPath(t *testing.T) {
}

func TestWallet_InitializeKeymanager_web3Signer_nilConfig(t *testing.T) {
w := wallet.NewWalletForWeb3Signer()
app := cli.App{}
set := flag.NewFlagSet("test", 0)
newDir := filepath.Join(t.TempDir(), "new")
set.String(flags.WalletDirFlag.Name, newDir, "")
w := wallet.NewWalletForWeb3Signer(cli.NewContext(&app, set, nil))
ctx := context.Background()
config := iface.InitKeymanagerConfig{
ListenForChanges: false,
Expand Down
2 changes: 2 additions & 0 deletions validator/client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ go_test(
"//async/event:go_default_library",
"//beacon-chain/core/signing:go_default_library",
"//cache/lru:go_default_library",
"//cmd/validator/flags:go_default_library",
"//config/features:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
Expand Down Expand Up @@ -169,6 +170,7 @@ go_test(
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
"@com_github_stretchr_testify//mock:go_default_library",
"@com_github_tyler_smith_go_bip39//:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
"@com_github_wealdtech_go_eth2_util//:go_default_library",
"@in_gopkg_d4l3k_messagediff_v1//:go_default_library",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
Expand Down
Loading
Loading