mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
Extract node configuration to separate file (#8744)
* Extract node configuration to separate file * rename WarnIfNotSupported * rename configuration to config Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
parent
97b4b86ddf
commit
389bad7d24
@ -4,6 +4,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_test")
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"config.go",
|
||||
"log.go",
|
||||
"node.go",
|
||||
],
|
||||
|
84
beacon-chain/node/config.go
Normal file
84
beacon-chain/node/config.go
Normal file
@ -0,0 +1,84 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags"
|
||||
"github.com/prysmaticlabs/prysm/shared/cmd"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"github.com/prysmaticlabs/prysm/shared/tracing"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func configureTracing(cliCtx *cli.Context) error {
|
||||
return tracing.Setup(
|
||||
"beacon-chain", // service name
|
||||
cliCtx.String(cmd.TracingProcessNameFlag.Name),
|
||||
cliCtx.String(cmd.TracingEndpointFlag.Name),
|
||||
cliCtx.Float64(cmd.TraceSampleFractionFlag.Name),
|
||||
cliCtx.Bool(cmd.EnableTracingFlag.Name),
|
||||
)
|
||||
}
|
||||
|
||||
func configureChainConfig(cliCtx *cli.Context) {
|
||||
if cliCtx.IsSet(cmd.ChainConfigFileFlag.Name) {
|
||||
chainConfigFileName := cliCtx.String(cmd.ChainConfigFileFlag.Name)
|
||||
params.LoadChainConfigFile(chainConfigFileName)
|
||||
}
|
||||
}
|
||||
|
||||
func configureHistoricalSlasher(cliCtx *cli.Context) {
|
||||
if cliCtx.Bool(flags.HistoricalSlasherNode.Name) {
|
||||
c := params.BeaconConfig()
|
||||
// Save a state every 4 epochs.
|
||||
c.SlotsPerArchivedPoint = params.BeaconConfig().SlotsPerEpoch * 4
|
||||
params.OverrideBeaconConfig(c)
|
||||
cmdConfig := cmd.Get()
|
||||
// Allow up to 4096 attestations at a time to be requested from the beacon nde.
|
||||
cmdConfig.MaxRPCPageSize = int(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().MaxAttestations))
|
||||
cmd.Init(cmdConfig)
|
||||
log.Warnf(
|
||||
"Setting %d slots per archive point and %d max RPC page size for historical slasher usage. This requires additional storage",
|
||||
c.SlotsPerArchivedPoint,
|
||||
cmdConfig.MaxRPCPageSize,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func configureSlotsPerArchivedPoint(cliCtx *cli.Context) {
|
||||
if cliCtx.IsSet(flags.SlotsPerArchivedPoint.Name) {
|
||||
c := params.BeaconConfig()
|
||||
c.SlotsPerArchivedPoint = types.Slot(cliCtx.Int(flags.SlotsPerArchivedPoint.Name))
|
||||
params.OverrideBeaconConfig(c)
|
||||
}
|
||||
}
|
||||
|
||||
func configureProofOfWork(cliCtx *cli.Context) {
|
||||
if cliCtx.IsSet(flags.ChainID.Name) {
|
||||
c := params.BeaconConfig()
|
||||
c.DepositChainID = cliCtx.Uint64(flags.ChainID.Name)
|
||||
params.OverrideBeaconConfig(c)
|
||||
}
|
||||
if cliCtx.IsSet(flags.NetworkID.Name) {
|
||||
c := params.BeaconConfig()
|
||||
c.DepositNetworkID = cliCtx.Uint64(flags.NetworkID.Name)
|
||||
params.OverrideBeaconConfig(c)
|
||||
}
|
||||
if cliCtx.IsSet(flags.DepositContractFlag.Name) {
|
||||
c := params.BeaconConfig()
|
||||
c.DepositContractAddress = cliCtx.String(flags.DepositContractFlag.Name)
|
||||
params.OverrideBeaconConfig(c)
|
||||
}
|
||||
}
|
||||
|
||||
func configureNetwork(cliCtx *cli.Context) {
|
||||
if cliCtx.IsSet(cmd.BootstrapNode.Name) {
|
||||
c := params.BeaconNetworkConfig()
|
||||
c.BootstrapNodes = cliCtx.StringSlice(cmd.BootstrapNode.Name)
|
||||
params.OverrideBeaconNetworkConfig(c)
|
||||
}
|
||||
if cliCtx.IsSet(flags.ContractDeploymentBlock.Name) {
|
||||
networkCfg := params.BeaconNetworkConfig()
|
||||
networkCfg.ContractDeploymentBlock = uint64(cliCtx.Int(flags.ContractDeploymentBlock.Name))
|
||||
params.OverrideBeaconNetworkConfig(networkCfg)
|
||||
}
|
||||
}
|
@ -17,7 +17,6 @@ import (
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/pkg/errors"
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
||||
@ -47,7 +46,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/shared/prereq"
|
||||
"github.com/prysmaticlabs/prysm/shared/prometheus"
|
||||
"github.com/prysmaticlabs/prysm/shared/sliceutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/tracing"
|
||||
"github.com/prysmaticlabs/prysm/shared/version"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -81,78 +79,18 @@ type BeaconNode struct {
|
||||
// New creates a new node instance, sets up configuration options, and registers
|
||||
// every required service to the node.
|
||||
func New(cliCtx *cli.Context) (*BeaconNode, error) {
|
||||
if err := tracing.Setup(
|
||||
"beacon-chain", // service name
|
||||
cliCtx.String(cmd.TracingProcessNameFlag.Name),
|
||||
cliCtx.String(cmd.TracingEndpointFlag.Name),
|
||||
cliCtx.Float64(cmd.TraceSampleFractionFlag.Name),
|
||||
cliCtx.Bool(cmd.EnableTracingFlag.Name),
|
||||
); err != nil {
|
||||
if err := configureTracing(cliCtx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Warn if user's platform is not supported
|
||||
prereq.WarnIfNotSupported(cliCtx.Context)
|
||||
|
||||
prereq.WarnIfPlatformNotSupported(cliCtx.Context)
|
||||
featureconfig.ConfigureBeaconChain(cliCtx)
|
||||
cmd.ConfigureBeaconChain(cliCtx)
|
||||
flags.ConfigureGlobalFlags(cliCtx)
|
||||
|
||||
if cliCtx.IsSet(cmd.ChainConfigFileFlag.Name) {
|
||||
chainConfigFileName := cliCtx.String(cmd.ChainConfigFileFlag.Name)
|
||||
params.LoadChainConfigFile(chainConfigFileName)
|
||||
}
|
||||
|
||||
if cliCtx.Bool(flags.HistoricalSlasherNode.Name) {
|
||||
c := params.BeaconConfig()
|
||||
// Save a state every 4 epochs.
|
||||
c.SlotsPerArchivedPoint = params.BeaconConfig().SlotsPerEpoch * 4
|
||||
params.OverrideBeaconConfig(c)
|
||||
cmdConfig := cmd.Get()
|
||||
// Allow up to 4096 attestations at a time to be requested from the beacon nde.
|
||||
cmdConfig.MaxRPCPageSize = int(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().MaxAttestations))
|
||||
cmd.Init(cmdConfig)
|
||||
log.Warnf(
|
||||
"Setting %d slots per archive point and %d max RPC page size for historical slasher usage. This requires additional storage",
|
||||
c.SlotsPerArchivedPoint,
|
||||
cmdConfig.MaxRPCPageSize,
|
||||
)
|
||||
}
|
||||
|
||||
if cliCtx.IsSet(flags.SlotsPerArchivedPoint.Name) {
|
||||
c := params.BeaconConfig()
|
||||
c.SlotsPerArchivedPoint = types.Slot(cliCtx.Int(flags.SlotsPerArchivedPoint.Name))
|
||||
params.OverrideBeaconConfig(c)
|
||||
}
|
||||
|
||||
// ETH PoW related flags.
|
||||
if cliCtx.IsSet(flags.ChainID.Name) {
|
||||
c := params.BeaconConfig()
|
||||
c.DepositChainID = cliCtx.Uint64(flags.ChainID.Name)
|
||||
params.OverrideBeaconConfig(c)
|
||||
}
|
||||
if cliCtx.IsSet(flags.NetworkID.Name) {
|
||||
c := params.BeaconConfig()
|
||||
c.DepositNetworkID = cliCtx.Uint64(flags.NetworkID.Name)
|
||||
params.OverrideBeaconConfig(c)
|
||||
}
|
||||
if cliCtx.IsSet(flags.DepositContractFlag.Name) {
|
||||
c := params.BeaconConfig()
|
||||
c.DepositContractAddress = cliCtx.String(flags.DepositContractFlag.Name)
|
||||
params.OverrideBeaconConfig(c)
|
||||
}
|
||||
|
||||
// Setting chain network specific flags.
|
||||
if cliCtx.IsSet(cmd.BootstrapNode.Name) {
|
||||
c := params.BeaconNetworkConfig()
|
||||
c.BootstrapNodes = cliCtx.StringSlice(cmd.BootstrapNode.Name)
|
||||
params.OverrideBeaconNetworkConfig(c)
|
||||
}
|
||||
if cliCtx.IsSet(flags.ContractDeploymentBlock.Name) {
|
||||
networkCfg := params.BeaconNetworkConfig()
|
||||
networkCfg.ContractDeploymentBlock = uint64(cliCtx.Int(flags.ContractDeploymentBlock.Name))
|
||||
params.OverrideBeaconNetworkConfig(networkCfg)
|
||||
}
|
||||
configureChainConfig(cliCtx)
|
||||
configureHistoricalSlasher(cliCtx)
|
||||
configureSlotsPerArchivedPoint(cliCtx)
|
||||
configureProofOfWork(cliCtx)
|
||||
configureNetwork(cliCtx)
|
||||
|
||||
registry := shared.NewServiceRegistry()
|
||||
|
||||
|
@ -94,8 +94,8 @@ func meetsMinPlatformReqs(ctx context.Context) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// WarnIfNotSupported warns if the user's platform is not supported or if it fails to detect user's platform
|
||||
func WarnIfNotSupported(ctx context.Context) {
|
||||
// WarnIfPlatformNotSupported warns if the user's platform is not supported or if it fails to detect user's platform
|
||||
func WarnIfPlatformNotSupported(ctx context.Context) {
|
||||
supported, err := meetsMinPlatformReqs(ctx)
|
||||
if err != nil {
|
||||
log.Warnf("Failed to detect host platform: %v", err)
|
||||
|
@ -106,7 +106,7 @@ func TestWarnIfNotSupported(t *testing.T) {
|
||||
runtimeOS = "linux"
|
||||
runtimeArch = "amd64"
|
||||
hook := logTest.NewGlobal()
|
||||
WarnIfNotSupported(context.Background())
|
||||
WarnIfPlatformNotSupported(context.Background())
|
||||
require.LogsDoNotContain(t, hook, "Failed to detect host platform")
|
||||
require.LogsDoNotContain(t, hook, "platform is not supported")
|
||||
|
||||
@ -116,13 +116,13 @@ func TestWarnIfNotSupported(t *testing.T) {
|
||||
runtimeOS = "darwin"
|
||||
runtimeArch = "amd64"
|
||||
hook = logTest.NewGlobal()
|
||||
WarnIfNotSupported(context.Background())
|
||||
WarnIfPlatformNotSupported(context.Background())
|
||||
require.LogsContain(t, hook, "Failed to detect host platform")
|
||||
require.LogsContain(t, hook, "error parsing version")
|
||||
|
||||
runtimeOS = "falseOs"
|
||||
runtimeArch = "falseArch"
|
||||
hook = logTest.NewGlobal()
|
||||
WarnIfNotSupported(context.Background())
|
||||
WarnIfPlatformNotSupported(context.Background())
|
||||
require.LogsContain(t, hook, "platform is not supported")
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ func New(cliCtx *cli.Context) (*SlasherNode, error) {
|
||||
}
|
||||
|
||||
// Warn if user's platform is not supported
|
||||
prereq.WarnIfNotSupported(cliCtx.Context)
|
||||
prereq.WarnIfPlatformNotSupported(cliCtx.Context)
|
||||
|
||||
if cliCtx.Bool(flags.EnableHistoricalDetectionFlag.Name) {
|
||||
// Set the max RPC size to 4096 as configured by --historical-slasher-node for optimal historical detection.
|
||||
|
@ -76,7 +76,7 @@ func NewValidatorClient(cliCtx *cli.Context) (*ValidatorClient, error) {
|
||||
logrus.SetLevel(level)
|
||||
|
||||
// Warn if user's platform is not supported
|
||||
prereq.WarnIfNotSupported(cliCtx.Context)
|
||||
prereq.WarnIfPlatformNotSupported(cliCtx.Context)
|
||||
|
||||
registry := shared.NewServiceRegistry()
|
||||
ctx, cancel := context.WithCancel(cliCtx.Context)
|
||||
|
Loading…
Reference in New Issue
Block a user