From 11ec5fbfcbe881c58b749f346145367f771c7589 Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Tue, 4 Mar 2025 14:30:53 +0100 Subject: [PATCH 01/24] Move config default log level from comet to rollkit --- cmd/rollkit/commands/root.go | 5 +++-- config/defaults.go | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/rollkit/commands/root.go b/cmd/rollkit/commands/root.go index b6f093202c..fbf3863809 100644 --- a/cmd/rollkit/commands/root.go +++ b/cmd/rollkit/commands/root.go @@ -1,8 +1,9 @@ package commands import ( - cometconfig "github.com/cometbft/cometbft/config" "github.com/spf13/cobra" + + rollkitconfig "github.com/rollkit/rollkit/config" ) func init() { @@ -11,7 +12,7 @@ func init() { // registerFlagsRootCmd registers the flags for the root command func registerFlagsRootCmd(cmd *cobra.Command) { - cmd.PersistentFlags().String("log_level", cometconfig.DefaultLogLevel, "set the log level; default is info. other options include debug, info, error, none") + cmd.PersistentFlags().String("log_level", rollkitconfig.DefaultLogLevel, "set the log level; default is info. other options include debug, info, error, none") } // RootCmd is the root command for Rollkit diff --git a/config/defaults.go b/config/defaults.go index 51f3dd7e7a..87495264cf 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -18,6 +18,8 @@ const ( DefaultSequencerRollupID = "mock-rollup" // DefaultExecutorAddress is the default address for the executor middleware DefaultExecutorAddress = "localhost:40041" + // DefaultLogLevel is the default log level for the application + DefaultLogLevel = "info" ) // DefaultNodeConfig keeps default values of NodeConfig From 7ab7387f87f61d924e258e4b5f963082e0ff4656 Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Tue, 4 Mar 2025 14:42:31 +0100 Subject: [PATCH 02/24] Use instrumentation config from rollkit --- config/config.go | 16 +++-- config/config_test.go | 30 +++++++++- config/defaults.go | 1 + config/instrumentation.go | 54 +++++++++++++++++ config/instrumentation_test.go | 103 +++++++++++++++++++++++++++++++++ 5 files changed, 198 insertions(+), 6 deletions(-) create mode 100644 config/instrumentation.go create mode 100644 config/instrumentation_test.go diff --git a/config/config.go b/config/config.go index 17f016417e..f42b117351 100644 --- a/config/config.go +++ b/config/config.go @@ -62,10 +62,10 @@ type NodeConfig struct { DAAuthToken string `mapstructure:"da_auth_token"` Light bool `mapstructure:"light"` HeaderConfig `mapstructure:",squash"` - Instrumentation *cmcfg.InstrumentationConfig `mapstructure:"instrumentation"` - DAGasPrice float64 `mapstructure:"da_gas_price"` - DAGasMultiplier float64 `mapstructure:"da_gas_multiplier"` - DASubmitOptions string `mapstructure:"da_submit_options"` + Instrumentation *InstrumentationConfig `mapstructure:"instrumentation"` + DAGasPrice float64 `mapstructure:"da_gas_price"` + DAGasMultiplier float64 `mapstructure:"da_gas_multiplier"` + DASubmitOptions string `mapstructure:"da_submit_options"` // CLI flags DANamespace string `mapstructure:"da_namespace"` @@ -113,7 +113,13 @@ func GetNodeConfig(nodeConf *NodeConfig, cmConf *cmcfg.Config) { nodeConf.P2P.Seeds = cmConf.P2P.Seeds } if cmConf.Instrumentation != nil { - nodeConf.Instrumentation = cmConf.Instrumentation + // Convert CometBFT InstrumentationConfig to Rollkit InstrumentationConfig + nodeConf.Instrumentation = &InstrumentationConfig{ + Prometheus: cmConf.Instrumentation.Prometheus, + PrometheusListenAddr: cmConf.Instrumentation.PrometheusListenAddr, + MaxOpenConnections: cmConf.Instrumentation.MaxOpenConnections, + Namespace: "rollkit", // Use Rollkit namespace instead of CometBFT's + } } } } diff --git a/config/config_test.go b/config/config_test.go index d528114625..b8a6f334a4 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -23,13 +23,41 @@ func TestGetNodeConfig(t *testing.T) { {"ListenAddress", &cmcfg.Config{P2P: &cmcfg.P2PConfig{ListenAddress: "127.0.0.1:7676"}}, NodeConfig{P2P: P2PConfig{ListenAddress: "127.0.0.1:7676"}}}, {"RootDir", &cmcfg.Config{BaseConfig: cmcfg.BaseConfig{RootDir: "~/root"}}, NodeConfig{RootDir: "~/root"}}, {"DBPath", &cmcfg.Config{BaseConfig: cmcfg.BaseConfig{DBPath: "./database"}}, NodeConfig{DBPath: "./database"}}, + { + "Instrumentation", + &cmcfg.Config{ + Instrumentation: &cmcfg.InstrumentationConfig{ + Prometheus: true, + PrometheusListenAddr: ":8888", + MaxOpenConnections: 5, + Namespace: "cometbft", + }, + }, + NodeConfig{ + Instrumentation: &InstrumentationConfig{ + Prometheus: true, + PrometheusListenAddr: ":8888", + MaxOpenConnections: 5, + Namespace: "rollkit", // Should be converted to rollkit namespace + }, + }, + }, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { var actual NodeConfig GetNodeConfig(&actual, c.input) - assert.Equal(t, c.expected, actual) + + if c.name == "Instrumentation" { + // Special handling for Instrumentation test case + assert.Equal(t, c.expected.Instrumentation.Prometheus, actual.Instrumentation.Prometheus) + assert.Equal(t, c.expected.Instrumentation.PrometheusListenAddr, actual.Instrumentation.PrometheusListenAddr) + assert.Equal(t, c.expected.Instrumentation.MaxOpenConnections, actual.Instrumentation.MaxOpenConnections) + assert.Equal(t, c.expected.Instrumentation.Namespace, actual.Instrumentation.Namespace) + } else { + assert.Equal(t, c.expected, actual) + } }) } } diff --git a/config/defaults.go b/config/defaults.go index 87495264cf..9afc02bb77 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -42,6 +42,7 @@ var DefaultNodeConfig = NodeConfig{ HeaderConfig: HeaderConfig{ TrustedHash: "", }, + Instrumentation: DefaultInstrumentationConfig(), SequencerAddress: DefaultSequencerAddress, SequencerRollupID: DefaultSequencerRollupID, ExecutorAddress: DefaultExecutorAddress, diff --git a/config/instrumentation.go b/config/instrumentation.go new file mode 100644 index 0000000000..0903a73293 --- /dev/null +++ b/config/instrumentation.go @@ -0,0 +1,54 @@ +package config + +import "errors" + +// InstrumentationConfig defines the configuration for metrics reporting. +type InstrumentationConfig struct { + // When true, Prometheus metrics are served under /metrics on + // PrometheusListenAddr. + // Check out the documentation for the list of available metrics. + Prometheus bool `mapstructure:"prometheus"` + + // Address to listen for Prometheus collector(s) connections. + PrometheusListenAddr string `mapstructure:"prometheus_listen_addr"` + + // Maximum number of simultaneous connections. + // If you want to accept a larger number than the default, make sure + // you increase your OS limits. + // 0 - unlimited. + MaxOpenConnections int `mapstructure:"max_open_connections"` + + // Instrumentation namespace. + Namespace string `mapstructure:"namespace"` +} + +// DefaultInstrumentationConfig returns a default configuration for metrics +// reporting. +func DefaultInstrumentationConfig() *InstrumentationConfig { + return &InstrumentationConfig{ + Prometheus: false, + PrometheusListenAddr: ":26660", + MaxOpenConnections: 3, + Namespace: "rollkit", + } +} + +// TestInstrumentationConfig returns a default configuration for metrics +// reporting in test environments. +func TestInstrumentationConfig() *InstrumentationConfig { + return DefaultInstrumentationConfig() +} + +// ValidateBasic performs basic validation (checking param bounds, etc.) and +// returns an error if any check fails. +func (cfg *InstrumentationConfig) ValidateBasic() error { + if cfg.MaxOpenConnections < 0 { + return errors.New("max_open_connections can't be negative") + } + return nil +} + +// IsPrometheusEnabled returns true if Prometheus metrics are enabled. +func (cfg *InstrumentationConfig) IsPrometheusEnabled() bool { + return cfg.Prometheus && cfg.PrometheusListenAddr != "" +} diff --git a/config/instrumentation_test.go b/config/instrumentation_test.go new file mode 100644 index 0000000000..f2a7cda61a --- /dev/null +++ b/config/instrumentation_test.go @@ -0,0 +1,103 @@ +package config + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestDefaultInstrumentationConfig(t *testing.T) { + t.Parallel() + + cfg := DefaultInstrumentationConfig() + + assert.False(t, cfg.Prometheus) + assert.Equal(t, ":26660", cfg.PrometheusListenAddr) + assert.Equal(t, 3, cfg.MaxOpenConnections) + assert.Equal(t, "rollkit", cfg.Namespace) +} + +func TestInstrumentationConfigValidateBasic(t *testing.T) { + t.Parallel() + + testCases := []struct { + name string + cfg *InstrumentationConfig + expectErr bool + }{ + { + "valid config", + &InstrumentationConfig{ + MaxOpenConnections: 3, + }, + false, + }, + { + "negative max open connections", + &InstrumentationConfig{ + MaxOpenConnections: -1, + }, + true, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + err := tc.cfg.ValidateBasic() + if tc.expectErr { + assert.Error(t, err) + } else { + assert.NoError(t, err) + } + }) + } +} + +func TestIsPrometheusEnabled(t *testing.T) { + t.Parallel() + + testCases := []struct { + name string + cfg *InstrumentationConfig + expected bool + }{ + { + "prometheus enabled with address", + &InstrumentationConfig{ + Prometheus: true, + PrometheusListenAddr: ":26660", + }, + true, + }, + { + "prometheus enabled without address", + &InstrumentationConfig{ + Prometheus: true, + PrometheusListenAddr: "", + }, + false, + }, + { + "prometheus disabled with address", + &InstrumentationConfig{ + Prometheus: false, + PrometheusListenAddr: ":26660", + }, + false, + }, + { + "prometheus disabled without address", + &InstrumentationConfig{ + Prometheus: false, + PrometheusListenAddr: "", + }, + false, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + assert.Equal(t, tc.expected, tc.cfg.IsPrometheusEnabled()) + }) + } +} From 7cab9e52346f65e14b602c21df31cca0ac05ecd1 Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Tue, 4 Mar 2025 15:13:43 +0100 Subject: [PATCH 03/24] refactor: Migrate instrumentation config from CometBFT to Rollkit Updates imports and instrumentation configuration references to use the Rollkit configuration package instead of CometBFT in various test files and node configurations. --- cmd/rollkit/commands/run_node.go | 2 +- node/full_node_integration_test.go | 10 +++++----- node/helpers_test.go | 4 ++-- node/node_integration_test.go | 4 ++-- node/node_test.go | 4 ++-- node/setup.go | 5 ++--- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/cmd/rollkit/commands/run_node.go b/cmd/rollkit/commands/run_node.go index 33ed5dc1db..d1ae151668 100644 --- a/cmd/rollkit/commands/run_node.go +++ b/cmd/rollkit/commands/run_node.go @@ -129,7 +129,7 @@ func NewRunNodeCmd() *cobra.Command { } // initialize the metrics - metrics := node.DefaultMetricsProvider(cometconf.DefaultInstrumentationConfig()) + metrics := node.DefaultMetricsProvider(rollconf.DefaultInstrumentationConfig()) // Try and launch a mock JSON RPC DA server if there is no DA server running. // Only start mock DA server if the user did not provide --rollkit.da_address diff --git a/node/full_node_integration_test.go b/node/full_node_integration_test.go index 949b81551c..090bd97627 100644 --- a/node/full_node_integration_test.go +++ b/node/full_node_integration_test.go @@ -10,10 +10,10 @@ import ( "cosmossdk.io/log" testutils "github.com/celestiaorg/utils/test" - cmcfg "github.com/cometbft/cometbft/config" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + rollkitconfig "github.com/rollkit/rollkit/config" coreexecutor "github.com/rollkit/rollkit/core/execution" coresequencer "github.com/rollkit/rollkit/core/sequencer" "github.com/rollkit/rollkit/types" @@ -78,7 +78,7 @@ func (s *FullNodeTestSuite) SetupTest() { p2pKey, signingKey, genesis, - DefaultMetricsProvider(cmcfg.DefaultInstrumentationConfig()), + DefaultMetricsProvider(rollkitconfig.DefaultInstrumentationConfig()), log.NewTestLogger(s.T()), ) require.NoError(s.T(), err) @@ -329,7 +329,7 @@ func (s *FullNodeTestSuite) TestMaxPending() { p2pKey, signingKey, genesis, - DefaultMetricsProvider(cmcfg.DefaultInstrumentationConfig()), + DefaultMetricsProvider(rollkitconfig.DefaultInstrumentationConfig()), log.NewTestLogger(s.T()), ) require.NoError(err) @@ -411,7 +411,7 @@ func (s *FullNodeTestSuite) TestStateRecovery() { p2pKey, signingKey, genesis, - DefaultMetricsProvider(cmcfg.DefaultInstrumentationConfig()), + DefaultMetricsProvider(rollkitconfig.DefaultInstrumentationConfig()), log.NewTestLogger(s.T()), ) require.NoError(err) @@ -459,7 +459,7 @@ func (s *FullNodeTestSuite) TestInvalidDAConfig() { p2pKey, signingKey, genesis, - DefaultMetricsProvider(cmcfg.DefaultInstrumentationConfig()), + DefaultMetricsProvider(rollkitconfig.DefaultInstrumentationConfig()), log.NewTestLogger(s.T()), ) diff --git a/node/helpers_test.go b/node/helpers_test.go index 34bf4a79ce..5695c013ff 100644 --- a/node/helpers_test.go +++ b/node/helpers_test.go @@ -8,11 +8,11 @@ import ( "time" "cosmossdk.io/log" - cmcfg "github.com/cometbft/cometbft/config" "github.com/libp2p/go-libp2p/core/crypto" "github.com/stretchr/testify/require" "github.com/rollkit/rollkit/config" + rollkitconfig "github.com/rollkit/rollkit/config" coreexecutor "github.com/rollkit/rollkit/core/execution" coresequencer "github.com/rollkit/rollkit/core/sequencer" "github.com/rollkit/rollkit/types" @@ -68,7 +68,7 @@ func setupTestNodeWithCleanup(t *testing.T) (*FullNode, func()) { p2pKey, signingKey, genesis, - DefaultMetricsProvider(cmcfg.DefaultInstrumentationConfig()), + DefaultMetricsProvider(rollkitconfig.DefaultInstrumentationConfig()), log.NewTestLogger(t), ) require.NoError(t, err) diff --git a/node/node_integration_test.go b/node/node_integration_test.go index 842ca4405d..4978fbd7d0 100644 --- a/node/node_integration_test.go +++ b/node/node_integration_test.go @@ -10,11 +10,11 @@ import ( "cosmossdk.io/log" testutils "github.com/celestiaorg/utils/test" - cmcfg "github.com/cometbft/cometbft/config" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "google.golang.org/grpc" + rollkitconfig "github.com/rollkit/rollkit/config" coreexecutor "github.com/rollkit/rollkit/core/execution" coresequencer "github.com/rollkit/rollkit/core/sequencer" "github.com/rollkit/rollkit/types" @@ -62,7 +62,7 @@ func (s *NodeIntegrationTestSuite) SetupTest() { p2pKey, signingKey, genesis, - DefaultMetricsProvider(cmcfg.DefaultInstrumentationConfig()), + DefaultMetricsProvider(rollkitconfig.DefaultInstrumentationConfig()), log.NewTestLogger(s.T()), ) require.NoError(s.T(), err) diff --git a/node/node_test.go b/node/node_test.go index f0642d75c8..bfe26a6e3e 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -11,7 +11,6 @@ import ( "time" "cosmossdk.io/log" - cmconfig "github.com/cometbft/cometbft/config" cmcrypto "github.com/cometbft/cometbft/crypto" "github.com/stretchr/testify/require" "google.golang.org/grpc" @@ -27,6 +26,7 @@ import ( seqTest "github.com/rollkit/go-sequencing/test" "github.com/rollkit/rollkit/config" + rollkitconfig "github.com/rollkit/rollkit/config" coreexecutor "github.com/rollkit/rollkit/core/execution" coresequencer "github.com/rollkit/rollkit/core/sequencer" "github.com/rollkit/rollkit/types" @@ -274,7 +274,7 @@ func newTestNode(ctx context.Context, t *testing.T, nodeType NodeType, chainID s key, signingKey, genesis, - DefaultMetricsProvider(cmconfig.DefaultInstrumentationConfig()), + DefaultMetricsProvider(rollkitconfig.DefaultInstrumentationConfig()), logger, ) return node, genesisValidatorKey, err diff --git a/node/setup.go b/node/setup.go index 248e768b48..e848bc04d1 100644 --- a/node/setup.go +++ b/node/setup.go @@ -3,9 +3,8 @@ package node import ( "time" - cmcfg "github.com/cometbft/cometbft/config" - "github.com/rollkit/rollkit/block" + "github.com/rollkit/rollkit/config" "github.com/rollkit/rollkit/p2p" ) @@ -16,7 +15,7 @@ type MetricsProvider func(chainID string) (*block.Metrics, *p2p.Metrics) // DefaultMetricsProvider returns Metrics build using Prometheus client library // if Prometheus is enabled. Otherwise, it returns no-op Metrics. -func DefaultMetricsProvider(config *cmcfg.InstrumentationConfig) MetricsProvider { +func DefaultMetricsProvider(config *config.InstrumentationConfig) MetricsProvider { return func(chainID string) (*block.Metrics, *p2p.Metrics) { if config.Prometheus { return block.PrometheusMetrics(config.Namespace, "chain_id", chainID), From 726e153e8b27e910d880434ba6e4cb33fc8ec655 Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Tue, 4 Mar 2025 16:26:02 +0100 Subject: [PATCH 04/24] refactor: Update node configuration to use Viper and remove CometBFT dependencies This commit introduces several changes to the node configuration: - Replaces CometBFT config references with Viper-based configuration - Modifies config parsing to use Viper directly - Removes direct dependencies on CometBFT configuration structs - Updates file path handling to use NodeConfig - Adds support for reading Rollkit-specific configuration parameters The changes improve configuration flexibility and reduce direct coupling with CometBFT configuration. --- cmd/rollkit/commands/run_node.go | 66 +++++++---- cmd/rollkit/commands/run_node_test.go | 63 +++++----- config/config.go | 49 ++++---- config/config_test.go | 161 +++++++++++++++++++++++--- config/toml.go | 34 +++++- 5 files changed, 274 insertions(+), 99 deletions(-) diff --git a/cmd/rollkit/commands/run_node.go b/cmd/rollkit/commands/run_node.go index d1ae151668..55129e8523 100644 --- a/cmd/rollkit/commands/run_node.go +++ b/cmd/rollkit/commands/run_node.go @@ -8,15 +8,14 @@ import ( "net" "net/url" "os" + "path/filepath" "syscall" "time" "cosmossdk.io/log" cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" - cometconf "github.com/cometbft/cometbft/config" cometcli "github.com/cometbft/cometbft/libs/cli" cometos "github.com/cometbft/cometbft/libs/os" - cometnode "github.com/cometbft/cometbft/node" cometp2p "github.com/cometbft/cometbft/p2p" cometprivval "github.com/cometbft/cometbft/privval" comettypes "github.com/cometbft/cometbft/types" @@ -45,7 +44,7 @@ import ( var ( // initialize the config with the cometBFT defaults - config = cometconf.DefaultConfig() + //config = cometconf.DefaultConfig() // initialize the rollkit node configuration nodeConfig = rollconf.DefaultNodeConfig @@ -98,16 +97,19 @@ func NewRunNodeCmd() *cobra.Command { return initFiles() }, RunE: func(cmd *cobra.Command, args []string) error { - genDocProvider := cometnode.DefaultGenesisDocProviderFunc(config) + genDocProvider := RollkitGenesisDocProviderFunc(nodeConfig) genDoc, err := genDocProvider() if err != nil { return err } - nodeKey, err := cometp2p.LoadOrGenNodeKey(config.NodeKeyFile()) + nodeKeyFile := filepath.Join(nodeConfig.RootDir, "config", "node_key.json") + nodeKey, err := cometp2p.LoadOrGenNodeKey(nodeKeyFile) if err != nil { return err } - pval := cometprivval.LoadOrGenFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile()) + privValidatorKeyFile := filepath.Join(nodeConfig.RootDir, "config", "priv_validator_key.json") + privValidatorStateFile := filepath.Join(nodeConfig.RootDir, "data", "priv_validator_state.json") + pval := cometprivval.LoadOrGenFilePV(privValidatorKeyFile, privValidatorStateFile) p2pKey, err := rolltypes.GetNodeKey(nodeKey) if err != nil { return err @@ -117,13 +119,7 @@ func NewRunNodeCmd() *cobra.Command { return err } - // default to socket connections for remote clients - if len(config.ABCI) == 0 { - config.ABCI = "socket" - } - // get the node configuration - rollconf.GetNodeConfig(&nodeConfig, config) if err := rollconf.TranslateAddresses(&nodeConfig); err != nil { return err } @@ -188,7 +184,8 @@ func NewRunNodeCmd() *cobra.Command { // use noop proxy app by default if !cmd.Flags().Lookup("proxy_app").Changed { - config.ProxyApp = "noop" + // nodeConfig does not have a ProxyApp field, so we don't need to set it + // config.ProxyApp = "noop" } // Create a cancellable context for the node @@ -325,11 +322,18 @@ func addNodeFlags(cmd *cobra.Command) { // Add cometBFT flags cmtcmd.AddNodeFlags(cmd) - cmd.Flags().String("transport", config.ABCI, "specify abci transport (socket | grpc)") + // nodeConfig does not have a ABCI field, so we use a default value + cmd.Flags().String("transport", "socket", "specify abci transport (socket | grpc)") cmd.Flags().Bool("ci", false, "run node for ci testing") // Add Rollkit flags rollconf.AddFlags(cmd) + + // special handling for the p2p external address, due to inconsistencies in mapstructure and flag name + if cmd.Flags().Lookup("p2p.external-address").Changed { + // nodeConfig.P2P does not have a ExternalAddress field, so we don't need to set it + // nodeConfig.P2P.ExternalAddress = viper.GetString("p2p.external-address") + } } // tryStartMockDAServJSONRPC will try and start a mock JSONRPC server @@ -413,8 +417,8 @@ func tryStartMockExecutorServerGRPC(listenAddress string) (*grpc.Server, error) // note that such a change would also require changing the cosmos-sdk func initFiles() error { // Generate the private validator config files - cometprivvalKeyFile := config.PrivValidatorKeyFile() - cometprivvalStateFile := config.PrivValidatorStateFile() + cometprivvalKeyFile := filepath.Join(nodeConfig.RootDir, "config", "priv_validator_key.json") + cometprivvalStateFile := filepath.Join(nodeConfig.RootDir, "data", "priv_validator_state.json") var pv *cometprivval.FilePV if cometos.FileExists(cometprivvalKeyFile) { pv = cometprivval.LoadFilePV(cometprivvalKeyFile, cometprivvalStateFile) @@ -428,7 +432,7 @@ func initFiles() error { } // Generate the node key config files - nodeKeyFile := config.NodeKeyFile() + nodeKeyFile := filepath.Join(nodeConfig.RootDir, "config", "node_key.json") if cometos.FileExists(nodeKeyFile) { logger.Info("Found node key", "path", nodeKeyFile) } else { @@ -439,7 +443,7 @@ func initFiles() error { } // Generate the genesis file - genFile := config.GenesisFile() + genFile := filepath.Join(nodeConfig.RootDir, "config", "genesis.json") if cometos.FileExists(genFile) { logger.Info("Found genesis file", "path", genFile) } else { @@ -478,15 +482,16 @@ func parseConfig(cmd *cobra.Command) error { return err } } - config.RootDir = home + nodeConfig.RootDir = home // Validate the root directory - cometconf.EnsureRoot(config.RootDir) + rollconf.EnsureRoot(nodeConfig.RootDir) // Validate the config - if err := config.ValidateBasic(); err != nil { - return fmt.Errorf("error in config file: %w", err) - } + // nodeConfig does not have a ValidateBasic method, so we don't need to validate it + // if err := nodeConfig.ValidateBasic(); err != nil { + // return fmt.Errorf("error in config file: %w", err) + // } // Parse the flags if err := parseFlags(cmd); err != nil { @@ -503,7 +508,7 @@ func parseFlags(cmd *cobra.Command) error { } // unmarshal viper into config - err := v.Unmarshal(&config, func(c *mapstructure.DecoderConfig) { + err := v.Unmarshal(&nodeConfig, func(c *mapstructure.DecoderConfig) { c.TagName = "mapstructure" c.DecodeHook = mapstructure.ComposeDecodeHookFunc( mapstructure.StringToTimeDurationHookFunc(), @@ -516,7 +521,8 @@ func parseFlags(cmd *cobra.Command) error { // special handling for the p2p external address, due to inconsistencies in mapstructure and flag name if cmd.Flags().Lookup("p2p.external-address").Changed { - config.P2P.ExternalAddress = viper.GetString("p2p.external-address") + // nodeConfig.P2P does not have a ExternalAddress field, so we don't need to set it + // nodeConfig.P2P.ExternalAddress = viper.GetString("p2p.external-address") } // handle rollkit node configuration @@ -526,3 +532,13 @@ func parseFlags(cmd *cobra.Command) error { return nil } + +// RollkitGenesisDocProviderFunc returns a function that loads the GenesisDoc from the filesystem +// using nodeConfig instead of config. +func RollkitGenesisDocProviderFunc(nodeConfig rollconf.NodeConfig) func() (*comettypes.GenesisDoc, error) { + return func() (*comettypes.GenesisDoc, error) { + // Construct the genesis file path using rootify + genFile := filepath.Join(nodeConfig.RootDir, "config", "genesis.json") + return comettypes.GenesisDocFromFile(genFile) + } +} diff --git a/cmd/rollkit/commands/run_node_test.go b/cmd/rollkit/commands/run_node_test.go index 2329548955..b1ca6a42a8 100644 --- a/cmd/rollkit/commands/run_node_test.go +++ b/cmd/rollkit/commands/run_node_test.go @@ -10,6 +10,7 @@ import ( "testing" "time" + "github.com/spf13/viper" "github.com/stretchr/testify/assert" "github.com/rollkit/go-da" @@ -72,39 +73,46 @@ func TestParseFlags(t *testing.T) { got interface{} expected interface{} }{ - {"ABCI", config.ABCI, "grpc"}, - {"CreateEmptyBlocks", config.Consensus.CreateEmptyBlocks, true}, - {"CreateEmptyBlocksInterval", config.Consensus.CreateEmptyBlocksInterval, 10 * time.Second}, - {"DoubleSignCheckHeight", config.Consensus.DoubleSignCheckHeight, int64(10)}, - {"DBBackend", config.DBBackend, "cleverdb"}, - {"DBDir", config.DBDir(), "data2"}, - {"Moniker", config.Moniker, "yarik-playground2"}, - {"ExternalAddress", config.P2P.ExternalAddress, "127.0.0.0:26000"}, - {"ListenAddress", config.P2P.ListenAddress, "tcp://127.0.0.1:27000"}, - {"PexReactor", config.P2P.PexReactor, true}, - {"PrivatePeerIDs", config.P2P.PrivatePeerIDs, "1,2,3"}, - {"SeedMode", config.P2P.SeedMode, true}, - {"UnconditionalPeerIDs", config.P2P.UnconditionalPeerIDs, "4,5,6"}, - {"PrivValidatorListenAddr", config.PrivValidatorListenAddr, "tcp://127.0.0.1:27003"}, - {"ProxyApp", config.ProxyApp, "tcp://127.0.0.1:27004"}, + // CometBFT fields, available in viper but not in nodeConfig + // TODO: decide if we want to add them to nodeConfig + {"ABCI", viper.GetString("abci"), "grpc"}, + {"CreateEmptyBlocks", viper.GetBool("consensus.create_empty_blocks"), true}, + {"CreateEmptyBlocksInterval", viper.GetDuration("consensus.create_empty_blocks_interval"), 10 * time.Second}, + {"DoubleSignCheckHeight", viper.GetInt64("consensus.double_sign_check_height"), int64(10)}, + {"DBBackend", viper.GetString("db_backend"), "cleverdb"}, + {"DBDir", viper.GetString("db_dir"), "data2"}, + {"Moniker", viper.GetString("moniker"), "yarik-playground2"}, + {"ExternalAddress", viper.GetString("p2p.external-address"), "127.0.0.0:26000"}, + {"ListenAddress", viper.GetString("p2p.laddr"), "tcp://127.0.0.1:27000"}, + {"PexReactor", viper.GetBool("p2p.pex"), true}, + {"PrivatePeerIDs", viper.GetString("p2p.private_peer_ids"), "1,2,3"}, + {"SeedMode", viper.GetBool("p2p.seed_mode"), true}, + {"UnconditionalPeerIDs", viper.GetString("p2p.unconditional_peer_ids"), "4,5,6"}, + {"PrivValidatorListenAddr", viper.GetString("priv_validator_laddr"), "tcp://127.0.0.1:27003"}, + {"ProxyApp", viper.GetString("proxy_app"), "tcp://127.0.0.1:27004"}, + + // Rollkit fields {"Aggregator", nodeConfig.Aggregator, false}, - {"BlockTime", nodeConfig.BlockTime, 2 * time.Second}, + {"BlockTime", nodeConfig.BlockManagerConfig.BlockTime, 2 * time.Second}, {"DAAddress", nodeConfig.DAAddress, "http://127.0.0.1:27005"}, {"DAAuthToken", nodeConfig.DAAuthToken, "token"}, - {"DABlockTime", nodeConfig.DABlockTime, 20 * time.Second}, + {"DABlockTime", nodeConfig.BlockManagerConfig.DABlockTime, 20 * time.Second}, {"DAGasMultiplier", nodeConfig.DAGasMultiplier, 1.5}, {"DAGasPrice", nodeConfig.DAGasPrice, 1.5}, - {"DAMempoolTTL", nodeConfig.DAMempoolTTL, uint64(10)}, + {"DAMempoolTTL", nodeConfig.BlockManagerConfig.DAMempoolTTL, uint64(10)}, {"DANamespace", nodeConfig.DANamespace, "namespace"}, - {"DAStartHeight", nodeConfig.DAStartHeight, uint64(100)}, - {"LazyAggregator", nodeConfig.LazyAggregator, true}, - {"LazyBlockTime", nodeConfig.LazyBlockTime, 2 * time.Minute}, + {"DAStartHeight", nodeConfig.BlockManagerConfig.DAStartHeight, uint64(100)}, + {"LazyAggregator", nodeConfig.BlockManagerConfig.LazyAggregator, true}, + {"LazyBlockTime", nodeConfig.BlockManagerConfig.LazyBlockTime, 2 * time.Minute}, {"Light", nodeConfig.Light, true}, - {"MaxPendingBlocks", nodeConfig.MaxPendingBlocks, uint64(100)}, - {"GRPCListenAddress", config.RPC.GRPCListenAddress, "tcp://127.0.0.1:27006"}, - {"ListenAddress", config.RPC.ListenAddress, "tcp://127.0.0.1:27007"}, - {"PprofListenAddress", config.RPC.PprofListenAddress, "tcp://127.0.0.1:27008"}, - {"Unsafe", config.RPC.Unsafe, true}, + {"MaxPendingBlocks", nodeConfig.BlockManagerConfig.MaxPendingBlocks, uint64(100)}, + + // RPC fields, available in viper but not in nodeConfig + // TODO: decide if we want to add them to nodeConfig + {"GRPCListenAddress", viper.GetString("rpc.grpc_laddr"), "tcp://127.0.0.1:27006"}, + {"RPCListenAddress", viper.GetString("rpc.laddr"), "tcp://127.0.0.1:27007"}, + {"PprofListenAddress", viper.GetString("rpc.pprof_laddr"), "tcp://127.0.0.1:27008"}, + {"Unsafe", viper.GetBool("rpc.unsafe"), true}, } for _, tc := range testCases { @@ -237,9 +245,6 @@ func TestStartMockDAServJSONRPC(t *testing.T) { newServerFunc := func(hostname, port string, da da.DA) *proxy.Server { mockServer := &MockServer{ Server: proxy.NewServer(hostname, port, da), - StartFunc: func(ctx context.Context) error { - return tt.mockServerErr - }, } return mockServer.Server } diff --git a/config/config.go b/config/config.go index f42b117351..d43aee1c48 100644 --- a/config/config.go +++ b/config/config.go @@ -3,7 +3,6 @@ package config import ( "time" - cmcfg "github.com/cometbft/cometbft/config" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -52,9 +51,9 @@ const ( // NodeConfig stores Rollkit node configuration. type NodeConfig struct { // parameters below are translated from existing config - RootDir string - DBPath string - P2P P2PConfig + RootDir string `mapstructure:"root_dir"` + DBPath string `mapstructure:"db_path"` + P2P P2PConfig `mapstructure:"p2p"` // parameters below are Rollkit specific and read from config Aggregator bool `mapstructure:"aggregator"` BlockManagerConfig `mapstructure:",squash"` @@ -100,34 +99,28 @@ type BlockManagerConfig struct { LazyBlockTime time.Duration `mapstructure:"lazy_block_time"` } -// GetNodeConfig translates Tendermint's configuration into Rollkit configuration. -// -// This method only translates configuration, and doesn't verify it. If some option is missing in Tendermint's -// config, it's skipped during translation. -func GetNodeConfig(nodeConf *NodeConfig, cmConf *cmcfg.Config) { - if cmConf != nil { - nodeConf.RootDir = cmConf.RootDir - nodeConf.DBPath = cmConf.DBPath - if cmConf.P2P != nil { - nodeConf.P2P.ListenAddress = cmConf.P2P.ListenAddress - nodeConf.P2P.Seeds = cmConf.P2P.Seeds - } - if cmConf.Instrumentation != nil { - // Convert CometBFT InstrumentationConfig to Rollkit InstrumentationConfig - nodeConf.Instrumentation = &InstrumentationConfig{ - Prometheus: cmConf.Instrumentation.Prometheus, - PrometheusListenAddr: cmConf.Instrumentation.PrometheusListenAddr, - MaxOpenConnections: cmConf.Instrumentation.MaxOpenConnections, - Namespace: "rollkit", // Use Rollkit namespace instead of CometBFT's - } - } - } -} - // GetViperConfig reads configuration parameters from Viper instance. // // This method is called in cosmos-sdk. func (nc *NodeConfig) GetViperConfig(v *viper.Viper) error { + nc.RootDir = v.GetString("root_dir") + nc.DBPath = v.GetString("db_path") + + nc.P2P.ListenAddress = v.GetString("p2p.listen_address") + nc.P2P.Seeds = v.GetString("p2p.seeds") + nc.P2P.BlockedPeers = v.GetString("p2p.blocked_peers") + nc.P2P.AllowedPeers = v.GetString("p2p.allowed_peers") + + if v.IsSet("instrumentation") { + if nc.Instrumentation == nil { + nc.Instrumentation = &InstrumentationConfig{} + } + nc.Instrumentation.Prometheus = v.GetBool("instrumentation.prometheus") + nc.Instrumentation.PrometheusListenAddr = v.GetString("instrumentation.prometheus_listen_addr") + nc.Instrumentation.MaxOpenConnections = v.GetInt("instrumentation.max_open_connections") + nc.Instrumentation.Namespace = "rollkit" + } + nc.Aggregator = v.GetBool(FlagAggregator) nc.DAAddress = v.GetString(FlagDAAddress) nc.DAAuthToken = v.GetString(FlagDAAuthToken) diff --git a/config/config_test.go b/config/config_test.go index b8a6f334a4..e6960d66e9 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -4,7 +4,6 @@ import ( "testing" "time" - cmcfg "github.com/cometbft/cometbft/config" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/stretchr/testify/assert" @@ -14,31 +13,148 @@ func TestGetNodeConfig(t *testing.T) { t.Parallel() cases := []struct { - name string - input *cmcfg.Config - expected NodeConfig + name string + viperValues map[string]interface{} + expected NodeConfig }{ - {"empty", nil, NodeConfig{}}, - {"Seeds", &cmcfg.Config{P2P: &cmcfg.P2PConfig{Seeds: "seeds"}}, NodeConfig{P2P: P2PConfig{Seeds: "seeds"}}}, - {"ListenAddress", &cmcfg.Config{P2P: &cmcfg.P2PConfig{ListenAddress: "127.0.0.1:7676"}}, NodeConfig{P2P: P2PConfig{ListenAddress: "127.0.0.1:7676"}}}, - {"RootDir", &cmcfg.Config{BaseConfig: cmcfg.BaseConfig{RootDir: "~/root"}}, NodeConfig{RootDir: "~/root"}}, - {"DBPath", &cmcfg.Config{BaseConfig: cmcfg.BaseConfig{DBPath: "./database"}}, NodeConfig{DBPath: "./database"}}, + { + "empty", + map[string]interface{}{}, + NodeConfig{}, + }, + { + "Seeds", + map[string]interface{}{ + "p2p.seeds": "seeds", + }, + NodeConfig{P2P: P2PConfig{Seeds: "seeds"}}, + }, + { + "ListenAddress", + map[string]interface{}{ + "p2p.listen_address": "127.0.0.1:7676", + }, + NodeConfig{P2P: P2PConfig{ListenAddress: "127.0.0.1:7676"}}, + }, + { + "RootDir", + map[string]interface{}{ + "root_dir": "~/root", + }, + NodeConfig{RootDir: "~/root"}, + }, + { + "DBPath", + map[string]interface{}{ + "db_path": "./database", + }, + NodeConfig{DBPath: "./database"}, + }, { "Instrumentation", - &cmcfg.Config{ - Instrumentation: &cmcfg.InstrumentationConfig{ + map[string]interface{}{ + "instrumentation.prometheus": true, + "instrumentation.prometheus_listen_addr": ":8888", + "instrumentation.max_open_connections": 5, + "instrumentation.namespace": "rollkit", + }, + NodeConfig{ + Instrumentation: &InstrumentationConfig{ Prometheus: true, PrometheusListenAddr: ":8888", MaxOpenConnections: 5, - Namespace: "cometbft", + Namespace: "rollkit", }, }, + }, + } + + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + // Create a new Viper instance and set the values directly + v := viper.New() + for key, value := range c.viperValues { + v.Set(key, value) + } + + // Read the config from Viper + var actual NodeConfig + err := actual.GetViperConfig(v) + assert.NoError(t, err) + + if c.name == "Instrumentation" { + // Special handling for Instrumentation test case + assert.Equal(t, c.expected.Instrumentation.Prometheus, actual.Instrumentation.Prometheus) + assert.Equal(t, c.expected.Instrumentation.PrometheusListenAddr, actual.Instrumentation.PrometheusListenAddr) + assert.Equal(t, c.expected.Instrumentation.MaxOpenConnections, actual.Instrumentation.MaxOpenConnections) + assert.Equal(t, c.expected.Instrumentation.Namespace, actual.Instrumentation.Namespace) + } else { + assert.Equal(t, c.expected.RootDir, actual.RootDir) + assert.Equal(t, c.expected.DBPath, actual.DBPath) + if c.name == "Seeds" { + assert.Equal(t, c.expected.P2P.Seeds, actual.P2P.Seeds) + } else if c.name == "ListenAddress" { + assert.Equal(t, c.expected.P2P.ListenAddress, actual.P2P.ListenAddress) + } + } + }) + } +} + +// TestConfigFromViper tests that the config can be read directly from Viper +func TestConfigFromViper(t *testing.T) { + t.Parallel() + + cases := []struct { + name string + viperValues map[string]interface{} + expected NodeConfig + }{ + { + "basic_config", + map[string]interface{}{ + "root_dir": "~/root", + "db_path": "./database", + "p2p.listen_address": "127.0.0.1:7676", + "p2p.seeds": "seeds", + }, + NodeConfig{ + RootDir: "~/root", + DBPath: "./database", + P2P: P2PConfig{ + ListenAddress: "127.0.0.1:7676", + Seeds: "seeds", + }, + }, + }, + { + "instrumentation_config", + map[string]interface{}{ + "instrumentation.prometheus": true, + "instrumentation.prometheus_listen_addr": ":8888", + "instrumentation.max_open_connections": 5, + }, NodeConfig{ Instrumentation: &InstrumentationConfig{ Prometheus: true, PrometheusListenAddr: ":8888", MaxOpenConnections: 5, - Namespace: "rollkit", // Should be converted to rollkit namespace + Namespace: "rollkit", + }, + }, + }, + { + "rollkit_specific_config", + map[string]interface{}{ + FlagAggregator: true, + FlagDAAddress: "da-address", + FlagBlockTime: "10s", + }, + NodeConfig{ + Aggregator: true, + DAAddress: "da-address", + BlockManagerConfig: BlockManagerConfig{ + BlockTime: 10 * time.Second, }, }, }, @@ -46,17 +162,30 @@ func TestGetNodeConfig(t *testing.T) { for _, c := range cases { t.Run(c.name, func(t *testing.T) { + v := viper.New() + for key, value := range c.viperValues { + v.Set(key, value) + } + var actual NodeConfig - GetNodeConfig(&actual, c.input) + err := actual.GetViperConfig(v) + assert.NoError(t, err) - if c.name == "Instrumentation" { + if c.name == "instrumentation_config" { // Special handling for Instrumentation test case assert.Equal(t, c.expected.Instrumentation.Prometheus, actual.Instrumentation.Prometheus) assert.Equal(t, c.expected.Instrumentation.PrometheusListenAddr, actual.Instrumentation.PrometheusListenAddr) assert.Equal(t, c.expected.Instrumentation.MaxOpenConnections, actual.Instrumentation.MaxOpenConnections) assert.Equal(t, c.expected.Instrumentation.Namespace, actual.Instrumentation.Namespace) + } else if c.name == "rollkit_specific_config" { + assert.Equal(t, c.expected.Aggregator, actual.Aggregator) + assert.Equal(t, c.expected.DAAddress, actual.DAAddress) + assert.Equal(t, c.expected.BlockManagerConfig.BlockTime, actual.BlockManagerConfig.BlockTime) } else { - assert.Equal(t, c.expected, actual) + assert.Equal(t, c.expected.RootDir, actual.RootDir) + assert.Equal(t, c.expected.DBPath, actual.DBPath) + assert.Equal(t, c.expected.P2P.ListenAddress, actual.P2P.ListenAddress) + assert.Equal(t, c.expected.P2P.Seeds, actual.P2P.Seeds) } }) } diff --git a/config/toml.go b/config/toml.go index a2a089902d..875eda86ae 100644 --- a/config/toml.go +++ b/config/toml.go @@ -11,8 +11,17 @@ import ( // RollkitToml is the filename for the rollkit configuration file. const RollkitToml = "rollkit.toml" +// DefaultDirPerm is the default permissions used when creating directories. +const DefaultDirPerm = 0700 + +// DefaultConfigDir is the default directory for configuration files. +const DefaultConfigDir = "config" + +// DefaultDataDir is the default directory for data files. +const DefaultDataDir = "data" + // ErrReadToml is the error returned when reading the rollkit.toml file fails. -var ErrReadToml = fmt.Errorf("Reading %s", RollkitToml) +var ErrReadToml = fmt.Errorf("reading %s", RollkitToml) // TomlConfig is the configuration read from rollkit.toml type TomlConfig struct { @@ -152,3 +161,26 @@ func WriteTomlConfig(config TomlConfig) error { return nil } + +// EnsureRoot creates the root, config, and data directories if they don't exist, +// and panics if it fails. +func EnsureRoot(rootDir string) { + if err := ensureDir(rootDir, DefaultDirPerm); err != nil { + panic(err.Error()) + } + if err := ensureDir(filepath.Join(rootDir, DefaultConfigDir), DefaultDirPerm); err != nil { + panic(err.Error()) + } + if err := ensureDir(filepath.Join(rootDir, DefaultDataDir), DefaultDirPerm); err != nil { + panic(err.Error()) + } +} + +// ensureDir ensures the directory exists, creating it if necessary. +func ensureDir(dirPath string, mode os.FileMode) error { + err := os.MkdirAll(dirPath, mode) + if err != nil { + return fmt.Errorf("could not create directory %q: %w", dirPath, err) + } + return nil +} From a0819f957eb4406c8dcc7aa9efe863ab54ba213b Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Tue, 4 Mar 2025 16:51:46 +0100 Subject: [PATCH 05/24] refactor: Remove proxy_app configuration in node commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This modification removes references and configurations related to the proxy_app flag in node command files and documentation. The changes include: • Removing the proxy_app flag from tests • Deleting the default configuration code for proxy_app • Updating the Rollkit startup documentation to remove the reference to the flag --- cmd/rollkit/commands/run_node.go | 6 ------ cmd/rollkit/commands/run_node_test.go | 2 -- cmd/rollkit/docs/rollkit_start.md | 1 - 3 files changed, 9 deletions(-) diff --git a/cmd/rollkit/commands/run_node.go b/cmd/rollkit/commands/run_node.go index 55129e8523..63e100c6b3 100644 --- a/cmd/rollkit/commands/run_node.go +++ b/cmd/rollkit/commands/run_node.go @@ -182,12 +182,6 @@ func NewRunNodeCmd() *cobra.Command { logger.Info("Executor address", "address", nodeConfig.ExecutorAddress) - // use noop proxy app by default - if !cmd.Flags().Lookup("proxy_app").Changed { - // nodeConfig does not have a ProxyApp field, so we don't need to set it - // config.ProxyApp = "noop" - } - // Create a cancellable context for the node ctx, cancel := context.WithCancel(cmd.Context()) defer cancel() // Ensure context is cancelled when command exits diff --git a/cmd/rollkit/commands/run_node_test.go b/cmd/rollkit/commands/run_node_test.go index b1ca6a42a8..c25e1b9ea1 100644 --- a/cmd/rollkit/commands/run_node_test.go +++ b/cmd/rollkit/commands/run_node_test.go @@ -35,7 +35,6 @@ func TestParseFlags(t *testing.T) { "--p2p.seed_mode", "--p2p.unconditional_peer_ids", "4,5,6", "--priv_validator_laddr", "tcp://127.0.0.1:27003", - "--proxy_app", "tcp://127.0.0.1:27004", "--rollkit.aggregator=false", "--rollkit.block_time", "2s", "--rollkit.da_address", "http://127.0.0.1:27005", @@ -89,7 +88,6 @@ func TestParseFlags(t *testing.T) { {"SeedMode", viper.GetBool("p2p.seed_mode"), true}, {"UnconditionalPeerIDs", viper.GetString("p2p.unconditional_peer_ids"), "4,5,6"}, {"PrivValidatorListenAddr", viper.GetString("priv_validator_laddr"), "tcp://127.0.0.1:27003"}, - {"ProxyApp", viper.GetString("proxy_app"), "tcp://127.0.0.1:27004"}, // Rollkit fields {"Aggregator", nodeConfig.Aggregator, false}, diff --git a/cmd/rollkit/docs/rollkit_start.md b/cmd/rollkit/docs/rollkit_start.md index aa0cc4560c..4e1adf469e 100644 --- a/cmd/rollkit/docs/rollkit_start.md +++ b/cmd/rollkit/docs/rollkit_start.md @@ -28,7 +28,6 @@ rollkit start [flags] --p2p.seeds string comma-delimited ID@host:port seed nodes --p2p.unconditional_peer_ids string comma-delimited IDs of unconditional peers --priv_validator_laddr string socket address to listen on for connections from external priv_validator process - --proxy_app string proxy app address, or one of: 'kvstore', 'persistent_kvstore' or 'noop' for local testing. (default "tcp://127.0.0.1:26658") --rollkit.aggregator run node in aggregator mode --rollkit.block_time duration block time (for aggregator mode) (default 1s) --rollkit.da_address string DA address (host:port) (default "http://localhost:26658") From ede26905cf4366120b1229a137ba9594f5ab970a Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Tue, 4 Mar 2025 16:55:57 +0100 Subject: [PATCH 06/24] refactor: Remove ABCI transport configuration flags This commit removes references to ABCI transport flags in the Rollkit node commands and documentation. Specifically: - Deleted the `--transport` and `--abci` flags from run_node.go - Removed corresponding flag tests in run_node_test.go - Updated the Rollkit start documentation to remove ABCI transport flag descriptions --- cmd/rollkit/commands/run_node.go | 1 - cmd/rollkit/commands/run_node_test.go | 2 -- cmd/rollkit/docs/rollkit_start.md | 2 -- 3 files changed, 5 deletions(-) diff --git a/cmd/rollkit/commands/run_node.go b/cmd/rollkit/commands/run_node.go index 63e100c6b3..c873eb8086 100644 --- a/cmd/rollkit/commands/run_node.go +++ b/cmd/rollkit/commands/run_node.go @@ -317,7 +317,6 @@ func addNodeFlags(cmd *cobra.Command) { cmtcmd.AddNodeFlags(cmd) // nodeConfig does not have a ABCI field, so we use a default value - cmd.Flags().String("transport", "socket", "specify abci transport (socket | grpc)") cmd.Flags().Bool("ci", false, "run node for ci testing") // Add Rollkit flags diff --git a/cmd/rollkit/commands/run_node_test.go b/cmd/rollkit/commands/run_node_test.go index c25e1b9ea1..bea8fc082e 100644 --- a/cmd/rollkit/commands/run_node_test.go +++ b/cmd/rollkit/commands/run_node_test.go @@ -21,7 +21,6 @@ import ( func TestParseFlags(t *testing.T) { flags := []string{ - "--abci", "grpc", "--consensus.create_empty_blocks", "true", "--consensus.create_empty_blocks_interval", "10s", "--consensus.double_sign_check_height", "10", @@ -74,7 +73,6 @@ func TestParseFlags(t *testing.T) { }{ // CometBFT fields, available in viper but not in nodeConfig // TODO: decide if we want to add them to nodeConfig - {"ABCI", viper.GetString("abci"), "grpc"}, {"CreateEmptyBlocks", viper.GetBool("consensus.create_empty_blocks"), true}, {"CreateEmptyBlocksInterval", viper.GetDuration("consensus.create_empty_blocks_interval"), 10 * time.Second}, {"DoubleSignCheckHeight", viper.GetInt64("consensus.double_sign_check_height"), int64(10)}, diff --git a/cmd/rollkit/docs/rollkit_start.md b/cmd/rollkit/docs/rollkit_start.md index 4e1adf469e..3c332a4d6e 100644 --- a/cmd/rollkit/docs/rollkit_start.md +++ b/cmd/rollkit/docs/rollkit_start.md @@ -9,7 +9,6 @@ rollkit start [flags] ### Options ``` - --abci string specify abci transport (socket | grpc) (default "socket") --ci run node for ci testing --consensus.create_empty_blocks set this to false to only produce blocks when there are txs or when the AppHash changes (default true) --consensus.create_empty_blocks_interval string the possible interval between empty blocks (default "0s") @@ -51,7 +50,6 @@ rollkit start [flags] --rpc.laddr string RPC listen address. Port required (default "tcp://127.0.0.1:26657") --rpc.pprof_laddr string pprof listen address (https://golang.org/pkg/net/http/pprof) --rpc.unsafe enabled unsafe rpc methods - --transport string specify abci transport (socket | grpc) (default "socket") ``` ### Options inherited from parent commands From 90096e72b9911bff7c826ddc85beabe8a0ade418 Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Tue, 4 Mar 2025 17:27:08 +0100 Subject: [PATCH 07/24] refactor: Update P2P configuration to use 'p2p.laddr' instead of 'p2p.listen_address' This commit updates the configuration parsing to use the 'p2p.laddr' key instead of 'p2p.listen_address' across multiple files: - Modified config/config.go to read ListenAddress from 'p2p.laddr' - Updated config/config_test.go to use 'p2p.laddr' in test cases - Adjusted run_node_test.go to reflect the new configuration parsing - Removed commented-out CometBFT config initialization in run_node.go --- cmd/rollkit/commands/run_node.go | 3 --- cmd/rollkit/commands/run_node_test.go | 2 +- config/config.go | 2 +- config/config_test.go | 10 +++++----- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/cmd/rollkit/commands/run_node.go b/cmd/rollkit/commands/run_node.go index c873eb8086..8279cf5735 100644 --- a/cmd/rollkit/commands/run_node.go +++ b/cmd/rollkit/commands/run_node.go @@ -43,9 +43,6 @@ import ( ) var ( - // initialize the config with the cometBFT defaults - //config = cometconf.DefaultConfig() - // initialize the rollkit node configuration nodeConfig = rollconf.DefaultNodeConfig diff --git a/cmd/rollkit/commands/run_node_test.go b/cmd/rollkit/commands/run_node_test.go index bea8fc082e..44b0f595c2 100644 --- a/cmd/rollkit/commands/run_node_test.go +++ b/cmd/rollkit/commands/run_node_test.go @@ -80,7 +80,6 @@ func TestParseFlags(t *testing.T) { {"DBDir", viper.GetString("db_dir"), "data2"}, {"Moniker", viper.GetString("moniker"), "yarik-playground2"}, {"ExternalAddress", viper.GetString("p2p.external-address"), "127.0.0.0:26000"}, - {"ListenAddress", viper.GetString("p2p.laddr"), "tcp://127.0.0.1:27000"}, {"PexReactor", viper.GetBool("p2p.pex"), true}, {"PrivatePeerIDs", viper.GetString("p2p.private_peer_ids"), "1,2,3"}, {"SeedMode", viper.GetBool("p2p.seed_mode"), true}, @@ -101,6 +100,7 @@ func TestParseFlags(t *testing.T) { {"LazyAggregator", nodeConfig.BlockManagerConfig.LazyAggregator, true}, {"LazyBlockTime", nodeConfig.BlockManagerConfig.LazyBlockTime, 2 * time.Minute}, {"Light", nodeConfig.Light, true}, + {"ListenAddress", nodeConfig.P2P.ListenAddress, "tcp://127.0.0.1:27000"}, {"MaxPendingBlocks", nodeConfig.BlockManagerConfig.MaxPendingBlocks, uint64(100)}, // RPC fields, available in viper but not in nodeConfig diff --git a/config/config.go b/config/config.go index d43aee1c48..7fd104eaac 100644 --- a/config/config.go +++ b/config/config.go @@ -106,7 +106,7 @@ func (nc *NodeConfig) GetViperConfig(v *viper.Viper) error { nc.RootDir = v.GetString("root_dir") nc.DBPath = v.GetString("db_path") - nc.P2P.ListenAddress = v.GetString("p2p.listen_address") + nc.P2P.ListenAddress = v.GetString("p2p.laddr") nc.P2P.Seeds = v.GetString("p2p.seeds") nc.P2P.BlockedPeers = v.GetString("p2p.blocked_peers") nc.P2P.AllowedPeers = v.GetString("p2p.allowed_peers") diff --git a/config/config_test.go b/config/config_test.go index e6960d66e9..b40934f406 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -32,7 +32,7 @@ func TestGetNodeConfig(t *testing.T) { { "ListenAddress", map[string]interface{}{ - "p2p.listen_address": "127.0.0.1:7676", + "p2p.laddr": "127.0.0.1:7676", }, NodeConfig{P2P: P2PConfig{ListenAddress: "127.0.0.1:7676"}}, }, @@ -113,10 +113,10 @@ func TestConfigFromViper(t *testing.T) { { "basic_config", map[string]interface{}{ - "root_dir": "~/root", - "db_path": "./database", - "p2p.listen_address": "127.0.0.1:7676", - "p2p.seeds": "seeds", + "root_dir": "~/root", + "db_path": "./database", + "p2p.laddr": "127.0.0.1:7676", + "p2p.seeds": "seeds", }, NodeConfig{ RootDir: "~/root", From d719600fd5266ba9c775e299ec73b912c3e3455a Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Tue, 4 Mar 2025 17:33:09 +0100 Subject: [PATCH 08/24] refactor: Remove commented-out code and unused configurations in run_node.go This change cleans up the code in run_node.go by removing: - Comments related to external P2P address configuration - Commented-out code for basic configuration validation - Redundant or unused sections related to node configuration --- cmd/rollkit/commands/run_node.go | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/cmd/rollkit/commands/run_node.go b/cmd/rollkit/commands/run_node.go index 8279cf5735..2c3ad5fb4a 100644 --- a/cmd/rollkit/commands/run_node.go +++ b/cmd/rollkit/commands/run_node.go @@ -318,12 +318,6 @@ func addNodeFlags(cmd *cobra.Command) { // Add Rollkit flags rollconf.AddFlags(cmd) - - // special handling for the p2p external address, due to inconsistencies in mapstructure and flag name - if cmd.Flags().Lookup("p2p.external-address").Changed { - // nodeConfig.P2P does not have a ExternalAddress field, so we don't need to set it - // nodeConfig.P2P.ExternalAddress = viper.GetString("p2p.external-address") - } } // tryStartMockDAServJSONRPC will try and start a mock JSONRPC server @@ -477,12 +471,6 @@ func parseConfig(cmd *cobra.Command) error { // Validate the root directory rollconf.EnsureRoot(nodeConfig.RootDir) - // Validate the config - // nodeConfig does not have a ValidateBasic method, so we don't need to validate it - // if err := nodeConfig.ValidateBasic(); err != nil { - // return fmt.Errorf("error in config file: %w", err) - // } - // Parse the flags if err := parseFlags(cmd); err != nil { return err @@ -509,12 +497,6 @@ func parseFlags(cmd *cobra.Command) error { return fmt.Errorf("unable to decode command flags into config: %w", err) } - // special handling for the p2p external address, due to inconsistencies in mapstructure and flag name - if cmd.Flags().Lookup("p2p.external-address").Changed { - // nodeConfig.P2P does not have a ExternalAddress field, so we don't need to set it - // nodeConfig.P2P.ExternalAddress = viper.GetString("p2p.external-address") - } - // handle rollkit node configuration if err := nodeConfig.GetViperConfig(v); err != nil { return fmt.Errorf("unable to decode command flags into nodeConfig: %w", err) From 5fa72f22e99aecdd58a27139ebd65e8134c5d40c Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Tue, 4 Mar 2025 17:44:26 +0100 Subject: [PATCH 09/24] refactor: Remove P2P external address configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This modification removes the P2P external address configuration from Rollkit’s test files and documentation. The changes include: • Removal of the --p2p.external-address flag in run_node_test.go • Removal of the external address flag description in Rollkit’s startup documentation --- cmd/rollkit/commands/run_node_test.go | 2 -- cmd/rollkit/docs/rollkit_start.md | 1 - 2 files changed, 3 deletions(-) diff --git a/cmd/rollkit/commands/run_node_test.go b/cmd/rollkit/commands/run_node_test.go index 44b0f595c2..84ea5059e7 100644 --- a/cmd/rollkit/commands/run_node_test.go +++ b/cmd/rollkit/commands/run_node_test.go @@ -27,7 +27,6 @@ func TestParseFlags(t *testing.T) { "--db_backend", "cleverdb", "--db_dir", "data2", "--moniker", "yarik-playground2", - "--p2p.external-address", "127.0.0.0:26000", "--p2p.laddr", "tcp://127.0.0.1:27000", "--p2p.pex", "--p2p.private_peer_ids", "1,2,3", @@ -79,7 +78,6 @@ func TestParseFlags(t *testing.T) { {"DBBackend", viper.GetString("db_backend"), "cleverdb"}, {"DBDir", viper.GetString("db_dir"), "data2"}, {"Moniker", viper.GetString("moniker"), "yarik-playground2"}, - {"ExternalAddress", viper.GetString("p2p.external-address"), "127.0.0.0:26000"}, {"PexReactor", viper.GetBool("p2p.pex"), true}, {"PrivatePeerIDs", viper.GetString("p2p.private_peer_ids"), "1,2,3"}, {"SeedMode", viper.GetBool("p2p.seed_mode"), true}, diff --git a/cmd/rollkit/docs/rollkit_start.md b/cmd/rollkit/docs/rollkit_start.md index 3c332a4d6e..4f104275f7 100644 --- a/cmd/rollkit/docs/rollkit_start.md +++ b/cmd/rollkit/docs/rollkit_start.md @@ -18,7 +18,6 @@ rollkit start [flags] --genesis_hash bytesHex optional SHA-256 hash of the genesis file -h, --help help for start --moniker string node name (default "Your Computer Username") - --p2p.external-address string ip:port address to advertise to peers for them to dial --p2p.laddr string node listen address. (0.0.0.0:0 means any interface, any port) (default "tcp://0.0.0.0:26656") --p2p.persistent_peers string comma-delimited ID@host:port persistent peers --p2p.pex enable/disable Peer-Exchange (default true) From 31007eacf31f034874abbb5dc27098289a990ec7 Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Wed, 5 Mar 2025 10:52:50 +0100 Subject: [PATCH 10/24] remove duplicated rollkit config --- node/helpers_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/node/helpers_test.go b/node/helpers_test.go index 5695c013ff..8ffb01e57f 100644 --- a/node/helpers_test.go +++ b/node/helpers_test.go @@ -11,7 +11,6 @@ import ( "github.com/libp2p/go-libp2p/core/crypto" "github.com/stretchr/testify/require" - "github.com/rollkit/rollkit/config" rollkitconfig "github.com/rollkit/rollkit/config" coreexecutor "github.com/rollkit/rollkit/core/execution" coresequencer "github.com/rollkit/rollkit/core/sequencer" @@ -27,19 +26,19 @@ func generateSingleKey() crypto.PrivKey { return key } -func getTestConfig(n int) config.NodeConfig { +func getTestConfig(n int) rollkitconfig.NodeConfig { startPort := 10000 - return config.NodeConfig{ + return rollkitconfig.NodeConfig{ Aggregator: true, DAAddress: MockDAAddress, DANamespace: MockDANamespace, ExecutorAddress: MockExecutorAddress, SequencerAddress: MockSequencerAddress, - BlockManagerConfig: config.BlockManagerConfig{ + BlockManagerConfig: rollkitconfig.BlockManagerConfig{ BlockTime: 500 * time.Millisecond, LazyBlockTime: 5 * time.Second, }, - P2P: config.P2PConfig{ + P2P: rollkitconfig.P2PConfig{ ListenAddress: "/ip4/127.0.0.1/tcp/" + strconv.Itoa(startPort+n), }, } From 2d99233d7ddf29f58a08ab65cf17bd97e7db63ef Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Wed, 5 Mar 2025 10:54:31 +0100 Subject: [PATCH 11/24] remove duplicate --- node/node_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/node/node_test.go b/node/node_test.go index bfe26a6e3e..63e7f39b64 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -25,7 +25,6 @@ import ( seqGRPC "github.com/rollkit/go-sequencing/proxy/grpc" seqTest "github.com/rollkit/go-sequencing/test" - "github.com/rollkit/rollkit/config" rollkitconfig "github.com/rollkit/rollkit/config" coreexecutor "github.com/rollkit/rollkit/core/execution" coresequencer "github.com/rollkit/rollkit/core/sequencer" @@ -246,7 +245,7 @@ func setupTestNode(ctx context.Context, t *testing.T, nodeType NodeType, chainID // newTestNode creates a new test node based on the NodeType. func newTestNode(ctx context.Context, t *testing.T, nodeType NodeType, chainID string) (Node, cmcrypto.PrivKey, error) { - config := config.NodeConfig{ + config := rollkitconfig.NodeConfig{ DAAddress: MockDAAddress, DANamespace: MockDANamespace, ExecutorAddress: MockExecutorAddress, From 2e53815086840aa0fdc32a7d4c5a6c6dcc8582a8 Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Wed, 5 Mar 2025 13:45:15 +0100 Subject: [PATCH 12/24] Markdown lint --- cmd/rollkit/docs/rollkit.md | 16 +++++++--------- cmd/rollkit/docs/rollkit_completion.md | 11 +++++------ cmd/rollkit/docs/rollkit_completion_bash.md | 7 +++---- cmd/rollkit/docs/rollkit_completion_fish.md | 3 +-- .../docs/rollkit_completion_powershell.md | 3 +-- cmd/rollkit/docs/rollkit_completion_zsh.md | 7 +++---- cmd/rollkit/docs/rollkit_docs-gen.md | 2 +- cmd/rollkit/docs/rollkit_rebuild.md | 2 +- cmd/rollkit/docs/rollkit_start.md | 2 +- cmd/rollkit/docs/rollkit_toml.md | 4 ++-- cmd/rollkit/docs/rollkit_toml_init.md | 2 +- cmd/rollkit/docs/rollkit_version.md | 2 +- 12 files changed, 27 insertions(+), 34 deletions(-) diff --git a/cmd/rollkit/docs/rollkit.md b/cmd/rollkit/docs/rollkit.md index 5a4256f7ea..184a3b8fb2 100644 --- a/cmd/rollkit/docs/rollkit.md +++ b/cmd/rollkit/docs/rollkit.md @@ -4,12 +4,10 @@ The first sovereign rollup framework that allows you to launch a sovereign, cust ### Synopsis - Rollkit is the first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. -The rollkit-cli uses the environment variable "RKHOME" to point to a file path where the node keys, config, and data will be stored. +The rollkit-cli uses the environment variable "RKHOME" to point to a file path where the node keys, config, and data will be stored. If a path is not specified for RKHOME, the rollkit command will create a folder "~/.rollkit" where it will store said data. - ### Options ``` @@ -21,9 +19,9 @@ If a path is not specified for RKHOME, the rollkit command will create a folder ### SEE ALSO -* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell -* [rollkit docs-gen](rollkit_docs-gen.md) - Generate documentation for rollkit CLI -* [rollkit rebuild](rollkit_rebuild.md) - Rebuild rollup entrypoint -* [rollkit start](rollkit_start.md) - Run the rollkit node -* [rollkit toml](rollkit_toml.md) - TOML file operations -* [rollkit version](rollkit_version.md) - Show version info +* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell +* [rollkit docs-gen](rollkit_docs-gen.md) - Generate documentation for rollkit CLI +* [rollkit rebuild](rollkit_rebuild.md) - Rebuild rollup entrypoint +* [rollkit start](rollkit_start.md) - Run the rollkit node +* [rollkit toml](rollkit_toml.md) - TOML file operations +* [rollkit version](rollkit_version.md) - Show version info diff --git a/cmd/rollkit/docs/rollkit_completion.md b/cmd/rollkit/docs/rollkit_completion.md index 451f4a9ca9..255d971e12 100644 --- a/cmd/rollkit/docs/rollkit_completion.md +++ b/cmd/rollkit/docs/rollkit_completion.md @@ -7,7 +7,6 @@ Generate the autocompletion script for the specified shell Generate the autocompletion script for rollkit for the specified shell. See each sub-command's help for details on how to use the generated script. - ### Options ``` @@ -24,8 +23,8 @@ See each sub-command's help for details on how to use the generated script. ### SEE ALSO -* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. -* [rollkit completion bash](rollkit_completion_bash.md) - Generate the autocompletion script for bash -* [rollkit completion fish](rollkit_completion_fish.md) - Generate the autocompletion script for fish -* [rollkit completion powershell](rollkit_completion_powershell.md) - Generate the autocompletion script for powershell -* [rollkit completion zsh](rollkit_completion_zsh.md) - Generate the autocompletion script for zsh +* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. +* [rollkit completion bash](rollkit_completion_bash.md) - Generate the autocompletion script for bash +* [rollkit completion fish](rollkit_completion_fish.md) - Generate the autocompletion script for fish +* [rollkit completion powershell](rollkit_completion_powershell.md) - Generate the autocompletion script for powershell +* [rollkit completion zsh](rollkit_completion_zsh.md) - Generate the autocompletion script for zsh diff --git a/cmd/rollkit/docs/rollkit_completion_bash.md b/cmd/rollkit/docs/rollkit_completion_bash.md index 130134d412..4a9051701d 100644 --- a/cmd/rollkit/docs/rollkit_completion_bash.md +++ b/cmd/rollkit/docs/rollkit_completion_bash.md @@ -15,17 +15,16 @@ To load completions in your current shell session: To load completions for every new session, execute once: -#### Linux: +#### Linux rollkit completion bash > /etc/bash_completion.d/rollkit -#### macOS: +#### macOS rollkit completion bash > $(brew --prefix)/etc/bash_completion.d/rollkit You will need to start a new shell for this setup to take effect. - ``` rollkit completion bash ``` @@ -47,4 +46,4 @@ rollkit completion bash ### SEE ALSO -* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell +* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell diff --git a/cmd/rollkit/docs/rollkit_completion_fish.md b/cmd/rollkit/docs/rollkit_completion_fish.md index 7e6386a01f..dd35e73107 100644 --- a/cmd/rollkit/docs/rollkit_completion_fish.md +++ b/cmd/rollkit/docs/rollkit_completion_fish.md @@ -16,7 +16,6 @@ To load completions for every new session, execute once: You will need to start a new shell for this setup to take effect. - ``` rollkit completion fish [flags] ``` @@ -38,4 +37,4 @@ rollkit completion fish [flags] ### SEE ALSO -* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell +* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell diff --git a/cmd/rollkit/docs/rollkit_completion_powershell.md b/cmd/rollkit/docs/rollkit_completion_powershell.md index 6d06a6b61e..e1117333e5 100644 --- a/cmd/rollkit/docs/rollkit_completion_powershell.md +++ b/cmd/rollkit/docs/rollkit_completion_powershell.md @@ -13,7 +13,6 @@ To load completions in your current shell session: To load completions for every new session, add the output of the above command to your powershell profile. - ``` rollkit completion powershell [flags] ``` @@ -35,4 +34,4 @@ rollkit completion powershell [flags] ### SEE ALSO -* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell +* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell diff --git a/cmd/rollkit/docs/rollkit_completion_zsh.md b/cmd/rollkit/docs/rollkit_completion_zsh.md index e3e0263af0..44ce5dc618 100644 --- a/cmd/rollkit/docs/rollkit_completion_zsh.md +++ b/cmd/rollkit/docs/rollkit_completion_zsh.md @@ -17,17 +17,16 @@ To load completions in your current shell session: To load completions for every new session, execute once: -#### Linux: +#### Linux rollkit completion zsh > "${fpath[1]}/_rollkit" -#### macOS: +#### macOS rollkit completion zsh > $(brew --prefix)/share/zsh/site-functions/_rollkit You will need to start a new shell for this setup to take effect. - ``` rollkit completion zsh [flags] ``` @@ -49,4 +48,4 @@ rollkit completion zsh [flags] ### SEE ALSO -* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell +* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell diff --git a/cmd/rollkit/docs/rollkit_docs-gen.md b/cmd/rollkit/docs/rollkit_docs-gen.md index eb76469d92..94e93fb4fa 100644 --- a/cmd/rollkit/docs/rollkit_docs-gen.md +++ b/cmd/rollkit/docs/rollkit_docs-gen.md @@ -22,4 +22,4 @@ rollkit docs-gen [flags] ### SEE ALSO -* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. +* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. diff --git a/cmd/rollkit/docs/rollkit_rebuild.md b/cmd/rollkit/docs/rollkit_rebuild.md index 99ef5118ca..d7e5147324 100644 --- a/cmd/rollkit/docs/rollkit_rebuild.md +++ b/cmd/rollkit/docs/rollkit_rebuild.md @@ -26,4 +26,4 @@ rollkit rebuild [flags] ### SEE ALSO -* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. +* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. diff --git a/cmd/rollkit/docs/rollkit_start.md b/cmd/rollkit/docs/rollkit_start.md index 4f104275f7..821f7e05c4 100644 --- a/cmd/rollkit/docs/rollkit_start.md +++ b/cmd/rollkit/docs/rollkit_start.md @@ -61,4 +61,4 @@ rollkit start [flags] ### SEE ALSO -* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. +* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. diff --git a/cmd/rollkit/docs/rollkit_toml.md b/cmd/rollkit/docs/rollkit_toml.md index ba0ae4519a..80f65f56bd 100644 --- a/cmd/rollkit/docs/rollkit_toml.md +++ b/cmd/rollkit/docs/rollkit_toml.md @@ -28,5 +28,5 @@ This command group is used to interact with TOML files. ### SEE ALSO -* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. -* [rollkit toml init](rollkit_toml_init.md) - Initialize a new rollkit.toml file +* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. +* [rollkit toml init](rollkit_toml_init.md) - Initialize a new rollkit.toml file diff --git a/cmd/rollkit/docs/rollkit_toml_init.md b/cmd/rollkit/docs/rollkit_toml_init.md index ef9054f18f..64c829ef57 100644 --- a/cmd/rollkit/docs/rollkit_toml_init.md +++ b/cmd/rollkit/docs/rollkit_toml_init.md @@ -26,4 +26,4 @@ rollkit toml init [flags] ### SEE ALSO -* [rollkit toml](rollkit_toml.md) - TOML file operations +* [rollkit toml](rollkit_toml.md) - TOML file operations diff --git a/cmd/rollkit/docs/rollkit_version.md b/cmd/rollkit/docs/rollkit_version.md index 053ac99d7f..128252454e 100644 --- a/cmd/rollkit/docs/rollkit_version.md +++ b/cmd/rollkit/docs/rollkit_version.md @@ -22,4 +22,4 @@ rollkit version [flags] ### SEE ALSO -* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. +* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. From 08746a5a2f1d27b0c4b37d2ec974cb00791c2b27 Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Wed, 5 Mar 2025 14:42:23 +0100 Subject: [PATCH 13/24] use default nodeRollkit --- config/defaults.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/config/defaults.go b/config/defaults.go index 9afc02bb77..92049cbfe4 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -1,6 +1,8 @@ package config import ( + "os" + "path/filepath" "time" ) @@ -22,8 +24,19 @@ const ( DefaultLogLevel = "info" ) +// DefaultRootDir returns the default root directory for rollkit +func DefaultRootDir() string { + home, err := os.UserHomeDir() + if err != nil { + return "" + } + return filepath.Join(home, ".rollkit") +} + // DefaultNodeConfig keeps default values of NodeConfig var DefaultNodeConfig = NodeConfig{ + RootDir: DefaultRootDir(), + DBPath: "data", P2P: P2PConfig{ ListenAddress: DefaultListenAddress, Seeds: "", From 01f5412bf18a2bdd35e948a17a11457206d61f97 Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Wed, 5 Mar 2025 15:06:32 +0100 Subject: [PATCH 14/24] Add conditionals to viper load --- config/config.go | 112 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 84 insertions(+), 28 deletions(-) diff --git a/config/config.go b/config/config.go index 7fd104eaac..6926602c7c 100644 --- a/config/config.go +++ b/config/config.go @@ -103,43 +103,99 @@ type BlockManagerConfig struct { // // This method is called in cosmos-sdk. func (nc *NodeConfig) GetViperConfig(v *viper.Viper) error { - nc.RootDir = v.GetString("root_dir") - nc.DBPath = v.GetString("db_path") + if v.IsSet("root_dir") { + nc.RootDir = v.GetString("root_dir") + } + if v.IsSet("db_path") { + nc.DBPath = v.GetString("db_path") + } - nc.P2P.ListenAddress = v.GetString("p2p.laddr") - nc.P2P.Seeds = v.GetString("p2p.seeds") - nc.P2P.BlockedPeers = v.GetString("p2p.blocked_peers") - nc.P2P.AllowedPeers = v.GetString("p2p.allowed_peers") + if v.IsSet("p2p.laddr") { + nc.P2P.ListenAddress = v.GetString("p2p.laddr") + } + if v.IsSet("p2p.seeds") { + nc.P2P.Seeds = v.GetString("p2p.seeds") + } + if v.IsSet("p2p.blocked_peers") { + nc.P2P.BlockedPeers = v.GetString("p2p.blocked_peers") + } + if v.IsSet("p2p.allowed_peers") { + nc.P2P.AllowedPeers = v.GetString("p2p.allowed_peers") + } if v.IsSet("instrumentation") { if nc.Instrumentation == nil { nc.Instrumentation = &InstrumentationConfig{} } - nc.Instrumentation.Prometheus = v.GetBool("instrumentation.prometheus") - nc.Instrumentation.PrometheusListenAddr = v.GetString("instrumentation.prometheus_listen_addr") - nc.Instrumentation.MaxOpenConnections = v.GetInt("instrumentation.max_open_connections") + if v.IsSet("instrumentation.prometheus") { + nc.Instrumentation.Prometheus = v.GetBool("instrumentation.prometheus") + } + if v.IsSet("instrumentation.prometheus_listen_addr") { + nc.Instrumentation.PrometheusListenAddr = v.GetString("instrumentation.prometheus_listen_addr") + } + if v.IsSet("instrumentation.max_open_connections") { + nc.Instrumentation.MaxOpenConnections = v.GetInt("instrumentation.max_open_connections") + } nc.Instrumentation.Namespace = "rollkit" } - nc.Aggregator = v.GetBool(FlagAggregator) - nc.DAAddress = v.GetString(FlagDAAddress) - nc.DAAuthToken = v.GetString(FlagDAAuthToken) - nc.DAGasPrice = v.GetFloat64(FlagDAGasPrice) - nc.DAGasMultiplier = v.GetFloat64(FlagDAGasMultiplier) - nc.DANamespace = v.GetString(FlagDANamespace) - nc.DAStartHeight = v.GetUint64(FlagDAStartHeight) - nc.DABlockTime = v.GetDuration(FlagDABlockTime) - nc.DASubmitOptions = v.GetString(FlagDASubmitOptions) - nc.BlockTime = v.GetDuration(FlagBlockTime) - nc.LazyAggregator = v.GetBool(FlagLazyAggregator) - nc.Light = v.GetBool(FlagLight) - nc.TrustedHash = v.GetString(FlagTrustedHash) - nc.MaxPendingBlocks = v.GetUint64(FlagMaxPendingBlocks) - nc.DAMempoolTTL = v.GetUint64(FlagDAMempoolTTL) - nc.LazyBlockTime = v.GetDuration(FlagLazyBlockTime) - nc.SequencerAddress = v.GetString(FlagSequencerAddress) - nc.SequencerRollupID = v.GetString(FlagSequencerRollupID) - nc.ExecutorAddress = v.GetString(FlagExecutorAddress) + if v.IsSet(FlagAggregator) { + nc.Aggregator = v.GetBool(FlagAggregator) + } + if v.IsSet(FlagDAAddress) { + nc.DAAddress = v.GetString(FlagDAAddress) + } + if v.IsSet(FlagDAAuthToken) { + nc.DAAuthToken = v.GetString(FlagDAAuthToken) + } + if v.IsSet(FlagDAGasPrice) { + nc.DAGasPrice = v.GetFloat64(FlagDAGasPrice) + } + if v.IsSet(FlagDAGasMultiplier) { + nc.DAGasMultiplier = v.GetFloat64(FlagDAGasMultiplier) + } + if v.IsSet(FlagDANamespace) { + nc.DANamespace = v.GetString(FlagDANamespace) + } + if v.IsSet(FlagDAStartHeight) { + nc.DAStartHeight = v.GetUint64(FlagDAStartHeight) + } + if v.IsSet(FlagDABlockTime) { + nc.DABlockTime = v.GetDuration(FlagDABlockTime) + } + if v.IsSet(FlagDASubmitOptions) { + nc.DASubmitOptions = v.GetString(FlagDASubmitOptions) + } + if v.IsSet(FlagBlockTime) { + nc.BlockTime = v.GetDuration(FlagBlockTime) + } + if v.IsSet(FlagLazyAggregator) { + nc.LazyAggregator = v.GetBool(FlagLazyAggregator) + } + if v.IsSet(FlagLight) { + nc.Light = v.GetBool(FlagLight) + } + if v.IsSet(FlagTrustedHash) { + nc.TrustedHash = v.GetString(FlagTrustedHash) + } + if v.IsSet(FlagMaxPendingBlocks) { + nc.MaxPendingBlocks = v.GetUint64(FlagMaxPendingBlocks) + } + if v.IsSet(FlagDAMempoolTTL) { + nc.DAMempoolTTL = v.GetUint64(FlagDAMempoolTTL) + } + if v.IsSet(FlagLazyBlockTime) { + nc.LazyBlockTime = v.GetDuration(FlagLazyBlockTime) + } + if v.IsSet(FlagSequencerAddress) { + nc.SequencerAddress = v.GetString(FlagSequencerAddress) + } + if v.IsSet(FlagSequencerRollupID) { + nc.SequencerRollupID = v.GetString(FlagSequencerRollupID) + } + if v.IsSet(FlagExecutorAddress) { + nc.ExecutorAddress = v.GetString(FlagExecutorAddress) + } return nil } From 9892f0eac3b944481bd3c842632f98605863cab2 Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Wed, 5 Mar 2025 15:19:54 +0100 Subject: [PATCH 15/24] fix default url --- config/defaults.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/defaults.go b/config/defaults.go index 92049cbfe4..751abd0bbd 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -8,7 +8,7 @@ import ( const ( // DefaultListenAddress is a default listen address for P2P client. - DefaultListenAddress = "/ip4/0.0.0.0/tcp/7676" + DefaultListenAddress = "tcp://0.0.0.0:7676" // Version is the current rollkit version // Please keep updated with each new release Version = "0.38.5" From 7f57d499a6135b5d160e389eeffb3c453da3dee3 Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Wed, 5 Mar 2025 16:37:35 +0100 Subject: [PATCH 16/24] fix units --- config/defaults.go | 2 +- p2p/client_test.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/config/defaults.go b/config/defaults.go index 751abd0bbd..92049cbfe4 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -8,7 +8,7 @@ import ( const ( // DefaultListenAddress is a default listen address for P2P client. - DefaultListenAddress = "tcp://0.0.0.0:7676" + DefaultListenAddress = "/ip4/0.0.0.0/tcp/7676" // Version is the current rollkit version // Please keep updated with each new release Version = "0.38.5" diff --git a/p2p/client_test.go b/p2p/client_test.go index 19f74359b1..24f439347d 100644 --- a/p2p/client_test.go +++ b/p2p/client_test.go @@ -4,6 +4,7 @@ import ( "context" "crypto/rand" "testing" + "time" "cosmossdk.io/log" "github.com/ipfs/go-datastore" @@ -70,6 +71,9 @@ func TestBootstrapping(t *testing.T) { // wait for clients to finish refreshing routing tables clients.WaitForDHT() + // Add a small delay to allow connections to be established + time.Sleep(100 * time.Millisecond) + for _, client := range clients { assert.Equal(3, len(client.host.Network().Peers())) } From b2fca53b2c1ccd89839ece4fd6888d74f050a623 Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Wed, 5 Mar 2025 16:44:24 +0100 Subject: [PATCH 17/24] update code --- cmd/rollkit/commands/run_node.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/cmd/rollkit/commands/run_node.go b/cmd/rollkit/commands/run_node.go index baaf17a80f..5daebed00c 100644 --- a/cmd/rollkit/commands/run_node.go +++ b/cmd/rollkit/commands/run_node.go @@ -116,11 +116,6 @@ func NewRunNodeCmd() *cobra.Command { return err } - // get the node configuration - if err := rollconf.TranslateAddresses(&nodeConfig); err != nil { - return err - } - // initialize the metrics metrics := node.DefaultMetricsProvider(rollconf.DefaultInstrumentationConfig()) From 1feddf3decb9b10d5c82d1f8a1bad8136235a97e Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Wed, 5 Mar 2025 16:49:45 +0100 Subject: [PATCH 18/24] update docs --- cmd/rollkit/docs/rollkit.md | 16 +++++++++------- cmd/rollkit/docs/rollkit_completion.md | 11 ++++++----- cmd/rollkit/docs/rollkit_completion_bash.md | 7 ++++--- cmd/rollkit/docs/rollkit_completion_fish.md | 3 ++- .../docs/rollkit_completion_powershell.md | 3 ++- cmd/rollkit/docs/rollkit_completion_zsh.md | 7 ++++--- cmd/rollkit/docs/rollkit_docs-gen.md | 2 +- cmd/rollkit/docs/rollkit_rebuild.md | 2 +- cmd/rollkit/docs/rollkit_start.md | 5 ++++- cmd/rollkit/docs/rollkit_toml.md | 4 ++-- cmd/rollkit/docs/rollkit_toml_init.md | 2 +- cmd/rollkit/docs/rollkit_version.md | 2 +- 12 files changed, 37 insertions(+), 27 deletions(-) diff --git a/cmd/rollkit/docs/rollkit.md b/cmd/rollkit/docs/rollkit.md index 184a3b8fb2..5a4256f7ea 100644 --- a/cmd/rollkit/docs/rollkit.md +++ b/cmd/rollkit/docs/rollkit.md @@ -4,10 +4,12 @@ The first sovereign rollup framework that allows you to launch a sovereign, cust ### Synopsis + Rollkit is the first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. -The rollkit-cli uses the environment variable "RKHOME" to point to a file path where the node keys, config, and data will be stored. +The rollkit-cli uses the environment variable "RKHOME" to point to a file path where the node keys, config, and data will be stored. If a path is not specified for RKHOME, the rollkit command will create a folder "~/.rollkit" where it will store said data. + ### Options ``` @@ -19,9 +21,9 @@ If a path is not specified for RKHOME, the rollkit command will create a folder ### SEE ALSO -* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell -* [rollkit docs-gen](rollkit_docs-gen.md) - Generate documentation for rollkit CLI -* [rollkit rebuild](rollkit_rebuild.md) - Rebuild rollup entrypoint -* [rollkit start](rollkit_start.md) - Run the rollkit node -* [rollkit toml](rollkit_toml.md) - TOML file operations -* [rollkit version](rollkit_version.md) - Show version info +* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell +* [rollkit docs-gen](rollkit_docs-gen.md) - Generate documentation for rollkit CLI +* [rollkit rebuild](rollkit_rebuild.md) - Rebuild rollup entrypoint +* [rollkit start](rollkit_start.md) - Run the rollkit node +* [rollkit toml](rollkit_toml.md) - TOML file operations +* [rollkit version](rollkit_version.md) - Show version info diff --git a/cmd/rollkit/docs/rollkit_completion.md b/cmd/rollkit/docs/rollkit_completion.md index 255d971e12..451f4a9ca9 100644 --- a/cmd/rollkit/docs/rollkit_completion.md +++ b/cmd/rollkit/docs/rollkit_completion.md @@ -7,6 +7,7 @@ Generate the autocompletion script for the specified shell Generate the autocompletion script for rollkit for the specified shell. See each sub-command's help for details on how to use the generated script. + ### Options ``` @@ -23,8 +24,8 @@ See each sub-command's help for details on how to use the generated script. ### SEE ALSO -* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. -* [rollkit completion bash](rollkit_completion_bash.md) - Generate the autocompletion script for bash -* [rollkit completion fish](rollkit_completion_fish.md) - Generate the autocompletion script for fish -* [rollkit completion powershell](rollkit_completion_powershell.md) - Generate the autocompletion script for powershell -* [rollkit completion zsh](rollkit_completion_zsh.md) - Generate the autocompletion script for zsh +* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. +* [rollkit completion bash](rollkit_completion_bash.md) - Generate the autocompletion script for bash +* [rollkit completion fish](rollkit_completion_fish.md) - Generate the autocompletion script for fish +* [rollkit completion powershell](rollkit_completion_powershell.md) - Generate the autocompletion script for powershell +* [rollkit completion zsh](rollkit_completion_zsh.md) - Generate the autocompletion script for zsh diff --git a/cmd/rollkit/docs/rollkit_completion_bash.md b/cmd/rollkit/docs/rollkit_completion_bash.md index 4a9051701d..130134d412 100644 --- a/cmd/rollkit/docs/rollkit_completion_bash.md +++ b/cmd/rollkit/docs/rollkit_completion_bash.md @@ -15,16 +15,17 @@ To load completions in your current shell session: To load completions for every new session, execute once: -#### Linux +#### Linux: rollkit completion bash > /etc/bash_completion.d/rollkit -#### macOS +#### macOS: rollkit completion bash > $(brew --prefix)/etc/bash_completion.d/rollkit You will need to start a new shell for this setup to take effect. + ``` rollkit completion bash ``` @@ -46,4 +47,4 @@ rollkit completion bash ### SEE ALSO -* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell +* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell diff --git a/cmd/rollkit/docs/rollkit_completion_fish.md b/cmd/rollkit/docs/rollkit_completion_fish.md index dd35e73107..7e6386a01f 100644 --- a/cmd/rollkit/docs/rollkit_completion_fish.md +++ b/cmd/rollkit/docs/rollkit_completion_fish.md @@ -16,6 +16,7 @@ To load completions for every new session, execute once: You will need to start a new shell for this setup to take effect. + ``` rollkit completion fish [flags] ``` @@ -37,4 +38,4 @@ rollkit completion fish [flags] ### SEE ALSO -* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell +* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell diff --git a/cmd/rollkit/docs/rollkit_completion_powershell.md b/cmd/rollkit/docs/rollkit_completion_powershell.md index e1117333e5..6d06a6b61e 100644 --- a/cmd/rollkit/docs/rollkit_completion_powershell.md +++ b/cmd/rollkit/docs/rollkit_completion_powershell.md @@ -13,6 +13,7 @@ To load completions in your current shell session: To load completions for every new session, add the output of the above command to your powershell profile. + ``` rollkit completion powershell [flags] ``` @@ -34,4 +35,4 @@ rollkit completion powershell [flags] ### SEE ALSO -* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell +* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell diff --git a/cmd/rollkit/docs/rollkit_completion_zsh.md b/cmd/rollkit/docs/rollkit_completion_zsh.md index 44ce5dc618..e3e0263af0 100644 --- a/cmd/rollkit/docs/rollkit_completion_zsh.md +++ b/cmd/rollkit/docs/rollkit_completion_zsh.md @@ -17,16 +17,17 @@ To load completions in your current shell session: To load completions for every new session, execute once: -#### Linux +#### Linux: rollkit completion zsh > "${fpath[1]}/_rollkit" -#### macOS +#### macOS: rollkit completion zsh > $(brew --prefix)/share/zsh/site-functions/_rollkit You will need to start a new shell for this setup to take effect. + ``` rollkit completion zsh [flags] ``` @@ -48,4 +49,4 @@ rollkit completion zsh [flags] ### SEE ALSO -* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell +* [rollkit completion](rollkit_completion.md) - Generate the autocompletion script for the specified shell diff --git a/cmd/rollkit/docs/rollkit_docs-gen.md b/cmd/rollkit/docs/rollkit_docs-gen.md index 94e93fb4fa..eb76469d92 100644 --- a/cmd/rollkit/docs/rollkit_docs-gen.md +++ b/cmd/rollkit/docs/rollkit_docs-gen.md @@ -22,4 +22,4 @@ rollkit docs-gen [flags] ### SEE ALSO -* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. +* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. diff --git a/cmd/rollkit/docs/rollkit_rebuild.md b/cmd/rollkit/docs/rollkit_rebuild.md index d7e5147324..99ef5118ca 100644 --- a/cmd/rollkit/docs/rollkit_rebuild.md +++ b/cmd/rollkit/docs/rollkit_rebuild.md @@ -26,4 +26,4 @@ rollkit rebuild [flags] ### SEE ALSO -* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. +* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. diff --git a/cmd/rollkit/docs/rollkit_start.md b/cmd/rollkit/docs/rollkit_start.md index 821f7e05c4..edadac9a3a 100644 --- a/cmd/rollkit/docs/rollkit_start.md +++ b/cmd/rollkit/docs/rollkit_start.md @@ -9,6 +9,7 @@ rollkit start [flags] ### Options ``` + --abci string specify abci transport (socket | grpc) (default "socket") --ci run node for ci testing --consensus.create_empty_blocks set this to false to only produce blocks when there are txs or when the AppHash changes (default true) --consensus.create_empty_blocks_interval string the possible interval between empty blocks (default "0s") @@ -18,6 +19,7 @@ rollkit start [flags] --genesis_hash bytesHex optional SHA-256 hash of the genesis file -h, --help help for start --moniker string node name (default "Your Computer Username") + --p2p.external-address string ip:port address to advertise to peers for them to dial --p2p.laddr string node listen address. (0.0.0.0:0 means any interface, any port) (default "tcp://0.0.0.0:26656") --p2p.persistent_peers string comma-delimited ID@host:port persistent peers --p2p.pex enable/disable Peer-Exchange (default true) @@ -26,6 +28,7 @@ rollkit start [flags] --p2p.seeds string comma-delimited ID@host:port seed nodes --p2p.unconditional_peer_ids string comma-delimited IDs of unconditional peers --priv_validator_laddr string socket address to listen on for connections from external priv_validator process + --proxy_app string proxy app address, or one of: 'kvstore', 'persistent_kvstore' or 'noop' for local testing. (default "tcp://127.0.0.1:26658") --rollkit.aggregator run node in aggregator mode --rollkit.block_time duration block time (for aggregator mode) (default 1s) --rollkit.da_address string DA address (host:port) (default "http://localhost:26658") @@ -61,4 +64,4 @@ rollkit start [flags] ### SEE ALSO -* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. +* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. diff --git a/cmd/rollkit/docs/rollkit_toml.md b/cmd/rollkit/docs/rollkit_toml.md index 80f65f56bd..ba0ae4519a 100644 --- a/cmd/rollkit/docs/rollkit_toml.md +++ b/cmd/rollkit/docs/rollkit_toml.md @@ -28,5 +28,5 @@ This command group is used to interact with TOML files. ### SEE ALSO -* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. -* [rollkit toml init](rollkit_toml_init.md) - Initialize a new rollkit.toml file +* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. +* [rollkit toml init](rollkit_toml_init.md) - Initialize a new rollkit.toml file diff --git a/cmd/rollkit/docs/rollkit_toml_init.md b/cmd/rollkit/docs/rollkit_toml_init.md index 64c829ef57..ef9054f18f 100644 --- a/cmd/rollkit/docs/rollkit_toml_init.md +++ b/cmd/rollkit/docs/rollkit_toml_init.md @@ -26,4 +26,4 @@ rollkit toml init [flags] ### SEE ALSO -* [rollkit toml](rollkit_toml.md) - TOML file operations +* [rollkit toml](rollkit_toml.md) - TOML file operations diff --git a/cmd/rollkit/docs/rollkit_version.md b/cmd/rollkit/docs/rollkit_version.md index 128252454e..053ac99d7f 100644 --- a/cmd/rollkit/docs/rollkit_version.md +++ b/cmd/rollkit/docs/rollkit_version.md @@ -22,4 +22,4 @@ rollkit version [flags] ### SEE ALSO -* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. +* [rollkit](rollkit.md) - The first sovereign rollup framework that allows you to launch a sovereign, customizable blockchain as easily as a smart contract. From dfd8f01f156be8dcaea1827f280d353406db8742 Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Wed, 5 Mar 2025 17:08:40 +0100 Subject: [PATCH 19/24] remove links --- specs/src/SUMMARY.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/specs/src/SUMMARY.md b/specs/src/SUMMARY.md index 627512a41b..8923f51703 100644 --- a/specs/src/SUMMARY.md +++ b/specs/src/SUMMARY.md @@ -5,14 +5,9 @@ - [Template](./specs/template.md) - [Dependency Graph](./specs/rollkit-dependency-graph.md) - [Block Manager](./specs/block-manager.md) -- [Block Executor](./specs/block-executor.md) - [Block Validity](./specs/block-validity.md) - [DA](./specs/da.md) - [Full Node](./specs/full_node.md) - [Header Sync](./specs/header-sync.md) -- [Indexer Service](./specs/indexer-service.md) -- [Mempool](./specs/mempool.md) - [P2P](./specs/p2p.md) -- [State](./specs/state.md) - [Store](./specs/store.md) -- [Validators](./specs/validators.md) From 48aaf04f5eba29156a9755336c4bbc7debe5dec7 Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Wed, 5 Mar 2025 17:24:39 +0100 Subject: [PATCH 20/24] fix files mdbook --- specs/src/specs/block-executor.md | 1 - specs/src/specs/indexer-service.md | 1 - specs/src/specs/mempool.md | 1 - specs/src/specs/state.md | 1 - specs/src/specs/validators.md | 1 - 5 files changed, 5 deletions(-) delete mode 120000 specs/src/specs/block-executor.md delete mode 120000 specs/src/specs/indexer-service.md delete mode 120000 specs/src/specs/mempool.md delete mode 120000 specs/src/specs/state.md delete mode 120000 specs/src/specs/validators.md diff --git a/specs/src/specs/block-executor.md b/specs/src/specs/block-executor.md deleted file mode 120000 index a61146216c..0000000000 --- a/specs/src/specs/block-executor.md +++ /dev/null @@ -1 +0,0 @@ -../../../state/block-executor.md \ No newline at end of file diff --git a/specs/src/specs/indexer-service.md b/specs/src/specs/indexer-service.md deleted file mode 120000 index d59f95d562..0000000000 --- a/specs/src/specs/indexer-service.md +++ /dev/null @@ -1 +0,0 @@ -../../../state/indexer-service.md \ No newline at end of file diff --git a/specs/src/specs/mempool.md b/specs/src/specs/mempool.md deleted file mode 120000 index 08f1cf8113..0000000000 --- a/specs/src/specs/mempool.md +++ /dev/null @@ -1 +0,0 @@ -../../../mempool/mempool.md \ No newline at end of file diff --git a/specs/src/specs/state.md b/specs/src/specs/state.md deleted file mode 120000 index a61146216c..0000000000 --- a/specs/src/specs/state.md +++ /dev/null @@ -1 +0,0 @@ -../../../state/block-executor.md \ No newline at end of file diff --git a/specs/src/specs/validators.md b/specs/src/specs/validators.md deleted file mode 120000 index 4f413be8b2..0000000000 --- a/specs/src/specs/validators.md +++ /dev/null @@ -1 +0,0 @@ -../../../state/validators.md \ No newline at end of file From 2af5c656e698c1b312566ad77dcc8ee9d8fb6a7b Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Wed, 5 Mar 2025 17:33:13 +0100 Subject: [PATCH 21/24] fix dockerfile --- Dockerfile | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2814c3902e..36d8aef167 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ ## prep the base image. # -FROM golang as base +FROM golang AS base RUN apt update && \ apt-get install -y \ @@ -9,21 +9,20 @@ RUN apt update && \ curl # enable faster module downloading. -ENV GOPROXY https://proxy.golang.org +ENV GOPROXY=https://proxy.golang.org ## builder stage. # -FROM base as builder +FROM base AS builder WORKDIR /rollkit -# cache dependencies. -COPY ./go.mod . -COPY ./go.sum . -RUN go mod download - +# Copiar todo el código fuente primero COPY . . +# Ahora descargar las dependencias +RUN go mod download + RUN make install ## prep the final image. From 75efbc8927f344910f23d39aa5f60c6b67cbda7c Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Wed, 5 Mar 2025 17:47:03 +0100 Subject: [PATCH 22/24] add test coverage --- cmd/rollkit/commands/run_node_test.go | 148 ++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/cmd/rollkit/commands/run_node_test.go b/cmd/rollkit/commands/run_node_test.go index 84ea5059e7..cb4a8d5d14 100644 --- a/cmd/rollkit/commands/run_node_test.go +++ b/cmd/rollkit/commands/run_node_test.go @@ -3,8 +3,11 @@ package commands import ( "context" "errors" + "fmt" "net" "net/url" + "os" + "path/filepath" "reflect" "syscall" "testing" @@ -311,3 +314,148 @@ func TestStartMockSequencerServer(t *testing.T) { fn() } } + +func TestStartMockExecutorServerGRPC(t *testing.T) { + tests := []struct { + name string + execAddress string + expectedErr error + }{ + { + name: "Success", + execAddress: "localhost:50052", + expectedErr: nil, + }, + { + name: "Invalid URL", + execAddress: "://invalid", + expectedErr: &net.OpError{}, + }, + { + name: "Server Already Running", + execAddress: "localhost:50052", + expectedErr: errExecutorAlreadyRunning, + }, + } + + stopFns := []func(){} + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + srv, err := tryStartMockExecutorServerGRPC(tt.execAddress) + if srv != nil { + stopFns = append(stopFns, func() { + srv.Stop() + }) + } + + if tt.expectedErr != nil { + assert.Error(t, err) + assert.IsType(t, tt.expectedErr, err) + assert.Nil(t, srv) + } else { + assert.NoError(t, err) + assert.NotNil(t, srv) + } + }) + } + + for _, fn := range stopFns { + fn() + } +} + +func TestRollkitGenesisDocProviderFunc(t *testing.T) { + // Create a temporary directory for the test + tempDir, err := os.MkdirTemp("", "rollkit-test") + assert.NoError(t, err) + defer os.RemoveAll(tempDir) + + // Create the config directory + configDir := filepath.Join(tempDir, "config") + err = os.MkdirAll(configDir, 0755) + assert.NoError(t, err) + + // Create a simple test genesis file + testChainID := "test-chain-id" + genFileContent := fmt.Sprintf(`{ + "chain_id": "%s", + "genesis_time": "2023-01-01T00:00:00Z", + "consensus_params": { + "block": { + "max_bytes": "22020096", + "max_gas": "-1" + }, + "evidence": { + "max_age_num_blocks": "100000", + "max_age_duration": "172800000000000" + }, + "validator": { + "pub_key_types": ["ed25519"] + } + } + }`, testChainID) + + genFile := filepath.Join(configDir, "genesis.json") + err = os.WriteFile(genFile, []byte(genFileContent), 0644) + assert.NoError(t, err) + + // Create a test node config + testNodeConfig := rollconf.NodeConfig{ + RootDir: tempDir, + } + + // Get the genesis doc provider function + genDocProvider := RollkitGenesisDocProviderFunc(testNodeConfig) + assert.NotNil(t, genDocProvider) + + // Call the provider function and verify the result + loadedGenDoc, err := genDocProvider() + assert.NoError(t, err) + assert.NotNil(t, loadedGenDoc) + assert.Equal(t, testChainID, loadedGenDoc.ChainID) +} + +func TestInitFiles(t *testing.T) { + // Save the original nodeConfig + origNodeConfig := nodeConfig + + // Create a temporary directory for the test + tempDir, err := os.MkdirTemp("", "rollkit-test") + assert.NoError(t, err) + defer os.RemoveAll(tempDir) + + // Create the necessary subdirectories + configDir := filepath.Join(tempDir, "config") + dataDir := filepath.Join(tempDir, "data") + err = os.MkdirAll(configDir, 0755) + assert.NoError(t, err) + err = os.MkdirAll(dataDir, 0755) + assert.NoError(t, err) + + // Set the nodeConfig to use the temporary directory + nodeConfig = rollconf.NodeConfig{ + RootDir: tempDir, + } + + // Restore the original nodeConfig when the test completes + defer func() { + nodeConfig = origNodeConfig + }() + + // Call initFiles + err = initFiles() + assert.NoError(t, err) + + // Verify that the expected files were created + files := []string{ + filepath.Join(tempDir, "config", "priv_validator_key.json"), + filepath.Join(tempDir, "data", "priv_validator_state.json"), + filepath.Join(tempDir, "config", "node_key.json"), + filepath.Join(tempDir, "config", "genesis.json"), + } + + for _, file := range files { + assert.FileExists(t, file) + } +} From 7e1b2b96b3f5b3a9a0380700294aee3c797b8095 Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Wed, 5 Mar 2025 17:53:10 +0100 Subject: [PATCH 23/24] fix lint errors --- cmd/rollkit/commands/run_node_test.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/rollkit/commands/run_node_test.go b/cmd/rollkit/commands/run_node_test.go index cb4a8d5d14..2a36b24e55 100644 --- a/cmd/rollkit/commands/run_node_test.go +++ b/cmd/rollkit/commands/run_node_test.go @@ -369,11 +369,14 @@ func TestRollkitGenesisDocProviderFunc(t *testing.T) { // Create a temporary directory for the test tempDir, err := os.MkdirTemp("", "rollkit-test") assert.NoError(t, err) - defer os.RemoveAll(tempDir) + defer func() { + err := os.RemoveAll(tempDir) + assert.NoError(t, err) + }() // Create the config directory configDir := filepath.Join(tempDir, "config") - err = os.MkdirAll(configDir, 0755) + err = os.MkdirAll(configDir, 0750) assert.NoError(t, err) // Create a simple test genesis file @@ -397,7 +400,7 @@ func TestRollkitGenesisDocProviderFunc(t *testing.T) { }`, testChainID) genFile := filepath.Join(configDir, "genesis.json") - err = os.WriteFile(genFile, []byte(genFileContent), 0644) + err = os.WriteFile(genFile, []byte(genFileContent), 0600) assert.NoError(t, err) // Create a test node config @@ -423,14 +426,17 @@ func TestInitFiles(t *testing.T) { // Create a temporary directory for the test tempDir, err := os.MkdirTemp("", "rollkit-test") assert.NoError(t, err) - defer os.RemoveAll(tempDir) + defer func() { + err := os.RemoveAll(tempDir) + assert.NoError(t, err) + }() // Create the necessary subdirectories configDir := filepath.Join(tempDir, "config") dataDir := filepath.Join(tempDir, "data") - err = os.MkdirAll(configDir, 0755) + err = os.MkdirAll(configDir, 0750) assert.NoError(t, err) - err = os.MkdirAll(dataDir, 0755) + err = os.MkdirAll(dataDir, 0750) assert.NoError(t, err) // Set the nodeConfig to use the temporary directory From 6319f6e7b07d05de16282b039f09479cbce2548d Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Wed, 5 Mar 2025 17:54:47 +0100 Subject: [PATCH 24/24] remove old comment --- cmd/rollkit/commands/run_node.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/rollkit/commands/run_node.go b/cmd/rollkit/commands/run_node.go index 5daebed00c..2b560102df 100644 --- a/cmd/rollkit/commands/run_node.go +++ b/cmd/rollkit/commands/run_node.go @@ -308,7 +308,6 @@ func addNodeFlags(cmd *cobra.Command) { // Add cometBFT flags cmtcmd.AddNodeFlags(cmd) - // nodeConfig does not have a ABCI field, so we use a default value cmd.Flags().Bool("ci", false, "run node for ci testing") // Add Rollkit flags