diff --git a/client/cmd/flags.go b/client/cmd/flags.go index 45e478c1..647a79b0 100644 --- a/client/cmd/flags.go +++ b/client/cmd/flags.go @@ -36,4 +36,9 @@ func bindInitFlags(flags *pflag.FlagSet, cfg *InitConfig) { flags.BoolVar(&cfg.TrustedSync, "trusted-sync", cfg.TrustedSync, "Initialize trusted state-sync height and hash by querying the Story RPC") flags.BoolVar(&cfg.Force, "force", cfg.Force, "Force initialization (overwrite existing files)") flags.BoolVar(&cfg.Clean, "clean", cfg.Clean, "Delete home directory before initialization") + flags.StringVar(&cfg.RPCLaddr, "rpc-laddr", "", "Override the RPC listening address") + flags.StringVar(&cfg.ExternalAddress, "external-address", "", "Override the P2P external address") + flags.StringVar(&cfg.Seeds, "seeds", "", "Override the P2P seeds (comma-separated)") + flags.BoolVar(&cfg.SeedMode, "seed-mode", false, "Enable seed mode") + flags.StringVar(&cfg.Moniker, "moniker", cfg.Moniker, "Custom moniker name for this node") } diff --git a/client/cmd/init.go b/client/cmd/init.go index cfac44aa..4518ce9f 100644 --- a/client/cmd/init.go +++ b/client/cmd/init.go @@ -26,13 +26,18 @@ import ( // InitConfig is the config for the init command. type InitConfig struct { - HomeDir string - Network netconf.ID - TrustedSync bool - Force bool - Clean bool - Cosmos bool - ExecutionHash common.Hash + HomeDir string + Network netconf.ID + TrustedSync bool + Force bool + Clean bool + Cosmos bool + ExecutionHash common.Hash + RPCLaddr string + ExternalAddress string + Seeds string + SeedMode bool + Moniker string } // newInitCmd returns a new cobra command that initializes the files and folders required by story. @@ -107,9 +112,9 @@ func InitFiles(ctx context.Context, initCfg InitConfig) error { cfg = storycfg.LocalConfig default: cfg = storycfg.DefaultConfig() - cfg.HomeDir = homeDir cfg.Network = network } + cfg.HomeDir = homeDir // Folders folders := []struct { @@ -133,9 +138,36 @@ func InitFiles(ctx context.Context, initCfg InitConfig) error { log.Info(ctx, "Generated folder", "reason", folder.Name, "path", folder.Path) } - // Add P2P seeds to comet config - if seeds := network.Static().ConsensusSeeds(); len(seeds) > 0 { + if initCfg.Moniker != "" { + comet.Moniker = initCfg.Moniker + log.Info(ctx, "Overriding node moniker", "moniker", comet.Moniker) + } + + if initCfg.RPCLaddr != "" { + comet.RPC.ListenAddress = initCfg.RPCLaddr + log.Info(ctx, "Overriding RPC listen address", "address", comet.RPC.ListenAddress) + } + + if initCfg.ExternalAddress != "" { + comet.P2P.ExternalAddress = initCfg.ExternalAddress + log.Info(ctx, "Overriding P2P external address", "address", comet.P2P.ExternalAddress) + } + + // Handle P2P seeds with prioritization + if initCfg.Seeds != "" { + // If seeds are provided via the flag, use them + seeds := SplitAndTrim(initCfg.Seeds) comet.P2P.Seeds = strings.Join(seeds, ",") + log.Info(ctx, "Overriding P2P seeds with provided flag", "seeds", comet.P2P.Seeds) + } else if networkSeeds := network.Static().ConsensusSeeds(); len(networkSeeds) > 0 { + // Otherwise, use the network's default seeds + comet.P2P.Seeds = strings.Join(networkSeeds, ",") + log.Info(ctx, "Using network's default P2P seeds", "seeds", comet.P2P.Seeds) + } + + if initCfg.SeedMode { + comet.P2P.SeedMode = true + log.Info(ctx, "Seed mode enabled") } // Setup comet config @@ -253,3 +285,14 @@ func prepareHomeDirectory(ctx context.Context, initCfg InitConfig, homeDir strin return nil } + +func SplitAndTrim(input string) []string { + l := strings.Split(input, ",") + var ret []string + for _, r := range l { + if r = strings.TrimSpace(r); r != "" { + ret = append(ret, r) + } + } + return ret +} diff --git a/client/config/config.go b/client/config/config.go index 0f7863f9..c9bba36b 100644 --- a/client/config/config.go +++ b/client/config/config.go @@ -58,6 +58,10 @@ var ( APIAddress: "127.0.0.1:1317", EnableUnsafeCORS: false, Tracer: tracer.DefaultConfig(), + RPCLaddr: "tcp://127.0.0.1:26657", + ExternalAddress: "", + Seeds: "", + SeedMode: false, } LocalConfig = Config{ HomeDir: DefaultHomeDir(), @@ -75,6 +79,10 @@ var ( APIAddress: "127.0.0.1:1317", EnableUnsafeCORS: false, Tracer: tracer.DefaultConfig(), + RPCLaddr: "tcp://127.0.0.1:26657", + ExternalAddress: "", + Seeds: "", + SeedMode: false, } ) @@ -96,6 +104,10 @@ func DefaultConfig() Config { APIAddress: "127.0.0.1:1317", EnableUnsafeCORS: false, Tracer: tracer.DefaultConfig(), + RPCLaddr: "tcp://127.0.0.1:26657", + ExternalAddress: "", + Seeds: "", + SeedMode: false, } } @@ -144,6 +156,10 @@ type Config struct { APIAddress string EnableUnsafeCORS bool Tracer tracer.Config + RPCLaddr string + ExternalAddress string + Seeds string + SeedMode bool } // ConfigFile returns the default path to the toml story config file.