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

Remote Signer: use hard coded genesis validators root #14469

Draft
wants to merge 7 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
- Updated k8s-io/client-go to v0.30.4 and k8s-io/apimachinery to v0.30.4
- Migrated tracing library from opencensus to opentelemetry for both the beacon node and validator.
- Refactored light client code to make it more readable and make future PRs easier.
- remote signer (web3signer) uses the hardcoded genesis validators root returned from beacon configs

### Deprecated
- `--disable-grpc-gateway` flag is deprecated due to grpc gateway removal.
Expand Down
4 changes: 0 additions & 4 deletions cmd/validator/accounts/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v5/cmd/validator/accounts",
visibility = ["//visibility:public"],
deps = [
"//api/grpc:go_default_library",
"//cmd:go_default_library",
"//cmd/validator/flags:go_default_library",
"//config/features:go_default_library",
"//io/prompt:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//runtime/tos:go_default_library",
"//validator/accounts:go_default_library",
"//validator/accounts/iface:go_default_library",
Expand All @@ -30,11 +28,9 @@ go_library(
"//validator/keymanager/local:go_default_library",
"//validator/keymanager/remote-web3signer:go_default_library",
"//validator/node:go_default_library",
"@com_github_golang_protobuf//ptypes/empty",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
"@org_golang_google_grpc//:go_default_library",
],
)

Expand Down
18 changes: 0 additions & 18 deletions cmd/validator/accounts/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@ import (
"io"
"strings"

"github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"
grpcutil "github.com/prysmaticlabs/prysm/v5/api/grpc"
"github.com/prysmaticlabs/prysm/v5/cmd"
"github.com/prysmaticlabs/prysm/v5/cmd/validator/flags"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/validator/accounts"
"github.com/prysmaticlabs/prysm/v5/validator/accounts/wallet"
"github.com/prysmaticlabs/prysm/v5/validator/client"
"github.com/prysmaticlabs/prysm/v5/validator/keymanager"
"github.com/prysmaticlabs/prysm/v5/validator/keymanager/local"
"github.com/prysmaticlabs/prysm/v5/validator/node"
"github.com/urfave/cli/v2"
"google.golang.org/grpc"
)

