diff --git a/command/genesis/genesis.go b/command/genesis/genesis.go index dd55ffe285..8aab21fd89 100644 --- a/command/genesis/genesis.go +++ b/command/genesis/genesis.go @@ -318,7 +318,7 @@ func runCommand(cmd *cobra.Command, _ []string) { var err error if params.isPolyBFTConsensus() { - err = params.generatePolyBftChainConfig(outputter) + err = params.generateChainConfig(outputter) } else { err = params.generateGenesis() } diff --git a/command/genesis/polybft_params.go b/command/genesis/polybft_params.go index 69fd109e34..56fe508583 100644 --- a/command/genesis/polybft_params.go +++ b/command/genesis/polybft_params.go @@ -24,9 +24,6 @@ import ( "github.com/0xPolygon/polygon-edge/types" ) -//nolint:godox -// TODO: @Stefan-Ethernal move this to params.go - const ( sprintSizeFlag = "sprint-size" blockTimeFlag = "block-time" @@ -34,9 +31,7 @@ const ( blockTimeDriftFlag = "block-time-drift" - defaultEpochSize = uint64(10) defaultSprintSize = uint64(5) - defaultValidatorSetSize = 100 defaultBlockTime = 2 * time.Second defaultEpochReward = 1 defaultBlockTimeDrift = uint64(10) @@ -72,11 +67,8 @@ type contractInfo struct { address types.Address } -// TODO: @Stefan-Ethernal Rename to generateChainConfig -// generatePolyBftChainConfig creates and persists polybft chain configuration to the provided file path -// -//nolint:godox -func (p *genesisParams) generatePolyBftChainConfig(o command.OutputFormatter) error { +// generateChainConfig creates and persists polybft chain configuration to the provided file path +func (p *genesisParams) generateChainConfig(o command.OutputFormatter) error { // populate premine balance map premineBalances := make(map[types.Address]*helper.PremineInfo, len(p.premine)) diff --git a/command/secrets/init/params.go b/command/secrets/init/params.go index 5eb4d24de2..21e3c7649e 100644 --- a/command/secrets/init/params.go +++ b/command/secrets/init/params.go @@ -160,36 +160,51 @@ func (ip *initParams) initKeys(secretsManager secrets.SecretsManager) ([]string, var generated []string if ip.generatesNetwork { - if !secretsManager.HasSecret(secrets.NetworkKey) { - if _, err := helper.InitNetworkingPrivateKey(secretsManager); err != nil { - return generated, fmt.Errorf("error initializing network-key: %w", err) - } - - generated = append(generated, secrets.NetworkKey) + if err := ip.generateNetworkKey(secretsManager, &generated); err != nil { + return generated, err } } if ip.generatesAccount { - var ( - a *wallet.Account - err error - ) + if err := ip.generateAccount(secretsManager, &generated); err != nil { + return generated, err + } + } - if !secretsManager.HasSecret(secrets.ValidatorKey) && !secretsManager.HasSecret(secrets.ValidatorBLSKey) { - a, err = wallet.GenerateAccount() - if err != nil { - return generated, fmt.Errorf("error generating account: %w", err) - } + return generated, nil +} - if err = a.Save(secretsManager); err != nil { - return generated, fmt.Errorf("error saving account: %w", err) - } +func (ip *initParams) generateNetworkKey(secretsManager secrets.SecretsManager, generated *[]string) error { + if secretsManager.HasSecret(secrets.NetworkKey) { + return nil + } - generated = append(generated, secrets.ValidatorKey, secrets.ValidatorBLSKey) - } + if _, err := helper.InitNetworkingPrivateKey(secretsManager); err != nil { + return fmt.Errorf("error initializing network-key: %w", err) } - return generated, nil + *generated = append(*generated, secrets.NetworkKey) + + return nil +} + +func (ip *initParams) generateAccount(secretsManager secrets.SecretsManager, generated *[]string) error { + if secretsManager.HasSecret(secrets.ValidatorKey) && secretsManager.HasSecret(secrets.ValidatorBLSKey) { + return nil + } + + a, err := wallet.GenerateAccount() + if err != nil { + return fmt.Errorf("error generating account: %w", err) + } + + if err = a.Save(secretsManager); err != nil { + return fmt.Errorf("error saving account: %w", err) + } + + *generated = append(*generated, secrets.ValidatorKey, secrets.ValidatorBLSKey) + + return nil } // getResult gets keys from secret manager and return result to display