diff --git a/gno.land/cmd/gnoland/config_get_test.go b/gno.land/cmd/gnoland/config_get_test.go index 940842516d0..e8c27045205 100644 --- a/gno.land/cmd/gnoland/config_get_test.go +++ b/gno.land/cmd/gnoland/config_get_test.go @@ -129,13 +129,6 @@ func TestConfig_Get_Base(t *testing.T) { assert.Equal(t, loadedCfg.DBPath, value) }, }, - { - "genesis path fetched", - "genesis_file", - func(loadedCfg *config.Config, value string) { - assert.Equal(t, loadedCfg.Genesis, value) - }, - }, { "validator key fetched", "priv_validator_key_file", diff --git a/gno.land/cmd/gnoland/config_set_test.go b/gno.land/cmd/gnoland/config_set_test.go index 87cfbfdfc4a..b0898194d64 100644 --- a/gno.land/cmd/gnoland/config_set_test.go +++ b/gno.land/cmd/gnoland/config_set_test.go @@ -184,16 +184,6 @@ func TestConfig_Set_Base(t *testing.T) { assert.Equal(t, value, loadedCfg.DBPath) }, }, - { - "genesis path updated", - []string{ - "genesis_file", - "example path", - }, - func(loadedCfg *config.Config, value string) { - assert.Equal(t, value, loadedCfg.Genesis) - }, - }, { "validator key updated", []string{ diff --git a/gno.land/cmd/gnoland/start.go b/gno.land/cmd/gnoland/start.go index 41f4e7c2f44..0cbbc6cb36d 100644 --- a/gno.land/cmd/gnoland/start.go +++ b/gno.land/cmd/gnoland/start.go @@ -43,6 +43,7 @@ type startCfg struct { skipStart bool genesisBalancesFile string genesisTxsFile string + genesisFile string chainID string genesisRemote string dataDir string @@ -106,6 +107,13 @@ func (c *startCfg) RegisterFlags(fs *flag.FlagSet) { "initial txs to replay", ) + fs.StringVar( + &c.genesisFile, + "genesis", + "genesis.json", + "the path to the genesis.json", + ) + fs.StringVar( &c.chainID, "chainid", @@ -200,6 +208,12 @@ func execStart(c *startCfg, io commands.IO) error { return fmt.Errorf("unable to get absolute path for data directory, %w", err) } + // Get the absolute path to the node's genesis.json + genesisPath, err := filepath.Abs(c.genesisFile) + if err != nil { + return fmt.Errorf("unable to get absolute path for the genesis.json, %w", err) + } + var ( cfg *config.Config loadCfgErr error @@ -241,11 +255,9 @@ func execStart(c *startCfg, io commands.IO) error { logger := log.ZapLoggerToSlog(zapLogger) // Write genesis file if missing. - // NOTE: this will be dropped in a PR that resolves issue #1883: - // https://github.com/gnolang/gno/issues/1883 - genesisFilePath := filepath.Join(nodeDir, "../", "genesis.json") - - if !osm.FileExists(genesisFilePath) { + // NOTE: this will be dropped in a PR that resolves issue #1886: + // https://github.com/gnolang/gno/issues/1886 + if !osm.FileExists(genesisPath) { // Create priv validator first. // Need it to generate genesis.json newPrivValKey := cfg.PrivValidatorKeyFile() @@ -254,7 +266,7 @@ func execStart(c *startCfg, io commands.IO) error { pk := priv.GetPubKey() // Generate genesis.json file - if err := generateGenesisFile(genesisFilePath, pk, c); err != nil { + if err := generateGenesisFile(genesisPath, pk, c); err != nil { return fmt.Errorf("unable to generate genesis file: %w", err) } } @@ -277,7 +289,7 @@ func execStart(c *startCfg, io commands.IO) error { io.Println(startGraphic) } - gnoNode, err := node.DefaultNewNode(cfg, genesisFilePath, logger) + gnoNode, err := node.DefaultNewNode(cfg, genesisPath, logger) if err != nil { return fmt.Errorf("error in creating node: %w", err) } diff --git a/gno.land/cmd/gnoland/start_test.go b/gno.land/cmd/gnoland/start_test.go index 2f266d8a879..cdec6de0f99 100644 --- a/gno.land/cmd/gnoland/start_test.go +++ b/gno.land/cmd/gnoland/start_test.go @@ -3,6 +3,7 @@ package main import ( "bytes" "context" + "path/filepath" "testing" "time" @@ -14,15 +15,24 @@ import ( func TestStartInitialize(t *testing.T) { t.Parallel() + // NOTE: cannot be txtar tests as they use their own parsing for the + // "gnoland" command line. See pkg/integration. + var ( - nodeDir = t.TempDir() + nodeDir = t.TempDir() + genesisFile = filepath.Join(nodeDir, "test_genesis.json") args = []string{ "start", "--skip-start", "--skip-failing-genesis-txs", + + // These two flags are tested together as they would otherwise + // pollute this directory (cmd/gnoland) if not set. "--data-dir", nodeDir, + "--genesis", + genesisFile, } ) @@ -42,4 +52,5 @@ func TestStartInitialize(t *testing.T) { // Make sure the directory is created assert.DirExists(t, nodeDir) + assert.FileExists(t, genesisFile) } diff --git a/tm2/pkg/bft/config/config.go b/tm2/pkg/bft/config/config.go index 8668dde5003..117ce36e96b 100644 --- a/tm2/pkg/bft/config/config.go +++ b/tm2/pkg/bft/config/config.go @@ -22,7 +22,6 @@ var ( errInvalidMoniker = errors.New("moniker not set") errInvalidDBBackend = errors.New("invalid DB backend") errInvalidDBPath = errors.New("invalid DB path") - errInvalidGenesisPath = errors.New("invalid genesis path") errInvalidPrivValidatorKeyPath = errors.New("invalid private validator key path") errInvalidPrivValidatorStatePath = errors.New("invalid private validator state file path") errInvalidABCIMechanism = errors.New("invalid ABCI mechanism") @@ -205,7 +204,6 @@ var ( defaultSecretsDir = "secrets" defaultConfigFileName = "config.toml" - defaultGenesisJSONName = "genesis.json" defaultNodeKeyName = "node_key.json" defaultPrivValKeyName = "priv_validator_key.json" defaultPrivValStateName = "priv_validator_state.json" @@ -271,9 +269,6 @@ type BaseConfig struct { // Database directory DBPath string `toml:"db_dir" comment:"Database directory"` - // Path to the JSON file containing the initial validator set and other meta data - Genesis string `toml:"genesis_file" comment:"Path to the JSON file containing the initial validator set and other meta data"` - // Path to the JSON file containing the private key to use as a validator in the consensus protocol PrivValidatorKey string `toml:"priv_validator_key_file" comment:"Path to the JSON file containing the private key to use as a validator in the consensus protocol"` @@ -301,7 +296,6 @@ type BaseConfig struct { // DefaultBaseConfig returns a default base configuration for a Tendermint node func DefaultBaseConfig() BaseConfig { return BaseConfig{ - Genesis: defaultGenesisJSONName, PrivValidatorKey: defaultPrivValKeyPath, PrivValidatorState: defaultPrivValStatePath, NodeKey: defaultNodeKeyPath, @@ -382,11 +376,6 @@ func (cfg BaseConfig) ValidateBasic() error { return errInvalidDBPath } - // Verify the genesis path is set - if cfg.Genesis == "" { - return errInvalidGenesisPath - } - // Verify the validator private key path is set if cfg.PrivValidatorKey == "" { return errInvalidPrivValidatorKeyPath diff --git a/tm2/pkg/bft/config/config_test.go b/tm2/pkg/bft/config/config_test.go index e1e439ac9c0..541b5591985 100644 --- a/tm2/pkg/bft/config/config_test.go +++ b/tm2/pkg/bft/config/config_test.go @@ -128,15 +128,6 @@ func TestConfig_ValidateBaseConfig(t *testing.T) { assert.ErrorIs(t, c.BaseConfig.ValidateBasic(), errInvalidDBPath) }) - t.Run("genesis path not set", func(t *testing.T) { - t.Parallel() - - c := DefaultConfig() - c.Genesis = "" - - assert.ErrorIs(t, c.BaseConfig.ValidateBasic(), errInvalidGenesisPath) - }) - t.Run("priv validator key path not set", func(t *testing.T) { t.Parallel() diff --git a/tm2/pkg/bft/config/toml.go b/tm2/pkg/bft/config/toml.go index 474fce0e8a3..5d8589394a0 100644 --- a/tm2/pkg/bft/config/toml.go +++ b/tm2/pkg/bft/config/toml.go @@ -81,7 +81,11 @@ func ResetTestRoot(testName string) (*Config, string) { baseConfig := DefaultBaseConfig() configFilePath := filepath.Join(rootDir, defaultConfigPath) - genesisFilePath := filepath.Join(rootDir, defaultGenesisJSONName) + // NOTE: this does not match the behaviour of the Gno.land node. + // However, many tests rely on the fact that they can cleanup the directory + // by doing RemoveAll on the rootDir; so to keep compatibility with that + // behaviour, we place genesis.json in the rootDir. + genesisFilePath := filepath.Join(rootDir, "genesis.json") privKeyFilePath := filepath.Join(rootDir, baseConfig.PrivValidatorKey) privStateFilePath := filepath.Join(rootDir, baseConfig.PrivValidatorState) diff --git a/tm2/pkg/bft/config/toml_test.go b/tm2/pkg/bft/config/toml_test.go index 53dea1f2dfe..3520bcebc9f 100644 --- a/tm2/pkg/bft/config/toml_test.go +++ b/tm2/pkg/bft/config/toml_test.go @@ -68,8 +68,8 @@ func TestEnsureTestRoot(t *testing.T) { ensureFiles( t, rootDir, + "genesis.json", DefaultDBDir, - baseConfig.Genesis, baseConfig.PrivValidatorKey, baseConfig.PrivValidatorState, ) @@ -93,7 +93,6 @@ func checkConfig(configFile string) bool { "wal", "propose", "max", - "genesis", } for _, e := range elems { if !strings.Contains(configFile, e) { diff --git a/tm2/pkg/bft/consensus/replay_file.go b/tm2/pkg/bft/consensus/replay_file.go index 03ddb2d2722..701c2893053 100644 --- a/tm2/pkg/bft/consensus/replay_file.go +++ b/tm2/pkg/bft/consensus/replay_file.go @@ -249,5 +249,3 @@ func (pb *playback) replayConsoleLoop() int { } } } - -// -------------------------------------------------------------------------------- diff --git a/tm2/pkg/bft/rpc/test/helpers.go b/tm2/pkg/bft/rpc/test/helpers.go index 39078eaaf7f..d934cf27a64 100644 --- a/tm2/pkg/bft/rpc/test/helpers.go +++ b/tm2/pkg/bft/rpc/test/helpers.go @@ -92,7 +92,7 @@ func StartTendermint(app abci.Application, opts ...func(*Options)) *nm.Node { for _, opt := range opts { opt(&nodeOpts) } - node := NewTendermint(app, &nodeOpts) + node := newTendermint(app, &nodeOpts) err := node.Start() if err != nil { panic(err) @@ -112,8 +112,8 @@ func StopTendermint(node *nm.Node) { os.RemoveAll(node.Config().RootDir) } -// NewTendermint creates a new tendermint server and sleeps forever -func NewTendermint(app abci.Application, opts *Options) *nm.Node { +// newTendermint creates a new tendermint server and sleeps forever +func newTendermint(app abci.Application, opts *Options) *nm.Node { // Create & start node config, genesisFile := GetConfig(opts.recreateConfig) diff --git a/tm2/pkg/bft/store/store_test.go b/tm2/pkg/bft/store/store_test.go index 6ea85592ac9..2e634681ecc 100644 --- a/tm2/pkg/bft/store/store_test.go +++ b/tm2/pkg/bft/store/store_test.go @@ -45,7 +45,7 @@ func makeBlock(height int64, state sm.State, lastCommit *types.Commit) *types.Bl return block } -func makeStateAndBlockStore(logger *slog.Logger) (sm.State, *BlockStore, cleanupFunc) { +func makeStateAndBlockStore(_ *slog.Logger) (sm.State, *BlockStore, cleanupFunc) { config, genesisFile := cfg.ResetTestRoot("blockchain_reactor_test") // blockDB := dbm.NewDebugDB("blockDB", memdb.NewMemDB()) // stateDB := dbm.NewDebugDB("stateDB", memdb.NewMemDB())