func Exit(c *cli.Context, r io.Reader) error {
Expand Down Expand Up @@ -47,24 +43,10 @@ func Exit(c *cli.Context, r io.Reader) error {
}
w = &wallet.Wallet{}
} else if c.IsSet(flags.Web3SignerURLFlag.Name) {
ctx := grpcutil.AppendHeaders(c.Context, grpcHeaders)
conn, err := grpc.DialContext(ctx, beaconRPCProvider, dialOpts...)
if err != nil {
return errors.Wrapf(err, "could not dial endpoint %s", beaconRPCProvider)
}
nodeClient := ethpb.NewNodeClient(conn)
resp, err := nodeClient.GetGenesis(c.Context, &empty.Empty{})
if err != nil {
return errors.Wrapf(err, "failed to get genesis info")
}
if err := conn.Close(); err != nil {
log.WithError(err).Error("Failed to close connection")
}
config, err := node.Web3SignerConfig(c)
if err != nil {
return errors.Wrapf(err, "could not configure remote signer")
}
config.GenesisValidatorsRoot = resp.GenesisValidatorsRoot
w, km, err = walletWithWeb3SignerKeymanager(c, config)
if err != nil {
return err
Expand Down
3 changes: 0 additions & 3 deletions cmd/validator/accounts/wallet_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,8 @@ func TestWalletWithKeymanager_web3signer(t *testing.T) {
require.NoError(t, set.Set(flags.Web3SignerURLFlag.Name, "http://localhost:12345"))
require.NoError(t, set.Set(flags.Web3SignerPublicValidatorKeysFlag.Name, "0xa2b5aaad9c6efefe7bb9b1243a043404f3362937cfb6b31833929833173f476630ea2cfeb0d9ddf15f97ca8685948820"))
ctx := cli.NewContext(&app, set, nil)
bytes, err := hexutil.Decode("0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2")
require.NoError(t, err)
config, err := node.Web3SignerConfig(ctx)
require.NoError(t, err)
config.GenesisValidatorsRoot = bytes
w, k, err := walletWithWeb3SignerKeymanager(ctx, config)
require.NoError(t, err)
keys, err := k.FetchValidatingPublicKeys(ctx.Context)
Expand Down
2 changes: 0 additions & 2 deletions validator/accounts/wallet/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ go_library(
],
deps = [
"//cmd/validator/flags:go_default_library",
"//encoding/bytesutil:go_default_library",
"//io/file:go_default_library",
"//io/prompt:go_default_library",
"//validator/accounts/iface:go_default_library",
Expand All @@ -41,7 +40,6 @@ go_test(
"//validator/accounts/iface:go_default_library",
"//validator/keymanager:go_default_library",
"//validator/keymanager/remote-web3signer:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
],
Expand Down
12 changes: 1 addition & 11 deletions validator/accounts/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/cmd/validator/flags"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/io/file"
"github.com/prysmaticlabs/prysm/v5/io/prompt"
"github.com/prysmaticlabs/prysm/v5/validator/accounts/iface"
Expand Down Expand Up @@ -350,16 +349,7 @@ func (w *Wallet) InitializeKeymanager(ctx context.Context, cfg iface.InitKeymana
return nil, errors.Wrap(err, "could not initialize derived keymanager")
}
case keymanager.Web3Signer:
config := cfg.Web3SignerConfig
if config == nil {
return nil, errors.New("web3signer config is nil")
}
// TODO(9883): future work needs to address how initialize keymanager is called for web3signer.
// an error may be thrown for genesis validators root for some InitializeKeymanager calls.
if !bytesutil.IsValidRoot(config.GenesisValidatorsRoot) {
return nil, errors.New("web3signer requires a genesis validators root value")
}
km, err = remoteweb3signer.NewKeymanager(ctx, config)
km, err = remoteweb3signer.NewKeymanager(ctx, cfg.Web3SignerConfig)
if err != nil {
return nil, errors.Wrap(err, "could not initialize web3signer keymanager")
}
Expand Down
6 changes: 1 addition & 5 deletions validator/accounts/wallet/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"reflect"
"testing"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/prysmaticlabs/prysm/v5/cmd/validator/flags"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/testing/assert"
Expand Down Expand Up @@ -67,13 +66,10 @@ func TestWallet_InitializeKeymanager_web3Signer_HappyPath(t *testing.T) {
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)
config := iface.InitKeymanagerConfig{
ListenForChanges: false,
Web3SignerConfig: &remoteweb3signer.SetupConfig{
BaseEndpoint: "http://localhost:8545",
GenesisValidatorsRoot: root,
BaseEndpoint: "http://localhost:8545",
},
}
km, err := w.InitializeKeymanager(ctx, config)
Expand Down
8 changes: 0 additions & 8 deletions validator/client/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,6 @@ func (v *validator) WaitForKeymanagerInitialization(ctx context.Context) error {
ctx, span := trace.StartSpan(ctx, "validator.WaitForKeymanagerInitialization")
defer span.End()

genesisRoot, err := v.db.GenesisValidatorsRoot(ctx)
if err != nil {
return errors.Wrap(err, "unable to retrieve valid genesis validators root while initializing key manager")
}

if v.useWeb && v.wallet == nil {
log.Info("Waiting for keymanager to initialize validator client with web UI")
// if wallet is not set, wait for it to be set through the UI
Expand All @@ -159,9 +154,6 @@ func (v *validator) WaitForKeymanagerInitialization(ctx context.Context) error {
} else if v.wallet == nil {
return errors.New("wallet not set")
} else {
if v.web3SignerConfig != nil {
v.web3SignerConfig.GenesisValidatorsRoot = genesisRoot
}
keyManager, err := v.wallet.InitializeKeymanager(ctx, accountsiface.InitKeymanagerConfig{ListenForChanges: true, Web3SignerConfig: v.web3SignerConfig})
if err != nil {
return errors.Wrap(err, "could not initialize key manager")
Expand Down
1 change: 1 addition & 0 deletions validator/keymanager/remote-web3signer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ go_library(
deps = [
"//async/event:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//crypto/bls:go_default_library",
"//encoding/bytesutil:go_default_library",
"//io/file:go_default_library",
Expand Down
15 changes: 9 additions & 6 deletions validator/keymanager/remote-web3signer/keymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v5/async/event"
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/crypto/bls"
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v5/io/file"
Expand All @@ -41,9 +42,8 @@ const (
// a keymanager, such as passwords, the wallet, and more.
// Web3Signer contains one public keys option. Either through a URL or a static key list.
type SetupConfig struct {
KeyFilePath string
BaseEndpoint string
GenesisValidatorsRoot []byte
KeyFilePath string
BaseEndpoint string

// Either URL or keylist must be set.
// If the URL is set, the keymanager will fetch the public keys from the URL.
Expand Down Expand Up @@ -73,8 +73,11 @@ type Keymanager struct {
func NewKeymanager(ctx context.Context, cfg *SetupConfig) (*Keymanager, error) {
ctx, span := trace.StartSpan(ctx, "remote-keymanager.NewKeymanager")
defer span.End()
if cfg.BaseEndpoint == "" || !bytesutil.IsValidRoot(cfg.GenesisValidatorsRoot) {
return nil, fmt.Errorf("invalid setup config, one or more configs are empty: BaseEndpoint: %v, GenesisValidatorsRoot: %#x", cfg.BaseEndpoint, cfg.GenesisValidatorsRoot)
if cfg == nil {
return nil, errors.New("web3signer config is nil")
}
if cfg.BaseEndpoint == "" {
return nil, fmt.Errorf("invalid setup config, one or more configs are empty: BaseEndpoint: %v", cfg.BaseEndpoint)
}
client, err := internal.NewApiClient(cfg.BaseEndpoint)
if err != nil {
Expand All @@ -83,7 +86,7 @@ func NewKeymanager(ctx context.Context, cfg *SetupConfig) (*Keymanager, error) {

km := &Keymanager{
client: internal.HttpSignerClient(client),
genesisValidatorsRoot: cfg.GenesisValidatorsRoot,
genesisValidatorsRoot: params.BeaconConfig().GenesisValidatorsRoot[:],
accountsChangedFeed: new(event.Feed),
validator: validator.New(),
retriesRemaining: maxRetries,
Expand Down
Loading
Loading