mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-03 00:27:38 +00:00
Add error if chain-config-file used concurrently with network (#10863)
* Add error if chain-config-file used with network If the chain-config-file flag is used concurrently with the network flag then error and exit. Related to #10822. * Add config file name to error message with `fmt` Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * Add unit test for hasNetworkFlag * Add list of network flags to features * Fix imports * Run gazelle * retrigger checks Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
This commit is contained in:
parent
648ab9f2c2
commit
39a7988e9e
@ -85,6 +85,7 @@ go_test(
|
||||
"//beacon-chain/monitor:go_default_library",
|
||||
"//cmd:go_default_library",
|
||||
"//cmd/beacon-chain/flags:go_default_library",
|
||||
"//config/features:go_default_library",
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//consensus-types/primitives:go_default_library",
|
||||
|
@ -117,6 +117,9 @@ func New(cliCtx *cli.Context, opts ...Option) (*BeaconNode, error) {
|
||||
return nil, err
|
||||
}
|
||||
prereqs.WarnIfPlatformNotSupported(cliCtx.Context)
|
||||
if hasNetworkFlag(cliCtx) && cliCtx.IsSet(cmd.ChainConfigFileFlag.Name) {
|
||||
return nil, fmt.Errorf("%s cannot be passed concurrently with network flag", cmd.ChainConfigFileFlag.Name)
|
||||
}
|
||||
if err := features.ConfigureBeaconChain(cliCtx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -970,3 +973,14 @@ func (b *BeaconNode) registerBuilderService() error {
|
||||
}
|
||||
return b.services.RegisterService(svc)
|
||||
}
|
||||
|
||||
func hasNetworkFlag(cliCtx *cli.Context) bool {
|
||||
for _, flag := range features.NetworkFlags {
|
||||
for _, name := range flag.Names() {
|
||||
if cliCtx.IsSet(name) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/monitor"
|
||||
"github.com/prysmaticlabs/prysm/v3/cmd"
|
||||
"github.com/prysmaticlabs/prysm/v3/cmd/beacon-chain/flags"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/features"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
@ -171,3 +172,45 @@ func TestMonitor_RegisteredCorrectly(t *testing.T) {
|
||||
require.Equal(t, true, mService.TrackedValidators[2])
|
||||
require.Equal(t, false, mService.TrackedValidators[100])
|
||||
}
|
||||
|
||||
func Test_hasNetworkFlag(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
networkName string
|
||||
networkValue string
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "Prater testnet",
|
||||
networkName: features.PraterTestnet.Name,
|
||||
networkValue: "prater",
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "Mainnet",
|
||||
networkName: features.Mainnet.Name,
|
||||
networkValue: "mainnet",
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "No network flag",
|
||||
networkName: "",
|
||||
networkValue: "",
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.String(tt.networkName, tt.networkValue, tt.name)
|
||||
|
||||
cliCtx := cli.NewContext(&cli.App{}, set, nil)
|
||||
err := cliCtx.Set(tt.networkName, tt.networkValue)
|
||||
require.NoError(t, err)
|
||||
|
||||
if got := hasNetworkFlag(cliCtx); got != tt.want {
|
||||
t.Errorf("hasNetworkFlag() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -179,3 +179,11 @@ var BeaconChainFlags = append(deprecatedBeaconFlags, append(deprecatedFlags, []c
|
||||
var E2EBeaconChainFlags = []string{
|
||||
"--dev",
|
||||
}
|
||||
|
||||
// NetworkFlags contains a list of network flags.
|
||||
var NetworkFlags = []cli.Flag{
|
||||
Mainnet,
|
||||
PraterTestnet,
|
||||
RopstenTestnet,
|
||||
SepoliaTestnet,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user