2020-04-29 21:32:39 +00:00
|
|
|
// Package node is the main process which handles the lifecycle of
|
|
|
|
// the runtime services in a validator client process, gracefully shutting
|
|
|
|
// everything down upon close.
|
2018-06-02 22:29:35 +00:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
2020-12-11 18:31:35 +00:00
|
|
|
"context"
|
2022-03-10 20:25:26 +00:00
|
|
|
"encoding/json"
|
2018-06-03 23:24:31 +00:00
|
|
|
"fmt"
|
2022-03-10 20:25:26 +00:00
|
|
|
"io"
|
2021-06-18 13:35:13 +00:00
|
|
|
"net/http"
|
2022-01-31 16:44:17 +00:00
|
|
|
"net/url"
|
2018-06-11 22:21:24 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
2020-11-12 19:22:11 +00:00
|
|
|
"path/filepath"
|
2020-01-24 17:21:31 +00:00
|
|
|
"strings"
|
2018-06-04 20:00:47 +00:00
|
|
|
"sync"
|
2018-06-11 22:21:24 +00:00
|
|
|
"syscall"
|
2018-06-02 22:29:35 +00:00
|
|
|
|
2022-03-21 18:48:02 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2022-01-31 16:44:17 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
2022-06-18 12:13:36 +00:00
|
|
|
fastssz "github.com/ferranbt/fastssz"
|
2021-06-18 13:35:13 +00:00
|
|
|
gwruntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
2019-08-02 02:27:38 +00:00
|
|
|
"github.com/pkg/errors"
|
2021-09-16 19:55:51 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/api/gateway"
|
2021-12-07 20:26:21 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/api/gateway/apimiddleware"
|
2021-09-18 17:26:11 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/async/event"
|
2021-09-21 18:11:16 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/cmd"
|
2021-03-02 18:58:40 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/cmd/validator/flags"
|
2021-09-15 01:18:39 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/config/features"
|
2022-03-21 18:48:02 +00:00
|
|
|
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
2021-09-21 19:59:25 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/config/params"
|
2022-03-21 18:48:02 +00:00
|
|
|
validatorServiceConfig "github.com/prysmaticlabs/prysm/config/validator/service"
|
2022-01-31 16:44:17 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
2021-09-17 21:55:24 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/io/file"
|
2021-09-14 20:59:51 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/monitoring/backup"
|
|
|
|
"github.com/prysmaticlabs/prysm/monitoring/prometheus"
|
|
|
|
tracing2 "github.com/prysmaticlabs/prysm/monitoring/tracing"
|
2021-12-07 20:26:21 +00:00
|
|
|
ethpbservice "github.com/prysmaticlabs/prysm/proto/eth/service"
|
2021-07-28 21:23:44 +00:00
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
2021-08-24 00:33:17 +00:00
|
|
|
validatorpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client"
|
2021-09-17 19:20:50 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/runtime"
|
2021-09-16 09:46:29 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/runtime/debug"
|
|
|
|
"github.com/prysmaticlabs/prysm/runtime/prereqs"
|
|
|
|
"github.com/prysmaticlabs/prysm/runtime/version"
|
2020-10-15 22:31:52 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
2020-07-02 17:50:05 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/validator/client"
|
2020-06-27 02:37:43 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/validator/db/kv"
|
2020-12-04 23:15:12 +00:00
|
|
|
g "github.com/prysmaticlabs/prysm/validator/graffiti"
|
2022-02-01 19:54:19 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/validator/keymanager/local"
|
2022-06-27 13:34:38 +00:00
|
|
|
remoteweb3signer "github.com/prysmaticlabs/prysm/validator/keymanager/remote-web3signer"
|
2020-08-12 23:33:15 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/validator/rpc"
|
2022-06-27 13:34:38 +00:00
|
|
|
validatormiddleware "github.com/prysmaticlabs/prysm/validator/rpc/apimiddleware"
|
2021-06-18 13:35:13 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/validator/web"
|
2020-07-08 05:01:09 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/urfave/cli/v2"
|
2021-06-18 13:35:13 +00:00
|
|
|
"google.golang.org/protobuf/encoding/protojson"
|
2022-06-06 19:32:41 +00:00
|
|
|
"gopkg.in/yaml.v2"
|
2018-06-02 22:29:35 +00:00
|
|
|
)
|
|
|
|
|
2021-06-26 19:00:33 +00:00
|
|
|
// ValidatorClient defines an instance of an Ethereum validator that manages
|
|
|
|
// the entire lifecycle of services attached to it participating in proof of stake.
|
2018-10-18 17:33:38 +00:00
|
|
|
type ValidatorClient struct {
|
2020-09-03 15:11:17 +00:00
|
|
|
cliCtx *cli.Context
|
2021-01-25 15:57:21 +00:00
|
|
|
ctx context.Context
|
|
|
|
cancel context.CancelFunc
|
2020-09-03 15:11:17 +00:00
|
|
|
db *kv.Store
|
2021-09-17 19:20:50 +00:00
|
|
|
services *runtime.ServiceRegistry // Lifecycle and service store.
|
2020-09-03 15:11:17 +00:00
|
|
|
lock sync.RWMutex
|
2020-09-17 01:34:42 +00:00
|
|
|
wallet *wallet.Wallet
|
2020-09-03 15:11:17 +00:00
|
|
|
walletInitialized *event.Feed
|
|
|
|
stop chan struct{} // Channel to wait for termination notifications.
|
2018-09-26 03:27:52 +00:00
|
|
|
}
|
|
|
|
|
2021-02-01 17:12:52 +00:00
|
|
|
// NewValidatorClient creates a new instance of the Prysm validator client.
|
2020-05-07 15:14:08 +00:00
|
|
|
func NewValidatorClient(cliCtx *cli.Context) (*ValidatorClient, error) {
|
2022-01-31 16:44:17 +00:00
|
|
|
// TODO(#9883) - Maybe we can pass in a new validator client config instead of the cliCTX to abstract away the use of flags here .
|
2021-09-14 20:59:51 +00:00
|
|
|
if err := tracing2.Setup(
|
2019-02-28 03:55:47 +00:00
|
|
|
"validator", // service name
|
2020-05-07 15:14:08 +00:00
|
|
|
cliCtx.String(cmd.TracingProcessNameFlag.Name),
|
|
|
|
cliCtx.String(cmd.TracingEndpointFlag.Name),
|
|
|
|
cliCtx.Float64(cmd.TraceSampleFractionFlag.Name),
|
|
|
|
cliCtx.Bool(cmd.EnableTracingFlag.Name),
|
2019-02-28 03:55:47 +00:00
|
|
|
); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-09-26 18:23:25 +00:00
|
|
|
|
2020-05-07 15:14:08 +00:00
|
|
|
verbosity := cliCtx.String(cmd.VerbosityFlag.Name)
|
2019-09-26 18:23:25 +00:00
|
|
|
level, err := logrus.ParseLevel(verbosity)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
logrus.SetLevel(level)
|
|
|
|
|
2020-10-02 06:45:34 +00:00
|
|
|
// Warn if user's platform is not supported
|
2021-09-16 09:46:29 +00:00
|
|
|
prereqs.WarnIfPlatformNotSupported(cliCtx.Context)
|
2020-10-02 06:45:34 +00:00
|
|
|
|
2021-09-17 19:20:50 +00:00
|
|
|
registry := runtime.NewServiceRegistry()
|
2021-01-25 15:57:21 +00:00
|
|
|
ctx, cancel := context.WithCancel(cliCtx.Context)
|
2021-02-01 17:12:52 +00:00
|
|
|
validatorClient := &ValidatorClient{
|
2020-09-03 15:11:17 +00:00
|
|
|
cliCtx: cliCtx,
|
2021-01-25 15:57:21 +00:00
|
|
|
ctx: ctx,
|
|
|
|
cancel: cancel,
|
2020-09-03 15:11:17 +00:00
|
|
|
services: registry,
|
|
|
|
walletInitialized: new(event.Feed),
|
|
|
|
stop: make(chan struct{}),
|
2018-06-06 15:04:20 +00:00
|
|
|
}
|
2018-09-27 21:46:07 +00:00
|
|
|
|
2022-05-20 07:16:53 +00:00
|
|
|
if err := features.ConfigureValidator(cliCtx); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := cmd.ConfigureValidator(cliCtx); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-08-01 00:46:55 +00:00
|
|
|
|
2020-05-07 15:14:08 +00:00
|
|
|
if cliCtx.IsSet(cmd.ChainConfigFileFlag.Name) {
|
|
|
|
chainConfigFileName := cliCtx.String(cmd.ChainConfigFileFlag.Name)
|
2022-05-20 07:16:53 +00:00
|
|
|
if err := params.LoadChainConfigFile(chainConfigFileName, nil); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-05-05 22:19:27 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 12:13:36 +00:00
|
|
|
configureFastSSZHashingAlgorithm()
|
|
|
|
|
2020-09-03 15:11:17 +00:00
|
|
|
// If the --web flag is enabled to administer the validator
|
|
|
|
// client via a web portal, we start the validator client in a different way.
|
|
|
|
if cliCtx.IsSet(flags.EnableWebFlag.Name) {
|
2022-01-31 16:44:17 +00:00
|
|
|
if cliCtx.IsSet(flags.Web3SignerURLFlag.Name) || cliCtx.IsSet(flags.Web3SignerPublicValidatorKeysFlag.Name) {
|
2022-04-11 20:05:40 +00:00
|
|
|
log.Warn("Remote Keymanager API enabled. Prysm web does not properly support web3signer at this time")
|
2022-01-31 16:44:17 +00:00
|
|
|
}
|
2020-09-03 15:11:17 +00:00
|
|
|
log.Info("Enabling web portal to manage the validator client")
|
2021-02-01 17:12:52 +00:00
|
|
|
if err := validatorClient.initializeForWeb(cliCtx); err != nil {
|
2020-09-03 15:11:17 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2021-02-01 17:12:52 +00:00
|
|
|
return validatorClient, nil
|
2020-09-03 15:11:17 +00:00
|
|
|
}
|
2020-12-04 23:15:12 +00:00
|
|
|
|
2021-02-01 17:12:52 +00:00
|
|
|
if err := validatorClient.initializeFromCLI(cliCtx); err != nil {
|
2020-09-03 15:11:17 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2020-12-04 23:15:12 +00:00
|
|
|
|
2021-02-01 17:12:52 +00:00
|
|
|
return validatorClient, nil
|
2020-09-03 15:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start every service in the validator client.
|
2021-01-20 14:39:07 +00:00
|
|
|
func (c *ValidatorClient) Start() {
|
|
|
|
c.lock.Lock()
|
2020-09-03 15:11:17 +00:00
|
|
|
|
|
|
|
log.WithFields(logrus.Fields{
|
2021-01-25 21:27:30 +00:00
|
|
|
"version": version.Version(),
|
2020-09-03 15:11:17 +00:00
|
|
|
}).Info("Starting validator node")
|
|
|
|
|
2021-01-20 14:39:07 +00:00
|
|
|
c.services.StartAll()
|
2020-09-03 15:11:17 +00:00
|
|
|
|
2021-01-20 14:39:07 +00:00
|
|
|
stop := c.stop
|
|
|
|
c.lock.Unlock()
|
2020-09-03 15:11:17 +00:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
sigc := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
defer signal.Stop(sigc)
|
|
|
|
<-sigc
|
|
|
|
log.Info("Got interrupt, shutting down...")
|
2021-01-20 14:39:07 +00:00
|
|
|
debug.Exit(c.cliCtx) // Ensure trace and CPU profile data are flushed.
|
|
|
|
go c.Close()
|
2020-09-03 15:11:17 +00:00
|
|
|
for i := 10; i > 0; i-- {
|
|
|
|
<-sigc
|
|
|
|
if i > 1 {
|
|
|
|
log.WithField("times", i-1).Info("Already shutting down, interrupt more to panic.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
panic("Panic closing the validator client")
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Wait for stop channel to be closed.
|
|
|
|
<-stop
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close handles graceful shutdown of the system.
|
2021-01-20 14:39:07 +00:00
|
|
|
func (c *ValidatorClient) Close() {
|
|
|
|
c.lock.Lock()
|
|
|
|
defer c.lock.Unlock()
|
2020-09-03 15:11:17 +00:00
|
|
|
|
2021-01-20 14:39:07 +00:00
|
|
|
c.services.StopAll()
|
2020-09-03 15:11:17 +00:00
|
|
|
log.Info("Stopping Prysm validator")
|
2021-01-25 15:57:21 +00:00
|
|
|
c.cancel()
|
2021-01-20 14:39:07 +00:00
|
|
|
close(c.stop)
|
2020-09-03 15:11:17 +00:00
|
|
|
}
|
|
|
|
|
2021-01-20 14:39:07 +00:00
|
|
|
func (c *ValidatorClient) initializeFromCLI(cliCtx *cli.Context) error {
|
2020-09-03 15:11:17 +00:00
|
|
|
var err error
|
2020-10-28 17:09:44 +00:00
|
|
|
dataDir := cliCtx.String(flags.WalletDirFlag.Name)
|
2022-01-31 16:44:17 +00:00
|
|
|
if !cliCtx.IsSet(flags.InteropNumValidators.Name) {
|
|
|
|
// Custom Check For Web3Signer
|
2022-04-11 20:05:40 +00:00
|
|
|
if cliCtx.IsSet(flags.Web3SignerURLFlag.Name) {
|
|
|
|
c.wallet = wallet.NewWalletForWeb3Signer()
|
2022-01-31 16:44:17 +00:00
|
|
|
} else {
|
|
|
|
w, err := wallet.OpenWalletOrElseCli(cliCtx, func(cliCtx *cli.Context) (*wallet.Wallet, error) {
|
|
|
|
return nil, wallet.ErrNoWalletFound
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not open wallet")
|
|
|
|
}
|
|
|
|
c.wallet = w
|
|
|
|
// TODO(#9883) - Remove this when we have a better way to handle this.
|
|
|
|
log.WithFields(logrus.Fields{
|
|
|
|
"wallet": w.AccountsDir(),
|
|
|
|
"keymanager-kind": w.KeymanagerKind().String(),
|
|
|
|
}).Info("Opened validator wallet")
|
|
|
|
dataDir = c.wallet.AccountsDir()
|
|
|
|
}
|
2020-10-28 17:09:44 +00:00
|
|
|
}
|
|
|
|
if cliCtx.String(cmd.DataDirFlag.Name) != cmd.DefaultDataDir() {
|
|
|
|
dataDir = cliCtx.String(cmd.DataDirFlag.Name)
|
|
|
|
}
|
2020-05-07 15:14:08 +00:00
|
|
|
clearFlag := cliCtx.Bool(cmd.ClearDB.Name)
|
|
|
|
forceClearFlag := cliCtx.Bool(cmd.ForceClearDB.Name)
|
2020-01-08 18:16:17 +00:00
|
|
|
if clearFlag || forceClearFlag {
|
2021-01-20 14:39:07 +00:00
|
|
|
if dataDir == "" && c.wallet != nil {
|
|
|
|
dataDir = c.wallet.AccountsDir()
|
2020-06-25 18:02:07 +00:00
|
|
|
if dataDir == "" {
|
|
|
|
log.Fatal(
|
2021-01-20 14:39:07 +00:00
|
|
|
"Could not determine your system'c HOME path, please specify a --datadir you wish " +
|
2020-06-25 18:02:07 +00:00
|
|
|
"to use for your validator data",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-03-19 21:46:44 +00:00
|
|
|
}
|
2020-12-11 18:31:35 +00:00
|
|
|
if err := clearDB(cliCtx.Context, dataDir, forceClearFlag); err != nil {
|
2020-09-03 15:11:17 +00:00
|
|
|
return err
|
2020-01-08 18:16:17 +00:00
|
|
|
}
|
2020-11-12 19:22:11 +00:00
|
|
|
} else {
|
|
|
|
dataFile := filepath.Join(dataDir, kv.ProtectionDbFileName)
|
2021-09-17 21:55:24 +00:00
|
|
|
if !file.FileExists(dataFile) {
|
2020-11-12 19:22:11 +00:00
|
|
|
log.Warnf("Slashing protection file %s is missing.\n"+
|
|
|
|
"If you changed your --wallet-dir or --datadir, please copy your previous \"validator.db\" file into your current --datadir.\n"+
|
|
|
|
"Disregard this warning if this is the first time you are running this set of keys.", dataFile)
|
|
|
|
}
|
2020-01-08 18:16:17 +00:00
|
|
|
}
|
2020-04-30 23:17:06 +00:00
|
|
|
log.WithField("databasePath", dataDir).Info("Checking DB")
|
2020-01-08 18:16:17 +00:00
|
|
|
|
2021-02-15 20:29:47 +00:00
|
|
|
valDB, err := kv.NewKVStore(cliCtx.Context, dataDir, &kv.Config{
|
|
|
|
PubKeys: nil,
|
|
|
|
InitialMMapSize: cliCtx.Int(cmd.BoltMMapInitialSizeFlag.Name),
|
|
|
|
})
|
2020-08-14 02:49:57 +00:00
|
|
|
if err != nil {
|
2020-09-03 15:11:17 +00:00
|
|
|
return errors.Wrap(err, "could not initialize db")
|
2020-08-14 02:49:57 +00:00
|
|
|
}
|
2021-01-20 14:39:07 +00:00
|
|
|
c.db = valDB
|
2021-01-15 21:35:21 +00:00
|
|
|
if err := valDB.RunUpMigrations(cliCtx.Context); err != nil {
|
2020-12-16 03:33:04 +00:00
|
|
|
return errors.Wrap(err, "could not run database migration")
|
|
|
|
}
|
2021-01-22 23:12:22 +00:00
|
|
|
|
2020-09-30 20:55:56 +00:00
|
|
|
if !cliCtx.Bool(cmd.DisableMonitoringFlag.Name) {
|
2021-01-20 14:39:07 +00:00
|
|
|
if err := c.registerPrometheusService(cliCtx); err != nil {
|
2020-09-30 20:55:56 +00:00
|
|
|
return err
|
|
|
|
}
|
2018-06-20 03:59:02 +00:00
|
|
|
}
|
2022-01-31 16:44:17 +00:00
|
|
|
if err := c.registerValidatorService(cliCtx); err != nil {
|
2020-09-03 15:11:17 +00:00
|
|
|
return err
|
2019-01-13 07:01:11 +00:00
|
|
|
}
|
2020-09-30 20:55:56 +00:00
|
|
|
if cliCtx.Bool(flags.EnableRPCFlag.Name) {
|
2022-01-31 16:44:17 +00:00
|
|
|
if err := c.registerRPCService(cliCtx); err != nil {
|
2020-09-30 20:55:56 +00:00
|
|
|
return err
|
|
|
|
}
|
2021-01-20 14:39:07 +00:00
|
|
|
if err := c.registerRPCGatewayService(cliCtx); err != nil {
|
2020-09-30 20:55:56 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-08-14 02:49:57 +00:00
|
|
|
}
|
2020-09-03 15:11:17 +00:00
|
|
|
return nil
|
2018-06-02 22:29:35 +00:00
|
|
|
}
|
|
|
|
|
2021-01-20 14:39:07 +00:00
|
|
|
func (c *ValidatorClient) initializeForWeb(cliCtx *cli.Context) error {
|
2020-10-20 02:26:31 +00:00
|
|
|
var err error
|
2022-04-11 20:05:40 +00:00
|
|
|
dataDir := cliCtx.String(flags.WalletDirFlag.Name)
|
|
|
|
if cliCtx.IsSet(flags.Web3SignerURLFlag.Name) {
|
|
|
|
c.wallet = wallet.NewWalletForWeb3Signer()
|
|
|
|
} else {
|
|
|
|
// Read the wallet password file from the cli context.
|
|
|
|
if err = setWalletPasswordFilePath(cliCtx); err != nil {
|
|
|
|
return errors.Wrap(err, "could not read wallet password file")
|
|
|
|
}
|
2021-02-15 17:55:28 +00:00
|
|
|
|
2022-04-11 20:05:40 +00:00
|
|
|
// Read the wallet from the specified path.
|
|
|
|
w, err := wallet.OpenWalletOrElseCli(cliCtx, func(cliCtx *cli.Context) (*wallet.Wallet, error) {
|
|
|
|
return nil, nil
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not open wallet")
|
|
|
|
}
|
|
|
|
c.wallet = w
|
|
|
|
if c.wallet != nil {
|
|
|
|
dataDir = c.wallet.AccountsDir()
|
|
|
|
}
|
2020-11-23 22:11:42 +00:00
|
|
|
}
|
2021-02-15 17:55:28 +00:00
|
|
|
|
2020-10-28 17:09:44 +00:00
|
|
|
if cliCtx.String(cmd.DataDirFlag.Name) != cmd.DefaultDataDir() {
|
|
|
|
dataDir = cliCtx.String(cmd.DataDirFlag.Name)
|
|
|
|
}
|
2020-09-03 15:11:17 +00:00
|
|
|
clearFlag := cliCtx.Bool(cmd.ClearDB.Name)
|
|
|
|
forceClearFlag := cliCtx.Bool(cmd.ForceClearDB.Name)
|
2020-10-28 17:09:44 +00:00
|
|
|
|
2020-09-03 15:11:17 +00:00
|
|
|
if clearFlag || forceClearFlag {
|
|
|
|
if dataDir == "" {
|
|
|
|
dataDir = cmd.DefaultDataDir()
|
|
|
|
if dataDir == "" {
|
|
|
|
log.Fatal(
|
2021-01-20 14:39:07 +00:00
|
|
|
"Could not determine your system'c HOME path, please specify a --datadir you wish " +
|
2020-09-03 15:11:17 +00:00
|
|
|
"to use for your validator data",
|
|
|
|
)
|
2018-06-11 22:21:24 +00:00
|
|
|
}
|
2018-06-02 22:29:35 +00:00
|
|
|
|
2020-09-03 15:11:17 +00:00
|
|
|
}
|
2020-12-11 18:31:35 +00:00
|
|
|
if err := clearDB(cliCtx.Context, dataDir, forceClearFlag); err != nil {
|
2020-09-03 15:11:17 +00:00
|
|
|
return err
|
2020-08-25 01:37:25 +00:00
|
|
|
}
|
2020-08-10 17:48:41 +00:00
|
|
|
}
|
2020-09-03 15:11:17 +00:00
|
|
|
log.WithField("databasePath", dataDir).Info("Checking DB")
|
2021-02-15 20:29:47 +00:00
|
|
|
valDB, err := kv.NewKVStore(cliCtx.Context, dataDir, &kv.Config{
|
|
|
|
PubKeys: nil,
|
|
|
|
InitialMMapSize: cliCtx.Int(cmd.BoltMMapInitialSizeFlag.Name),
|
|
|
|
})
|
2020-09-03 15:11:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not initialize db")
|
|
|
|
}
|
2021-01-20 14:39:07 +00:00
|
|
|
c.db = valDB
|
2021-01-15 21:35:21 +00:00
|
|
|
if err := valDB.RunUpMigrations(cliCtx.Context); err != nil {
|
2020-12-16 03:33:04 +00:00
|
|
|
return errors.Wrap(err, "could not run database migration")
|
|
|
|
}
|
2021-01-22 23:12:22 +00:00
|
|
|
|
2020-09-30 20:55:56 +00:00
|
|
|
if !cliCtx.Bool(cmd.DisableMonitoringFlag.Name) {
|
2021-01-20 14:39:07 +00:00
|
|
|
if err := c.registerPrometheusService(cliCtx); err != nil {
|
2020-09-30 20:55:56 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-09-03 15:11:17 +00:00
|
|
|
}
|
2022-01-31 16:44:17 +00:00
|
|
|
if err := c.registerValidatorService(cliCtx); err != nil {
|
2020-09-03 15:11:17 +00:00
|
|
|
return err
|
|
|
|
}
|
2022-01-31 16:44:17 +00:00
|
|
|
if err := c.registerRPCService(cliCtx); err != nil {
|
2020-09-03 15:11:17 +00:00
|
|
|
return err
|
|
|
|
}
|
2021-01-20 14:39:07 +00:00
|
|
|
if err := c.registerRPCGatewayService(cliCtx); err != nil {
|
2020-09-03 15:11:17 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-10-21 22:32:00 +00:00
|
|
|
gatewayHost := cliCtx.String(flags.GRPCGatewayHost.Name)
|
|
|
|
gatewayPort := cliCtx.Int(flags.GRPCGatewayPort.Name)
|
|
|
|
webAddress := fmt.Sprintf("http://%s:%d", gatewayHost, gatewayPort)
|
|
|
|
log.WithField("address", webAddress).Info(
|
|
|
|
"Starting Prysm web UI on address, open in browser to access",
|
|
|
|
)
|
|
|
|
return nil
|
2018-06-04 19:31:42 +00:00
|
|
|
}
|
|
|
|
|
2021-01-20 14:39:07 +00:00
|
|
|
func (c *ValidatorClient) registerPrometheusService(cliCtx *cli.Context) error {
|
2020-12-03 22:28:57 +00:00
|
|
|
var additionalHandlers []prometheus.Handler
|
|
|
|
if cliCtx.IsSet(cmd.EnableBackupWebhookFlag.Name) {
|
|
|
|
additionalHandlers = append(
|
|
|
|
additionalHandlers,
|
|
|
|
prometheus.Handler{
|
|
|
|
Path: "/db/backup",
|
2021-09-14 20:59:51 +00:00
|
|
|
Handler: backup.BackupHandler(c.db, cliCtx.String(cmd.BackupWebhookOutputDir.Name)),
|
2020-12-03 22:28:57 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
2021-02-12 17:45:22 +00:00
|
|
|
service := prometheus.NewService(
|
2021-01-20 14:39:07 +00:00
|
|
|
fmt.Sprintf("%s:%d", c.cliCtx.String(cmd.MonitoringHostFlag.Name), c.cliCtx.Int(flags.MonitoringPortFlag.Name)),
|
|
|
|
c.services,
|
2020-12-03 22:28:57 +00:00
|
|
|
additionalHandlers...,
|
2019-01-13 07:01:11 +00:00
|
|
|
)
|
|
|
|
logrus.AddHook(prometheus.NewLogrusCollector())
|
2021-01-20 14:39:07 +00:00
|
|
|
return c.services.RegisterService(service)
|
2019-01-13 07:01:11 +00:00
|
|
|
}
|
2019-01-23 02:52:39 +00:00
|
|
|
|
2022-01-31 16:44:17 +00:00
|
|
|
func (c *ValidatorClient) registerValidatorService(cliCtx *cli.Context) error {
|
2022-03-21 18:48:02 +00:00
|
|
|
|
2021-01-20 14:39:07 +00:00
|
|
|
endpoint := c.cliCtx.String(flags.BeaconRPCProviderFlag.Name)
|
|
|
|
dataDir := c.cliCtx.String(cmd.DataDirFlag.Name)
|
|
|
|
logValidatorBalances := !c.cliCtx.Bool(flags.DisablePenaltyRewardLogFlag.Name)
|
|
|
|
emitAccountMetrics := !c.cliCtx.Bool(flags.DisableAccountMetricsFlag.Name)
|
|
|
|
cert := c.cliCtx.String(flags.CertFlag.Name)
|
|
|
|
graffiti := c.cliCtx.String(flags.GraffitiFlag.Name)
|
|
|
|
maxCallRecvMsgSize := c.cliCtx.Int(cmd.GrpcMaxCallRecvMsgSizeFlag.Name)
|
|
|
|
grpcRetries := c.cliCtx.Uint(flags.GrpcRetriesFlag.Name)
|
|
|
|
grpcRetryDelay := c.cliCtx.Duration(flags.GrpcRetryDelayFlag.Name)
|
2022-02-01 19:54:19 +00:00
|
|
|
var interopKeysConfig *local.InteropKeymanagerConfig
|
2022-01-31 16:44:17 +00:00
|
|
|
if c.cliCtx.IsSet(flags.InteropNumValidators.Name) {
|
2022-02-01 19:54:19 +00:00
|
|
|
interopKeysConfig = &local.InteropKeymanagerConfig{
|
2022-01-31 16:44:17 +00:00
|
|
|
Offset: cliCtx.Uint64(flags.InteropStartIndex.Name),
|
|
|
|
NumValidatorKeys: cliCtx.Uint64(flags.InteropNumValidators.Name),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-04 23:15:12 +00:00
|
|
|
gStruct := &g.Graffiti{}
|
|
|
|
var err error
|
2021-01-20 14:39:07 +00:00
|
|
|
if c.cliCtx.IsSet(flags.GraffitiFileFlag.Name) {
|
|
|
|
n := c.cliCtx.String(flags.GraffitiFileFlag.Name)
|
2020-12-04 23:15:12 +00:00
|
|
|
gStruct, err = g.ParseGraffitiFile(n)
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Warn("Could not parse graffiti file")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-31 16:44:17 +00:00
|
|
|
wsc, err := web3SignerConfig(c.cliCtx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-06-06 19:32:41 +00:00
|
|
|
bpc, err := proposerSettings(c.cliCtx)
|
2022-03-21 18:48:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-01-20 14:39:07 +00:00
|
|
|
v, err := client.NewValidatorService(c.cliCtx.Context, &client.Config{
|
2022-03-22 18:13:59 +00:00
|
|
|
Endpoint: endpoint,
|
|
|
|
DataDir: dataDir,
|
|
|
|
LogValidatorBalances: logValidatorBalances,
|
|
|
|
EmitAccountMetrics: emitAccountMetrics,
|
|
|
|
CertFlag: cert,
|
|
|
|
GraffitiFlag: g.ParseHexGraffiti(graffiti),
|
|
|
|
GrpcMaxCallRecvMsgSizeFlag: maxCallRecvMsgSize,
|
|
|
|
GrpcRetriesFlag: grpcRetries,
|
|
|
|
GrpcRetryDelay: grpcRetryDelay,
|
|
|
|
GrpcHeadersFlag: c.cliCtx.String(flags.GrpcHeadersFlag.Name),
|
|
|
|
ValDB: c.db,
|
|
|
|
UseWeb: c.cliCtx.Bool(flags.EnableWebFlag.Name),
|
|
|
|
InteropKeysConfig: interopKeysConfig,
|
|
|
|
Wallet: c.wallet,
|
|
|
|
WalletInitializedFeed: c.walletInitialized,
|
|
|
|
GraffitiStruct: gStruct,
|
|
|
|
LogDutyCountDown: c.cliCtx.Bool(flags.EnableDutyCountDown.Name),
|
|
|
|
Web3SignerConfig: wsc,
|
2022-06-06 19:32:41 +00:00
|
|
|
ProposerSettings: bpc,
|
2019-01-30 12:28:53 +00:00
|
|
|
})
|
2019-02-13 23:49:06 +00:00
|
|
|
if err != nil {
|
2021-02-01 17:12:52 +00:00
|
|
|
return errors.Wrap(err, "could not initialize validator service")
|
2019-02-13 23:49:06 +00:00
|
|
|
}
|
2021-06-10 16:54:24 +00:00
|
|
|
|
2021-01-20 14:39:07 +00:00
|
|
|
return c.services.RegisterService(v)
|
2019-01-23 02:52:39 +00:00
|
|
|
}
|
2020-01-04 03:51:53 +00:00
|
|
|
|
2022-06-27 13:34:38 +00:00
|
|
|
func web3SignerConfig(cliCtx *cli.Context) (*remoteweb3signer.SetupConfig, error) {
|
|
|
|
var web3signerConfig *remoteweb3signer.SetupConfig
|
2022-04-11 20:05:40 +00:00
|
|
|
if cliCtx.IsSet(flags.Web3SignerURLFlag.Name) {
|
2022-01-31 16:44:17 +00:00
|
|
|
urlStr := cliCtx.String(flags.Web3SignerURLFlag.Name)
|
2022-02-24 16:24:11 +00:00
|
|
|
u, err := url.ParseRequestURI(urlStr)
|
2022-01-31 16:44:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrapf(err, "web3signer url %s is invalid", urlStr)
|
|
|
|
}
|
2022-02-24 16:24:11 +00:00
|
|
|
if u.Scheme == "" || u.Host == "" {
|
|
|
|
return nil, fmt.Errorf("web3signer url must be in the format of http(s)://host:port url used: %v", urlStr)
|
|
|
|
}
|
2022-06-27 13:34:38 +00:00
|
|
|
web3signerConfig = &remoteweb3signer.SetupConfig{
|
2022-01-31 16:44:17 +00:00
|
|
|
BaseEndpoint: u.String(),
|
|
|
|
GenesisValidatorsRoot: nil,
|
|
|
|
}
|
2022-04-11 20:05:40 +00:00
|
|
|
if cliCtx.IsSet(flags.Web3SignerPublicValidatorKeysFlag.Name) {
|
|
|
|
publicKeysStr := cliCtx.String(flags.Web3SignerPublicValidatorKeysFlag.Name)
|
|
|
|
pURL, err := url.ParseRequestURI(publicKeysStr)
|
|
|
|
if err == nil && pURL.Scheme != "" && pURL.Host != "" {
|
|
|
|
web3signerConfig.PublicKeysURL = publicKeysStr
|
|
|
|
} else {
|
|
|
|
var validatorKeys [][48]byte
|
|
|
|
for _, key := range strings.Split(publicKeysStr, ",") {
|
|
|
|
decodedKey, decodeErr := hexutil.Decode(key)
|
|
|
|
if decodeErr != nil {
|
|
|
|
return nil, errors.Wrapf(decodeErr, "could not decode public key for web3signer: %s", key)
|
|
|
|
}
|
|
|
|
validatorKeys = append(validatorKeys, bytesutil.ToBytes48(decodedKey))
|
2022-01-31 16:44:17 +00:00
|
|
|
}
|
2022-04-11 20:05:40 +00:00
|
|
|
web3signerConfig.ProvidedPublicKeys = validatorKeys
|
2022-01-31 16:44:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return web3signerConfig, nil
|
|
|
|
}
|
|
|
|
|
2022-06-06 19:32:41 +00:00
|
|
|
func proposerSettings(cliCtx *cli.Context) (*validatorServiceConfig.ProposerSettings, error) {
|
|
|
|
var fileConfig *validatorServiceConfig.ProposerSettingsPayload
|
|
|
|
//TODO(10809): remove when fully deprecated
|
2022-03-21 18:48:02 +00:00
|
|
|
if cliCtx.IsSet(flags.FeeRecipientConfigFileFlag.Name) && cliCtx.IsSet(flags.FeeRecipientConfigURLFlag.Name) {
|
2022-05-26 17:47:00 +00:00
|
|
|
return nil, fmt.Errorf("cannot specify both --%s and --%s", flags.FeeRecipientConfigFileFlag.Name, flags.FeeRecipientConfigURLFlag.Name)
|
2022-03-21 18:48:02 +00:00
|
|
|
}
|
2022-06-06 19:32:41 +00:00
|
|
|
|
|
|
|
if cliCtx.IsSet(flags.ProposerSettingsFlag.Name) && cliCtx.IsSet(flags.ProposerSettingsURLFlag.Name) {
|
|
|
|
return nil, errors.New("cannot specify both " + flags.ProposerSettingsFlag.Name + " and " + flags.ProposerSettingsURLFlag.Name)
|
|
|
|
}
|
|
|
|
|
2022-06-06 16:58:52 +00:00
|
|
|
// is overridden by file and URL flags
|
|
|
|
if cliCtx.IsSet(flags.SuggestedFeeRecipientFlag.Name) {
|
|
|
|
suggestedFee := cliCtx.String(flags.SuggestedFeeRecipientFlag.Name)
|
2022-06-06 19:32:41 +00:00
|
|
|
fileConfig = &validatorServiceConfig.ProposerSettingsPayload{
|
2022-06-06 16:58:52 +00:00
|
|
|
ProposeConfig: nil,
|
2022-06-06 19:32:41 +00:00
|
|
|
DefaultConfig: &validatorServiceConfig.ProposerOptionPayload{
|
2022-06-06 16:58:52 +00:00
|
|
|
FeeRecipient: suggestedFee,
|
2022-06-06 19:32:41 +00:00
|
|
|
GasLimit: params.BeaconConfig().DefaultBuilderGasLimit,
|
2022-06-06 16:58:52 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-21 18:48:02 +00:00
|
|
|
if cliCtx.IsSet(flags.FeeRecipientConfigFileFlag.Name) {
|
2022-06-06 19:32:41 +00:00
|
|
|
return nil, errors.New(flags.FeeRecipientConfigFileFlag.Usage)
|
|
|
|
}
|
|
|
|
|
|
|
|
if cliCtx.IsSet(flags.FeeRecipientConfigURLFlag.Name) {
|
|
|
|
return nil, errors.New(flags.FeeRecipientConfigURLFlag.Usage)
|
|
|
|
}
|
|
|
|
|
|
|
|
if cliCtx.IsSet(flags.ProposerSettingsFlag.Name) {
|
|
|
|
if err := unmarshalFromFile(cliCtx.Context, cliCtx.String(flags.ProposerSettingsFlag.Name), &fileConfig); err != nil {
|
2022-03-21 18:48:02 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
2022-06-06 19:32:41 +00:00
|
|
|
if cliCtx.IsSet(flags.ProposerSettingsURLFlag.Name) {
|
|
|
|
if err := unmarshalFromURL(cliCtx.Context, cliCtx.String(flags.ProposerSettingsURLFlag.Name), &fileConfig); err != nil {
|
2022-03-21 18:48:02 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
2022-06-06 16:58:52 +00:00
|
|
|
|
2022-03-22 18:13:59 +00:00
|
|
|
// nothing is set, so just return nil
|
2022-03-21 18:48:02 +00:00
|
|
|
if fileConfig == nil {
|
2022-03-22 18:13:59 +00:00
|
|
|
return nil, nil
|
2022-03-21 18:48:02 +00:00
|
|
|
}
|
|
|
|
//convert file config to proposer config for internal use
|
2022-06-06 19:32:41 +00:00
|
|
|
vpSettings := &validatorServiceConfig.ProposerSettings{}
|
2022-03-21 18:48:02 +00:00
|
|
|
|
|
|
|
// default fileConfig is mandatory
|
|
|
|
if fileConfig.DefaultConfig == nil {
|
|
|
|
return nil, errors.New("default fileConfig is required")
|
|
|
|
}
|
|
|
|
if !common.IsHexAddress(fileConfig.DefaultConfig.FeeRecipient) {
|
|
|
|
return nil, errors.New("default fileConfig fee recipient is not a valid eth1 address")
|
|
|
|
}
|
2022-06-14 18:43:37 +00:00
|
|
|
if err := warnNonChecksummedAddress(fileConfig.DefaultConfig.FeeRecipient); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-06-06 19:32:41 +00:00
|
|
|
vpSettings.DefaultConfig = &validatorServiceConfig.ProposerOption{
|
2022-06-14 18:43:37 +00:00
|
|
|
FeeRecipient: common.HexToAddress(fileConfig.DefaultConfig.FeeRecipient),
|
2022-06-06 19:32:41 +00:00
|
|
|
GasLimit: reviewGasLimit(fileConfig.DefaultConfig.GasLimit),
|
2022-03-21 18:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if fileConfig.ProposeConfig != nil {
|
2022-06-06 19:32:41 +00:00
|
|
|
vpSettings.ProposeConfig = make(map[[fieldparams.BLSPubkeyLength]byte]*validatorServiceConfig.ProposerOption)
|
2022-03-21 18:48:02 +00:00
|
|
|
for key, option := range fileConfig.ProposeConfig {
|
|
|
|
decodedKey, err := hexutil.Decode(key)
|
|
|
|
if err != nil {
|
2022-06-14 18:43:37 +00:00
|
|
|
return nil, errors.Wrapf(err, "could not decode public key %s", key)
|
2022-03-21 18:48:02 +00:00
|
|
|
}
|
|
|
|
if len(decodedKey) != fieldparams.BLSPubkeyLength {
|
|
|
|
return nil, fmt.Errorf("%v is not a bls public key", key)
|
|
|
|
}
|
|
|
|
if option == nil {
|
|
|
|
return nil, fmt.Errorf("fee recipient is required for proposer %s", key)
|
|
|
|
}
|
|
|
|
if !common.IsHexAddress(option.FeeRecipient) {
|
|
|
|
return nil, errors.New("fee recipient is not a valid eth1 address")
|
|
|
|
}
|
2022-06-14 18:43:37 +00:00
|
|
|
if err := warnNonChecksummedAddress(option.FeeRecipient); err != nil {
|
|
|
|
return nil, err
|
2022-05-11 19:36:57 +00:00
|
|
|
}
|
2022-06-06 19:32:41 +00:00
|
|
|
vpSettings.ProposeConfig[bytesutil.ToBytes48(decodedKey)] = &validatorServiceConfig.ProposerOption{
|
2022-06-14 18:43:37 +00:00
|
|
|
FeeRecipient: common.HexToAddress(option.FeeRecipient),
|
2022-06-06 19:32:41 +00:00
|
|
|
GasLimit: reviewGasLimit(option.GasLimit),
|
2022-03-21 18:48:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-06 19:32:41 +00:00
|
|
|
return vpSettings, nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 18:43:37 +00:00
|
|
|
func warnNonChecksummedAddress(feeRecipient string) error {
|
|
|
|
mixedcaseAddress, err := common.NewMixedcaseAddressFromString(feeRecipient)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "could not decode fee recipient %s", feeRecipient)
|
|
|
|
}
|
|
|
|
if !mixedcaseAddress.ValidChecksum() {
|
|
|
|
log.Warnf("Fee recipient %s is not a checksum Ethereum address. "+
|
|
|
|
"The checksummed address is %s and will be used as the fee recipient. "+
|
|
|
|
"We recommend using a mixed-case address (checksum) "+
|
|
|
|
"to prevent spelling mistakes in your fee recipient Ethereum address", feeRecipient, mixedcaseAddress.Address().Hex())
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-06-06 19:32:41 +00:00
|
|
|
func reviewGasLimit(gasLimit uint64) uint64 {
|
|
|
|
// sets gas limit to default if not defined or set to 0
|
|
|
|
if gasLimit == 0 {
|
|
|
|
return params.BeaconConfig().DefaultBuilderGasLimit
|
|
|
|
}
|
|
|
|
//TODO(10810): add in warning for ranges
|
|
|
|
return gasLimit
|
2022-03-21 18:48:02 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 16:44:17 +00:00
|
|
|
func (c *ValidatorClient) registerRPCService(cliCtx *cli.Context) error {
|
2020-08-12 23:33:15 +00:00
|
|
|
var vs *client.ValidatorService
|
2021-01-20 14:39:07 +00:00
|
|
|
if err := c.services.FetchService(&vs); err != nil {
|
2020-08-12 23:33:15 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-11-23 06:29:58 +00:00
|
|
|
validatorGatewayHost := cliCtx.String(flags.GRPCGatewayHost.Name)
|
|
|
|
validatorGatewayPort := cliCtx.Int(flags.GRPCGatewayPort.Name)
|
2020-11-27 18:28:45 +00:00
|
|
|
validatorMonitoringHost := cliCtx.String(cmd.MonitoringHostFlag.Name)
|
|
|
|
validatorMonitoringPort := cliCtx.Int(flags.MonitoringPortFlag.Name)
|
2020-08-14 02:49:57 +00:00
|
|
|
rpcHost := cliCtx.String(flags.RPCHost.Name)
|
|
|
|
rpcPort := cliCtx.Int(flags.RPCPort.Name)
|
2020-09-04 19:03:18 +00:00
|
|
|
nodeGatewayEndpoint := cliCtx.String(flags.BeaconRPCGatewayProviderFlag.Name)
|
2020-12-17 16:26:32 +00:00
|
|
|
beaconClientEndpoint := cliCtx.String(flags.BeaconRPCProviderFlag.Name)
|
2021-01-20 14:39:07 +00:00
|
|
|
maxCallRecvMsgSize := c.cliCtx.Int(cmd.GrpcMaxCallRecvMsgSizeFlag.Name)
|
|
|
|
grpcRetries := c.cliCtx.Uint(flags.GrpcRetriesFlag.Name)
|
|
|
|
grpcRetryDelay := c.cliCtx.Duration(flags.GrpcRetryDelayFlag.Name)
|
2020-10-10 02:07:28 +00:00
|
|
|
walletDir := cliCtx.String(flags.WalletDirFlag.Name)
|
2021-01-20 14:39:07 +00:00
|
|
|
grpcHeaders := c.cliCtx.String(flags.GrpcHeadersFlag.Name)
|
|
|
|
clientCert := c.cliCtx.String(flags.CertFlag.Name)
|
2020-09-09 09:48:52 +00:00
|
|
|
server := rpc.NewServer(cliCtx.Context, &rpc.Config{
|
2021-01-20 14:39:07 +00:00
|
|
|
ValDB: c.db,
|
2020-12-17 16:26:32 +00:00
|
|
|
Host: rpcHost,
|
|
|
|
Port: fmt.Sprintf("%d", rpcPort),
|
2021-01-20 14:39:07 +00:00
|
|
|
WalletInitializedFeed: c.walletInitialized,
|
2020-12-17 16:26:32 +00:00
|
|
|
ValidatorService: vs,
|
|
|
|
SyncChecker: vs,
|
|
|
|
GenesisFetcher: vs,
|
|
|
|
NodeGatewayEndpoint: nodeGatewayEndpoint,
|
|
|
|
WalletDir: walletDir,
|
2021-01-20 14:39:07 +00:00
|
|
|
Wallet: c.wallet,
|
2020-12-17 16:26:32 +00:00
|
|
|
ValidatorGatewayHost: validatorGatewayHost,
|
|
|
|
ValidatorGatewayPort: validatorGatewayPort,
|
|
|
|
ValidatorMonitoringHost: validatorMonitoringHost,
|
|
|
|
ValidatorMonitoringPort: validatorMonitoringPort,
|
|
|
|
BeaconClientEndpoint: beaconClientEndpoint,
|
|
|
|
ClientMaxCallRecvMsgSize: maxCallRecvMsgSize,
|
|
|
|
ClientGrpcRetries: grpcRetries,
|
|
|
|
ClientGrpcRetryDelay: grpcRetryDelay,
|
|
|
|
ClientGrpcHeaders: strings.Split(grpcHeaders, ","),
|
|
|
|
ClientWithCert: clientCert,
|
2020-08-14 02:49:57 +00:00
|
|
|
})
|
2021-01-20 14:39:07 +00:00
|
|
|
return c.services.RegisterService(server)
|
2020-08-12 23:33:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-20 14:39:07 +00:00
|
|
|
func (c *ValidatorClient) registerRPCGatewayService(cliCtx *cli.Context) error {
|
2020-08-14 02:49:57 +00:00
|
|
|
gatewayHost := cliCtx.String(flags.GRPCGatewayHost.Name)
|
2020-10-29 21:38:47 +00:00
|
|
|
if gatewayHost != flags.DefaultGatewayHost {
|
|
|
|
log.WithField("web-host", gatewayHost).Warn(
|
|
|
|
"You are using a non-default web host. Web traffic is served by HTTP, so be wary of " +
|
|
|
|
"changing this parameter if you are exposing this host to the Internet!",
|
|
|
|
)
|
|
|
|
}
|
2020-08-14 02:49:57 +00:00
|
|
|
gatewayPort := cliCtx.Int(flags.GRPCGatewayPort.Name)
|
|
|
|
rpcHost := cliCtx.String(flags.RPCHost.Name)
|
|
|
|
rpcPort := cliCtx.Int(flags.RPCPort.Name)
|
|
|
|
rpcAddr := fmt.Sprintf("%s:%d", rpcHost, rpcPort)
|
|
|
|
gatewayAddress := fmt.Sprintf("%s:%d", gatewayHost, gatewayPort)
|
2022-02-24 18:01:37 +00:00
|
|
|
timeout := cliCtx.Int(cmd.ApiTimeoutFlag.Name)
|
2022-02-09 17:18:49 +00:00
|
|
|
var allowedOrigins []string
|
|
|
|
if cliCtx.IsSet(flags.GPRCGatewayCorsDomain.Name) {
|
|
|
|
allowedOrigins = strings.Split(cliCtx.String(flags.GPRCGatewayCorsDomain.Name), ",")
|
|
|
|
} else {
|
|
|
|
allowedOrigins = strings.Split(flags.GPRCGatewayCorsDomain.Value, ",")
|
|
|
|
}
|
2021-06-18 13:35:13 +00:00
|
|
|
maxCallSize := cliCtx.Uint64(cmd.GrpcMaxCallRecvMsgSizeFlag.Name)
|
|
|
|
|
|
|
|
registrations := []gateway.PbHandlerRegistration{
|
2021-08-18 21:24:01 +00:00
|
|
|
validatorpb.RegisterAuthHandler,
|
|
|
|
validatorpb.RegisterWalletHandler,
|
2021-06-18 13:35:13 +00:00
|
|
|
pb.RegisterHealthHandler,
|
2021-10-06 19:07:29 +00:00
|
|
|
validatorpb.RegisterHealthHandler,
|
2021-08-18 21:24:01 +00:00
|
|
|
validatorpb.RegisterAccountsHandler,
|
|
|
|
validatorpb.RegisterBeaconHandler,
|
|
|
|
validatorpb.RegisterSlashingProtectionHandler,
|
2021-12-07 20:26:21 +00:00
|
|
|
ethpbservice.RegisterKeyManagementHandler,
|
2021-06-18 13:35:13 +00:00
|
|
|
}
|
2021-12-07 20:26:21 +00:00
|
|
|
gwmux := gwruntime.NewServeMux(
|
2021-06-18 13:35:13 +00:00
|
|
|
gwruntime.WithMarshalerOption(gwruntime.MIMEWildcard, &gwruntime.HTTPBodyMarshaler{
|
|
|
|
Marshaler: &gwruntime.JSONPb{
|
|
|
|
MarshalOptions: protojson.MarshalOptions{
|
|
|
|
EmitUnpopulated: true,
|
2021-12-07 20:26:21 +00:00
|
|
|
UseProtoNames: true,
|
2021-06-18 13:35:13 +00:00
|
|
|
},
|
|
|
|
UnmarshalOptions: protojson.UnmarshalOptions{
|
|
|
|
DiscardUnknown: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
gwruntime.WithMarshalerOption(
|
|
|
|
"text/event-stream", &gwruntime.EventSourceJSONPb{},
|
|
|
|
),
|
2022-06-16 15:10:23 +00:00
|
|
|
gwruntime.WithForwardResponseOption(gateway.HttpResponseModifier),
|
2021-06-18 13:35:13 +00:00
|
|
|
)
|
2021-12-07 20:26:21 +00:00
|
|
|
muxHandler := func(apiMware *apimiddleware.ApiProxyMiddleware, h http.HandlerFunc, w http.ResponseWriter, req *http.Request) {
|
|
|
|
// The validator gateway handler requires this special logic as it serves two kinds of APIs, namely
|
|
|
|
// the standard validator keymanager API under the /eth namespace, and the Prysm internal
|
|
|
|
// validator API under the /api namespace. Finally, it also serves requests to host the validator web UI.
|
|
|
|
if strings.HasPrefix(req.URL.Path, "/api/eth/") {
|
|
|
|
req.URL.Path = strings.Replace(req.URL.Path, "/api", "", 1)
|
|
|
|
// If the prefix has /eth/, we handle it with the standard API gateway middleware.
|
|
|
|
apiMware.ServeHTTP(w, req)
|
|
|
|
} else if strings.HasPrefix(req.URL.Path, "/api") {
|
|
|
|
req.URL.Path = strings.Replace(req.URL.Path, "/api", "", 1)
|
|
|
|
// Else, we handle with the Prysm API gateway without a middleware.
|
|
|
|
h(w, req)
|
2021-06-18 13:35:13 +00:00
|
|
|
} else {
|
2021-12-07 20:26:21 +00:00
|
|
|
// Finally, we handle with the web server.
|
2021-06-18 13:35:13 +00:00
|
|
|
web.Handler(w, req)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-24 09:25:42 +00:00
|
|
|
pbHandler := &gateway.PbMux{
|
2021-06-18 13:35:13 +00:00
|
|
|
Registrations: registrations,
|
2021-12-07 20:26:21 +00:00
|
|
|
Patterns: []string{"/accounts/", "/v2/", "/internal/eth/v1/"},
|
|
|
|
Mux: gwmux,
|
|
|
|
}
|
|
|
|
opts := []gateway.Option{
|
|
|
|
gateway.WithRemoteAddr(rpcAddr),
|
|
|
|
gateway.WithGatewayAddr(gatewayAddress),
|
|
|
|
gateway.WithMaxCallRecvMsgSize(maxCallSize),
|
|
|
|
gateway.WithPbHandlers([]*gateway.PbMux{pbHandler}),
|
|
|
|
gateway.WithAllowedOrigins(allowedOrigins),
|
2022-06-27 13:34:38 +00:00
|
|
|
gateway.WithApiMiddleware(&validatormiddleware.ValidatorEndpointFactory{}),
|
2021-12-07 20:26:21 +00:00
|
|
|
gateway.WithMuxHandler(muxHandler),
|
2022-02-24 18:01:37 +00:00
|
|
|
gateway.WithTimeout(uint64(timeout)),
|
2021-12-07 20:26:21 +00:00
|
|
|
}
|
|
|
|
gw, err := gateway.New(cliCtx.Context, opts...)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-06-18 13:35:13 +00:00
|
|
|
}
|
|
|
|
return c.services.RegisterService(gw)
|
2021-02-15 17:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func setWalletPasswordFilePath(cliCtx *cli.Context) error {
|
|
|
|
walletDir := cliCtx.String(flags.WalletDirFlag.Name)
|
|
|
|
defaultWalletPasswordFilePath := filepath.Join(walletDir, wallet.DefaultWalletPasswordFile)
|
2021-09-17 21:55:24 +00:00
|
|
|
if file.FileExists(defaultWalletPasswordFilePath) {
|
2021-02-15 17:55:28 +00:00
|
|
|
// Ensure file has proper permissions.
|
2021-09-17 21:55:24 +00:00
|
|
|
hasPerms, err := file.HasReadWritePermissions(defaultWalletPasswordFilePath)
|
2021-02-15 17:55:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if !hasPerms {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"wallet password file %s does not have proper 0600 permissions",
|
|
|
|
defaultWalletPasswordFilePath,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the filepath into the cli context.
|
|
|
|
if err := cliCtx.Set(flags.WalletPasswordFileFlag.Name, defaultWalletPasswordFilePath); err != nil {
|
|
|
|
return errors.Wrap(err, "could not set default wallet password file path")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
2020-08-14 02:49:57 +00:00
|
|
|
}
|
|
|
|
|
2020-12-11 18:31:35 +00:00
|
|
|
func clearDB(ctx context.Context, dataDir string, force bool) error {
|
2020-01-08 18:16:17 +00:00
|
|
|
var err error
|
|
|
|
clearDBConfirmed := force
|
|
|
|
|
|
|
|
if !force {
|
|
|
|
actionText := "This will delete your validator's historical actions database stored in your data directory. " +
|
|
|
|
"This may lead to potential slashing - do you want to proceed? (Y/N)"
|
|
|
|
deniedText := "The historical actions database will not be deleted. No changes have been made."
|
|
|
|
clearDBConfirmed, err = cmd.ConfirmAction(actionText, deniedText)
|
|
|
|
if err != nil {
|
2020-06-23 21:11:20 +00:00
|
|
|
return errors.Wrapf(err, "Could not clear DB in dir %s", dataDir)
|
2020-01-08 18:16:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if clearDBConfirmed {
|
2021-02-15 20:29:47 +00:00
|
|
|
valDB, err := kv.NewKVStore(ctx, dataDir, &kv.Config{})
|
2020-01-08 18:16:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "Could not create DB in dir %s", dataDir)
|
|
|
|
}
|
2020-10-09 09:28:35 +00:00
|
|
|
if err := valDB.Close(); err != nil {
|
|
|
|
return errors.Wrapf(err, "could not close DB in dir %s", dataDir)
|
|
|
|
}
|
2020-01-08 18:16:17 +00:00
|
|
|
|
|
|
|
log.Warning("Removing database")
|
|
|
|
if err := valDB.ClearDB(); err != nil {
|
|
|
|
return errors.Wrapf(err, "Could not clear DB in dir %s", dataDir)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2022-03-10 20:25:26 +00:00
|
|
|
|
|
|
|
func unmarshalFromURL(ctx context.Context, from string, to interface{}) error {
|
|
|
|
u, err := url.ParseRequestURI(from)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if u.Scheme == "" || u.Host == "" {
|
|
|
|
return fmt.Errorf("invalid URL: %s", from)
|
|
|
|
}
|
|
|
|
req, reqerr := http.NewRequestWithContext(ctx, http.MethodGet, from, nil)
|
|
|
|
if reqerr != nil {
|
|
|
|
return errors.Wrap(reqerr, "failed to create http request")
|
|
|
|
}
|
|
|
|
req.Header.Set("Content-Type", "application/json")
|
|
|
|
resp, resperr := http.DefaultClient.Do(req)
|
|
|
|
if resperr != nil {
|
|
|
|
return errors.Wrap(resperr, "failed to send http request")
|
|
|
|
}
|
|
|
|
defer func(Body io.ReadCloser) {
|
|
|
|
err = Body.Close()
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("failed to close response body")
|
|
|
|
}
|
|
|
|
}(resp.Body)
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
|
return errors.Errorf("http request to %v failed with status code %d", from, resp.StatusCode)
|
|
|
|
}
|
|
|
|
if decodeerr := json.NewDecoder(resp.Body).Decode(&to); decodeerr != nil {
|
|
|
|
return errors.Wrap(decodeerr, "failed to decode http response")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func unmarshalFromFile(ctx context.Context, from string, to interface{}) error {
|
|
|
|
if ctx == nil {
|
|
|
|
return errors.New("node: nil context passed to unmarshalFromFile")
|
|
|
|
}
|
|
|
|
cleanpath := filepath.Clean(from)
|
2022-06-06 19:32:41 +00:00
|
|
|
b, err := os.ReadFile(cleanpath)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to open file")
|
2022-03-10 20:25:26 +00:00
|
|
|
}
|
2022-06-06 19:32:41 +00:00
|
|
|
|
|
|
|
if err := yaml.Unmarshal(b, to); err != nil {
|
|
|
|
return errors.Wrap(err, "failed to unmarshal yaml file")
|
2022-03-10 20:25:26 +00:00
|
|
|
}
|
2022-06-06 19:32:41 +00:00
|
|
|
|
2022-03-10 20:25:26 +00:00
|
|
|
return nil
|
|
|
|
}
|
2022-06-18 12:13:36 +00:00
|
|
|
|
|
|
|
func configureFastSSZHashingAlgorithm() {
|
|
|
|
if features.Get().EnableVectorizedHTR {
|
|
|
|
fastssz.EnableVectorizedHTR = true
|
|
|
|
}
|
|
|
|
}
|