diff --git a/cmd/algocfg/profileCommand.go b/cmd/algocfg/profileCommand.go index ef64dda0be..2cf467d060 100644 --- a/cmd/algocfg/profileCommand.go +++ b/cmd/algocfg/profileCommand.go @@ -19,39 +19,70 @@ package main import ( "bufio" "fmt" - "github.com/spf13/cobra" "os" "path/filepath" "strings" + "github.com/spf13/cobra" + "github.com/algorand/go-algorand/cmd/util/datadir" "github.com/algorand/go-algorand/config" "github.com/algorand/go-algorand/util/codecs" ) -// profileConfigUpdater updates the provided config for non-defaults in a given profile -type profileConfigUpdater func(cfg config.Local) config.Local - -// defaultConfigUpdater leaves all default values in place -func defaultConfigUpdater(cfg config.Local) config.Local { - return cfg -} - -// relayConfigUpdater alters config values to set up a relay node -func relayConfigUpdater(cfg config.Local) config.Local { - cfg.Archival = true - cfg.EnableLedgerService = true - cfg.EnableBlockService = true - cfg.NetAddress = "4160" - return cfg +// configUpdater updates the provided config for non-defaults in a given profile +type configUpdater struct { + updateFunc func(cfg config.Local) config.Local + description string } var ( + development = configUpdater{ + description: "Build on Algorand.", + updateFunc: func(cfg config.Local) config.Local { + cfg.EnableExperimentalAPI = true + cfg.EnableDeveloperAPI = true + return cfg + }, + } + + conduit = configUpdater{ + description: "Provide data for the Conduit tool.", + updateFunc: func(cfg config.Local) config.Local { + cfg.EnableFollowMode = true + cfg.MaxAcctLookback = 64 + cfg.CatchupParallelBlocks = 64 + return cfg + }, + } + + participation = configUpdater{ + description: "Participate in consensus or simply ensure chain health by validating blocks.", + updateFunc: func(cfg config.Local) config.Local { + cfg.CatchupBlockValidateMode = 0b1100 + return cfg + }, + } + + relay = configUpdater{ + description: "Relay consensus messages across the network and support catchup.", + updateFunc: func(cfg config.Local) config.Local { + cfg.Archival = true + cfg.EnableLedgerService = true + cfg.EnableBlockService = true + cfg.NetAddress = "4160" + return cfg + }, + } + // profileNames are the supported pre-configurations of config values - profileNames = map[string]profileConfigUpdater{ - "relay": relayConfigUpdater, - "default": defaultConfigUpdater, + profileNames = map[string]configUpdater{ + "participation": participation, + "conduit": conduit, + "relay": relay, + "development": development, } + forceUpdate bool ) @@ -64,8 +95,19 @@ func init() { var profileCmd = &cobra.Command{ Use: "profile", - Short: "Manipulate config profiles", - Args: cobra.NoArgs, + Short: "Generate config.json file from a profile.", + Long: `Initialize algod config.json files based on a usage profile. + +The config file generated by these profiles can be used as a starting point +for a nodes configuration. The defaults for a given profile should be treated +as supplemental to the documentation, you should review the documentation to +understand what the settings are doing. + +For more details about configuration settings refer to the developer portal: +https://developer.algorand.org/docs/run-a-node/reference/config/ + +Profiles are subject to change or removal.`, + Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { cmd.HelpFunc()(cmd, args) }, @@ -73,20 +115,25 @@ var profileCmd = &cobra.Command{ var listProfileCmd = &cobra.Command{ Use: "list", - Short: "List config profiles", + Short: "A list of valid config profiles and a short description.", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { - var profiles string + longest := 0 for key := range profileNames { - profiles += fmt.Sprintf("%s ", key) + if len(key) > longest { + longest = len(key) + } + } + + for key, value := range profileNames { + reportInfof("%-*s %s", longest, key, value.description) } - reportInfof(profiles) }, } var setProfileCmd = &cobra.Command{ Use: "set", - Short: "Set preconfigured config defaults", + Short: "Set config.json file from a profile.", Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { datadir.OnDataDirs(func(dataDir string) { @@ -120,7 +167,7 @@ var setProfileCmd = &cobra.Command{ func getConfigForArg(configType string) (config.Local, error) { cfg := config.GetDefaultLocal() if updater, ok := profileNames[configType]; ok { - return updater(cfg), nil + return updater.updateFunc(cfg), nil } return config.Local{}, fmt.Errorf("invalid profile type %v", configType) }