From 1c9d402a505357c1301023581475b5e0a708a3cc Mon Sep 17 00:00:00 2001 From: Kaloyan Tanev Date: Thu, 3 Oct 2024 14:58:41 +0300 Subject: [PATCH 1/2] Add custom testnet flags for exits --- cmd/createcluster_internal_test.go | 6 ++++-- cmd/exit.go | 27 +++++++++++++++++++++++++++ cmd/exit_broadcast.go | 13 +++++++++++++ cmd/exit_fetch.go | 12 ++++++++++++ cmd/exit_list.go | 12 ++++++++++++ cmd/exit_sign.go | 12 ++++++++++++ 6 files changed, 80 insertions(+), 2 deletions(-) diff --git a/cmd/createcluster_internal_test.go b/cmd/createcluster_internal_test.go index a611206c1..9fb436951 100644 --- a/cmd/createcluster_internal_test.go +++ b/cmd/createcluster_internal_test.go @@ -824,10 +824,12 @@ func TestClusterCLI(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { cmd := newCreateCmd(newCreateClusterCmd(runCreateCluster)) + charonDir := testutil.CreateTempCharonDir(t) + clusterDirArg := "--cluster-dir=" + charonDir if test.threshold != "" { - cmd.SetArgs([]string{"cluster", test.nodes, test.feeRecipient, test.withdrawal, test.network, test.numValidators, test.threshold}) + cmd.SetArgs([]string{"cluster", clusterDirArg, test.nodes, test.feeRecipient, test.withdrawal, test.network, test.numValidators, test.threshold}) } else { - cmd.SetArgs([]string{"cluster", test.nodes, test.feeRecipient, test.withdrawal, test.network, test.numValidators}) + cmd.SetArgs([]string{"cluster", clusterDirArg, test.nodes, test.feeRecipient, test.withdrawal, test.network, test.numValidators}) } err := cmd.Execute() diff --git a/cmd/exit.go b/cmd/exit.go index 59d8155f9..2f933aa4c 100644 --- a/cmd/exit.go +++ b/cmd/exit.go @@ -13,6 +13,7 @@ import ( "github.com/obolnetwork/charon/app/errors" "github.com/obolnetwork/charon/app/eth2wrap" "github.com/obolnetwork/charon/app/log" + "github.com/obolnetwork/charon/eth2util" "github.com/obolnetwork/charon/eth2util/signing" "github.com/obolnetwork/charon/tbls" ) @@ -36,6 +37,7 @@ type exitConfig struct { ExitFromFileDir string Log log.Config All bool + testnetConfig eth2util.Network } func newExitCmd(cmds ...*cobra.Command) *cobra.Command { @@ -67,6 +69,11 @@ const ( publishTimeout validatorIndex all + testnetName + testnetForkVersion + testnetChainID + testnetGenesisTimestamp + testnetCapellaHardFork ) func (ef exitFlag) String() string { @@ -99,6 +106,16 @@ func (ef exitFlag) String() string { return "validator-index" case all: return "all" + case testnetName: + return "testnet-name" + case testnetForkVersion: + return "testnet-fork-version" + case testnetChainID: + return "testnet-chain-id" + case testnetGenesisTimestamp: + return "testnet-genesis-timestamp" + case testnetCapellaHardFork: + return "testnet-capella-hard-fork" default: return "unknown" } @@ -150,6 +167,16 @@ func bindExitFlags(cmd *cobra.Command, config *exitConfig, flags []exitCLIFlag) cmd.Flags().Uint64Var(&config.ValidatorIndex, validatorIndex.String(), 0, "Validator index of the validator to exit, the associated public key must be present in the cluster lock manifest. If --validator-public-key is also provided, validator existence won't be checked on the beacon chain.") case all: cmd.Flags().BoolVar(&config.All, all.String(), false, "Exit all currently active validators in the cluster.") + case testnetName: + cmd.Flags().StringVar(&config.testnetConfig.Name, testnetName.String(), "", "Name of the custom test network.") + case testnetForkVersion: + cmd.Flags().StringVar(&config.testnetConfig.GenesisForkVersionHex, testnetForkVersion.String(), "", "Genesis fork version of the custom test network (in hex).") + case testnetChainID: + cmd.Flags().Uint64Var(&config.testnetConfig.ChainID, "testnet-chain-id", 0, "Chain ID of the custom test network.") + case testnetGenesisTimestamp: + cmd.Flags().Int64Var(&config.testnetConfig.GenesisTimestamp, "testnet-genesis-timestamp", 0, "Genesis timestamp of the custom test network.") + case testnetCapellaHardFork: + cmd.Flags().StringVar(&config.testnetConfig.CapellaHardFork, "testnet-capella-hard-fork", "", "Capella hard fork version of the custom test network.") } if f.required { diff --git a/cmd/exit_broadcast.go b/cmd/exit_broadcast.go index 6f28ac01a..b32079c00 100644 --- a/cmd/exit_broadcast.go +++ b/cmd/exit_broadcast.go @@ -25,6 +25,7 @@ import ( "github.com/obolnetwork/charon/app/z" manifestpb "github.com/obolnetwork/charon/cluster/manifestpb/v1" "github.com/obolnetwork/charon/core" + "github.com/obolnetwork/charon/eth2util" "github.com/obolnetwork/charon/eth2util/keystore" "github.com/obolnetwork/charon/tbls" "github.com/obolnetwork/charon/tbls/tblsconv" @@ -62,6 +63,12 @@ func newBcastFullExitCmd(runFunc func(context.Context, exitConfig) error) *cobra {exitFromDir, false}, {beaconNodeTimeout, false}, {publishTimeout, false}, + {all, false}, + {testnetName, false}, + {testnetForkVersion, false}, + {testnetChainID, false}, + {testnetGenesisTimestamp, false}, + {testnetCapellaHardFork, false}, }) bindLogFlags(cmd.Flags(), &config.Log) @@ -98,6 +105,12 @@ func newBcastFullExitCmd(runFunc func(context.Context, exitConfig) error) *cobra } func runBcastFullExit(ctx context.Context, config exitConfig) error { + // Check if custom testnet configuration is provided. + if config.testnetConfig.IsNonZero() { + // Add testnet config to supported networks. + eth2util.AddTestNetwork(config.testnetConfig) + } + identityKey, err := k1util.Load(config.PrivateKeyPath) if err != nil { return errors.Wrap(err, "could not load identity key") diff --git a/cmd/exit_fetch.go b/cmd/exit_fetch.go index 0a3e25119..7dd7296ec 100644 --- a/cmd/exit_fetch.go +++ b/cmd/exit_fetch.go @@ -18,6 +18,7 @@ import ( "github.com/obolnetwork/charon/app/obolapi" "github.com/obolnetwork/charon/app/z" "github.com/obolnetwork/charon/core" + "github.com/obolnetwork/charon/eth2util" "github.com/obolnetwork/charon/eth2util/keystore" ) @@ -49,6 +50,11 @@ func newFetchExitCmd(runFunc func(context.Context, exitConfig) error) *cobra.Com {all, false}, {fetchedExitPath, false}, {publishTimeout, false}, + {testnetName, false}, + {testnetForkVersion, false}, + {testnetChainID, false}, + {testnetGenesisTimestamp, false}, + {testnetCapellaHardFork, false}, }) bindLogFlags(cmd.Flags(), &config.Log) @@ -73,6 +79,12 @@ func newFetchExitCmd(runFunc func(context.Context, exitConfig) error) *cobra.Com } func runFetchExit(ctx context.Context, config exitConfig) error { + // Check if custom testnet configuration is provided. + if config.testnetConfig.IsNonZero() { + // Add testnet config to supported networks. + eth2util.AddTestNetwork(config.testnetConfig) + } + if _, err := os.Stat(config.FetchedExitPath); err != nil { return errors.Wrap(err, "store exit path") } diff --git a/cmd/exit_list.go b/cmd/exit_list.go index 79c753df4..ef263f7ec 100644 --- a/cmd/exit_list.go +++ b/cmd/exit_list.go @@ -15,6 +15,7 @@ import ( "github.com/obolnetwork/charon/app/errors" "github.com/obolnetwork/charon/app/log" "github.com/obolnetwork/charon/app/z" + "github.com/obolnetwork/charon/eth2util" ) func newListActiveValidatorsCmd(runFunc func(context.Context, exitConfig) error) *cobra.Command { @@ -43,6 +44,11 @@ func newListActiveValidatorsCmd(runFunc func(context.Context, exitConfig) error) {lockFilePath, false}, {beaconNodeEndpoints, true}, {beaconNodeTimeout, false}, + {testnetName, false}, + {testnetForkVersion, false}, + {testnetChainID, false}, + {testnetGenesisTimestamp, false}, + {testnetCapellaHardFork, false}, }) bindLogFlags(cmd.Flags(), &config.Log) @@ -51,6 +57,12 @@ func newListActiveValidatorsCmd(runFunc func(context.Context, exitConfig) error) } func runListActiveValidatorsCmd(ctx context.Context, config exitConfig) error { + // Check if custom testnet configuration is provided. + if config.testnetConfig.IsNonZero() { + // Add testnet config to supported networks. + eth2util.AddTestNetwork(config.testnetConfig) + } + valList, err := listActiveVals(ctx, config) if err != nil { return err diff --git a/cmd/exit_sign.go b/cmd/exit_sign.go index 3b5f3b7e8..9aac498f5 100644 --- a/cmd/exit_sign.go +++ b/cmd/exit_sign.go @@ -19,6 +19,7 @@ import ( "github.com/obolnetwork/charon/app/obolapi" "github.com/obolnetwork/charon/app/z" "github.com/obolnetwork/charon/core" + "github.com/obolnetwork/charon/eth2util" "github.com/obolnetwork/charon/eth2util/keystore" ) @@ -54,6 +55,11 @@ func newSubmitPartialExitCmd(runFunc func(context.Context, exitConfig) error) *c {beaconNodeTimeout, false}, {publishTimeout, false}, {all, false}, + {testnetName, false}, + {testnetForkVersion, false}, + {testnetChainID, false}, + {testnetGenesisTimestamp, false}, + {testnetCapellaHardFork, false}, }) bindLogFlags(cmd.Flags(), &config.Log) @@ -82,6 +88,12 @@ func newSubmitPartialExitCmd(runFunc func(context.Context, exitConfig) error) *c } func runSignPartialExit(ctx context.Context, config exitConfig) error { + // Check if custom testnet configuration is provided. + if config.testnetConfig.IsNonZero() { + // Add testnet config to supported networks. + eth2util.AddTestNetwork(config.testnetConfig) + } + identityKey, err := k1util.Load(config.PrivateKeyPath) if err != nil { return errors.Wrap(err, "could not load identity key") From 2ebe6f74e4f9d60a2c38c61a39023ff871d6797e Mon Sep 17 00:00:00 2001 From: Kaloyan Tanev <24719519+KaloyanTanev@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:26:43 +0200 Subject: [PATCH 2/2] remove fixed test code, fixed already in main --- cmd/createcluster_internal_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmd/createcluster_internal_test.go b/cmd/createcluster_internal_test.go index 70525e6ac..46a09fc8d 100644 --- a/cmd/createcluster_internal_test.go +++ b/cmd/createcluster_internal_test.go @@ -839,8 +839,6 @@ func TestClusterCLI(t *testing.T) { clusterDir := "--cluster-dir=" + t.TempDir() cmd := newCreateCmd(newCreateClusterCmd(runCreateCluster)) - charonDir := testutil.CreateTempCharonDir(t) - clusterDirArg := "--cluster-dir=" + charonDir if test.threshold != "" { cmd.SetArgs([]string{"cluster", clusterDir, test.nodes, test.feeRecipient, test.withdrawal, test.network, test.numValidators, test.threshold}) } else {