Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 74 additions & 27 deletions cmd/algocfg/profileCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -64,29 +95,45 @@ 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)
},
}

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) {
Expand Down Expand Up @@ -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)
}