Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(services): set default chain-id in client.toml (backport #4183) #4186

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- [#4183](https://github.com/ignite/cli/pull/4183) Set `chain-id` in the client.toml

### Changes

- [#4149](https://github.com/ignite/cli/pull/4149) Bump cometbft to `v0.38.7`
Expand Down
2 changes: 1 addition & 1 deletion ignite/services/chain/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (c *Chain) InitChain(ctx context.Context, initConfiguration, initGenesis bo

// ovewrite app config files with the values defined in Ignite's config file
if initConfiguration {
if err := c.Configure(home, conf); err != nil {
if err := c.Configure(home, chainID, conf); err != nil {
return err
}
}
Expand Down
25 changes: 13 additions & 12 deletions ignite/services/chain/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ func (c Chain) Start(ctx context.Context, runner chaincmdrunner.Runner, cfg *cha
}

// Configure sets the runtime configurations files for a chain (app.toml, client.toml, config.toml).
func (c Chain) Configure(homePath string, cfg *chainconfig.Config) error {
if err := c.appTOML(homePath, cfg); err != nil {
func (c Chain) Configure(homePath, chainID string, cfg *chainconfig.Config) error {
if err := appTOML(homePath, cfg); err != nil {
return err
}
if err := c.clientTOML(homePath, cfg); err != nil {
if err := clientTOML(homePath, chainID, cfg); err != nil {
return err
}
return c.configTOML(homePath, cfg)
return configTOML(homePath, cfg)
}

func (c Chain) appTOML(homePath string, cfg *chainconfig.Config) error {
func appTOML(homePath string, cfg *chainconfig.Config) error {
validator, err := chainconfig.FirstValidator(cfg)
if err != nil {
return err
Expand Down Expand Up @@ -117,7 +117,7 @@ func (c Chain) appTOML(homePath string, cfg *chainconfig.Config) error {
return err
}

func (c Chain) configTOML(homePath string, cfg *chainconfig.Config) error {
func configTOML(homePath string, cfg *chainconfig.Config) error {
validator, err := chainconfig.FirstValidator(cfg)
if err != nil {
return err
Expand Down Expand Up @@ -170,14 +170,14 @@ func (c Chain) configTOML(homePath string, cfg *chainconfig.Config) error {
return err
}

func (c Chain) clientTOML(homePath string, cfg *chainconfig.Config) error {
func clientTOML(homePath, chainID string, cfg *chainconfig.Config) error {
validator, err := chainconfig.FirstValidator(cfg)
if err != nil {
return err
}

path := filepath.Join(homePath, "config/client.toml")
tmConfig, err := toml.LoadFile(path)
clientConfig, err := toml.LoadFile(path)
if os.IsNotExist(err) {
return nil
}
Expand All @@ -187,11 +187,12 @@ func (c Chain) clientTOML(homePath string, cfg *chainconfig.Config) error {
}

// Set default config values
tmConfig.Set("keyring-backend", "test")
tmConfig.Set("broadcast-mode", "sync")
clientConfig.Set("chain-id", chainID)
clientConfig.Set("keyring-backend", "test")
clientConfig.Set("broadcast-mode", "sync")

// Update config values with the validator's client config
if err := updateTomlTreeValues(tmConfig, validator.Client); err != nil {
if err := updateTomlTreeValues(clientConfig, validator.Client); err != nil {
return err
}

Expand All @@ -201,7 +202,7 @@ func (c Chain) clientTOML(homePath string, cfg *chainconfig.Config) error {
}
defer file.Close()

_, err = tmConfig.WriteTo(file)
_, err = clientConfig.WriteTo(file)
return err
}

Expand Down
Loading