1- package main
1+ package commands
22
33import (
44 "errors"
55 "fmt"
66 "os"
7+ "strings"
78
8- "golang.org/x/exp/slices "
9+ "github.com/KYVENetwork/supervysor/cmd/supervysor/commands/helpers "
910
10- "github.com/KYVENetwork/supervysor/cmd/supervysor/helpers"
11- "github.com/KYVENetwork/supervysor/types"
11+ "github.com/KYVENetwork/supervysor/utils"
12+
13+ "golang.org/x/exp/slices"
1214
1315 "github.com/KYVENetwork/supervysor/settings"
16+ "github.com/KYVENetwork/supervysor/types"
1417
1518 "github.com/pelletier/go-toml/v2"
1619
1720 "github.com/spf13/cobra"
1821)
1922
20- var (
21- abciEndpoint string
22- binary string
23- chainId string
24- fallbackEndpoints string
25- home string
26- metrics bool
27- metricsPort int
28- poolId int
29- seeds string
30- pruningInterval int
31-
32- cfg types.SupervysorConfig
33- )
34-
3523func init () {
36- initCmd .Flags ().StringVar (& binary , "binary" , "" , "path to chain binaries or cosmovisor (e.g. /root/go/bin/cosmovisor)" )
24+ initCmd .Flags ().StringVarP (& binary , "binary" , "b " , "" , "path to chain binaries or cosmovisor (e.g. /root/go/bin/cosmovisor)" )
3725 if err := initCmd .MarkFlagRequired ("binary" ); err != nil {
3826 panic (fmt .Errorf ("flag 'binary-path' should be required: %w" , err ))
3927 }
4028
4129 initCmd .Flags ().StringVar (& home , "home" , "" , "path to home directory (e.g. /root/.osmosisd)" )
42- if err := initCmd .MarkFlagRequired ("home" ); err != nil {
43- panic (fmt .Errorf ("flag 'home-path' should be required: %w" , err ))
44- }
30+
31+ initCmd .Flags ().StringVar (& config , "config" , "" , "path to config directory (default: ~/.supervysor/)" )
4532
4633 initCmd .Flags ().IntVar (& poolId , "pool-id" , 0 , "KYVE pool-id" )
4734 if err := initCmd .MarkFlagRequired ("pool-id" ); err != nil {
@@ -55,11 +42,15 @@ func init() {
5542
5643 initCmd .Flags ().StringVar (& chainId , "chain-id" , "kyve-1" , "KYVE chain-id" )
5744
45+ initCmd .Flags ().BoolVar (& optOut , "opt-out" , false , "disable the collection of anonymous usage data" )
46+
5847 initCmd .Flags ().StringVar (& fallbackEndpoints , "fallback-endpoints" , "" , "additional endpoints to query KYVE pool height" )
5948
6049 initCmd .Flags ().IntVar (& pruningInterval , "pruning-interval" , 24 , "block-pruning interval (hours)" )
6150
62- initCmd .Flags ().BoolVar (& metrics , "metrics" , true , "exposing Prometheus metrics (true or false)" )
51+ initCmd .Flags ().BoolVar (& statePruning , "state-pruning" , true , "state pruning enabled" )
52+
53+ initCmd .Flags ().BoolVar (& metrics , "metrics" , false , "exposing Prometheus metrics (true or false)" )
6354
6455 initCmd .Flags ().IntVar (& metricsPort , "metrics-port" , 26660 , "port for metrics server" )
6556
@@ -76,25 +67,31 @@ var initCmd = &cobra.Command{
7667 return fmt .Errorf ("not supported chain-id" )
7768 }
7869
70+ // if no home path was given get the default one
7971 if home == "" {
80- logger .Error ("home directory can not be empty" )
81- return fmt .Errorf ("empty home directory path" )
72+ home = helpers .GetHomePathFromBinary (binary )
8273 }
8374
8475 if pruningInterval <= 6 {
8576 logger .Error ("pruning-interval should be higher than 6 hours" )
8677 }
8778
79+ utils .TrackInitEvent (chainId , optOut )
80+
8881 if err := settings .InitializeSettings (binary , home , poolId , false , seeds , chainId , fallbackEndpoints ); err != nil {
8982 logger .Error ("could not initialize settings" , "err" , err )
9083 return err
9184 }
9285 logger .Info ("successfully initialized settings" )
9386
94- configPath , err := helpers .GetSupervysorDir ()
95- if err != nil {
96- logger .Error ("could not get supervysor directory path" , "err" , err )
97- return err
87+ if config == "" {
88+ configPath , err = helpers .GetSupervysorDir ()
89+ if err != nil {
90+ logger .Error ("could not get supervysor directory path" , "err" , err )
91+ return err
92+ }
93+ } else {
94+ configPath = config
9895 }
9996
10097 if _ , err = os .Stat (configPath + "/config.toml" ); err == nil {
@@ -109,7 +106,7 @@ var initCmd = &cobra.Command{
109106 }
110107 logger .Info ("initializing supverysor..." )
111108
112- config := types.SupervysorConfig {
109+ supervysorConfig := types.SupervysorConfig {
113110 ABCIEndpoint : abciEndpoint ,
114111 BinaryPath : binary ,
115112 ChainId : chainId ,
@@ -123,9 +120,10 @@ var initCmd = &cobra.Command{
123120 PoolId : poolId ,
124121 PruningInterval : pruningInterval ,
125122 Seeds : seeds ,
123+ StatePruning : statePruning ,
126124 StateRequests : false ,
127125 }
128- b , err := toml .Marshal (config )
126+ b , err := toml .Marshal (supervysorConfig )
129127 if err != nil {
130128 logger .Error ("could not unmarshal config" , "err" , err )
131129 return err
@@ -137,7 +135,7 @@ var initCmd = &cobra.Command{
137135 return err
138136 }
139137
140- _ , err = getSupervysorConfig ()
138+ _ , err = getSupervysorConfig (configPath )
141139 if err != nil {
142140 logger .Error ("could not load config file" , "err" , err )
143141 return err
@@ -153,13 +151,12 @@ var initCmd = &cobra.Command{
153151}
154152
155153// getSupervysorConfig returns the supervysor config.toml file.
156- func getSupervysorConfig () (* types.SupervysorConfig , error ) {
157- configPath , err := helpers .GetSupervysorDir ()
158- if err != nil {
159- return nil , fmt .Errorf ("could not get supervysor directory path: %s" , err )
154+ func getSupervysorConfig (configPath string ) (* types.SupervysorConfig , error ) {
155+ if ! strings .HasSuffix (configPath , "/config.toml" ) {
156+ configPath += "/config.toml"
160157 }
161158
162- data , err := os .ReadFile (configPath + "/config.toml" )
159+ data , err := os .ReadFile (configPath )
163160 if err != nil {
164161 return nil , fmt .Errorf ("could not find config. Please initialize again: %s" , err )
165162 }
0 commit comments