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: create config fix tool #14342

Merged
merged 32 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
bc015b1
feat: create config fix tool
julienrbrt Dec 16, 2022
3760019
Merge branch 'main' into julien/config-fix
julienrbrt Jan 2, 2023
d3909d9
wip
julienrbrt Jan 4, 2023
6822b81
updates
julienrbrt Jan 4, 2023
fbe2f40
wip
julienrbrt Jan 4, 2023
b0fcfa9
Merge branch 'main' into julien/config-fix
julienrbrt Jan 4, 2023
52325e9
updates
julienrbrt Jan 5, 2023
c4130ff
update changelog
julienrbrt Jan 5, 2023
5588b8f
Merge branch 'main' into julien/config-fix
julienrbrt Jan 5, 2023
61924ff
add tests and diff command
julienrbrt Jan 5, 2023
34388a6
updates
julienrbrt Jan 5, 2023
81a8f52
renaming
julienrbrt Jan 5, 2023
25d24fc
updates
julienrbrt Jan 5, 2023
79eb103
wip
julienrbrt Jan 6, 2023
f2cabde
Merge branch 'main' into julien/config-fix
julienrbrt Jan 6, 2023
ee11e8b
naming
julienrbrt Jan 6, 2023
a98c4ee
store value in diff
julienrbrt Jan 6, 2023
77be207
finish migrate (only comments addition missing)
julienrbrt Jan 6, 2023
14210fa
Merge branch 'main' into julien/config-fix
julienrbrt Jan 8, 2023
1dfd460
add section comments
julienrbrt Jan 8, 2023
c425738
parse comments from diff
julienrbrt Jan 8, 2023
1643cc7
remove dep and imp tests
julienrbrt Jan 9, 2023
86fd670
Merge branch 'main' into julien/config-fix
julienrbrt Jan 9, 2023
598817d
chore: add docs
julienrbrt Jan 9, 2023
d6f21ca
fix tests
julienrbrt Jan 9, 2023
942ae4e
fix tests
julienrbrt Jan 9, 2023
de3794d
Merge branch 'main' into julien/config-fix
julienrbrt Jan 9, 2023
bda3028
Merge branch 'main' into julien/config-fix
julienrbrt Jan 9, 2023
a6bac20
use tagged version
julienrbrt Jan 9, 2023
a99937f
Merge branch 'main' into julien/config-fix
julienrbrt Jan 10, 2023
d87310d
go mod tidy all
julienrbrt Jan 10, 2023
4e19b7f
go mod tidy
julienrbrt Jan 10, 2023
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
2 changes: 2 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"C:Rosetta":
- contrib/rosetta/**/*
- tools/rosetta/**/*
"C:Confix":
- tools/confix/**/*
"C:Keys":
- client/keys/**/*
"Type: Build":
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,24 @@ jobs:
**/go.sum
**/Makefile
Makefile
###################
#### Build App ####
###################
- name: Build
if: env.GIT_DIFF
run: GOARCH=${{ matrix.go-arch }} LEDGER_ENABLED=false make build
- name: Build Legacy
if: env.GIT_DIFF
run: GOARCH=${{ matrix.go-arch }} LEDGER_ENABLED=false COSMOS_BUILD_OPTIONS=legacy make build
###################
## Build Tooling ##
###################
- name: Build Cosmovisor
if: env.GIT_DIFF
run: GOARCH=${{ matrix.go-arch }} LEDGER_ENABLED=false make cosmovisor
- name: Build Rosetta
if: env.GIT_DIFF
run: GOARCH=${{ matrix.go-arch }} LEDGER_ENABLED=false make rosetta
- name: Build Confix
if: env.GIT_DIFF
run: GOARCH=${{ matrix.go-arch }} LEDGER_ENABLED=false make confix
38 changes: 38 additions & 0 deletions .github/workflows/release-confix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Release Confix

on:
push:
tags:
- "tools/confix/v*.*.*"
permissions:
contents: read

jobs:
goreleaser:
permissions:
contents: write # for goreleaser/goreleaser-action to create a GitHub release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.19.4
# get 'v*.*.*' part from 'confix/v*.*.*' and save to $GITHUB_ENV
- name: Set env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/confix/}" >> $GITHUB_ENV
# remove the possible pre-existing same tag for cosmos-sdk related tags instead of confix tags
# Because goreleaser enforces semantic versioning and will error on non compliant tags.(https://goreleaser.com/limitations/semver/)
- name: Tag without prefix locally to avoid error in goreleaser
run: |-
git tag -d ${{ env.RELEASE_VERSION }} || echo "No such a tag exists before"
git tag ${{ env.RELEASE_VERSION }} HEAD
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
# stick to version v0.179.0(https://github.com/cosmos/cosmos-sdk/issues/11125)
version: v0.179.0
args: release --rm-dist --skip-validate --release-notes ./RELEASE_NOTES.md
workdir: tools/confix
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_CURRENT_TAG: confix/${{ env.RELEASE_VERSION }}
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -551,3 +551,33 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_COSMOVISOR }}
with:
projectBaseDir: tools/cosmovisor/

test-confix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.19.4
cache: true
cache-dependency-path: tools/confix/go.sum
- uses: technote-space/get-diff-action@v6.1.2
id: git_diff
with:
PATTERNS: |
tools/confix/**/*.go
tools/confix/go.mod
tools/confix/go.sum
- name: tests
if: env.GIT_DIFF
run: |
cd tools/confix
go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb_build' ./...
- name: sonarcloud
if: env.GIT_DIFF
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_CONFIX }}
with:
projectBaseDir: tools/confix/
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

* (client) [#14342](https://github.com/cosmos/cosmos-sdk/pull/14342) Add `simd config` command is now a sub-command, for setting, getting and migrating Cosmos SDK configuration files.
* (client) [#13867](https://github.com/cosmos/cosmos-sdk/pull/13867/) Wire AutoCLI commands with SimApp.
* (x/distribution) [#14322](https://github.com/cosmos/cosmos-sdk/pull/14322) Introduce a new gRPC message handler, `DepositValidatorRewardsPool`, that allows explicit funding of a validator's reward pool.
* (x/slashing, x/staking) [#14363](https://github.com/cosmos/cosmos-sdk/pull/14363) Add the infraction a validator committed type as an argument to a `SlashWithInfractionReason` keeper method.
Expand Down Expand Up @@ -116,7 +117,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Store pacakge no longer has a dependency on baseapp.
* (store) [#14438](https://github.com/cosmos/cosmos-sdk/pull/14438) Pass logger from baseapp to store.
* (store) [#14439](https://github.com/cosmos/cosmos-sdk/pull/14439) Remove global metric gatherer from store.
* By default store has a no op metric gatherer, the application developer must set another metric gatherer or us the provided one in `store/metrics`.
* By default store has a no op metric gatherer, the application developer must set another metric gatherer or us the provided one in `store/metrics`.

### State Machine Breaking

Expand Down Expand Up @@ -206,6 +207,7 @@ extension interfaces. `module.Manager.Modules` is now of type `map[string]interf

### CLI Breaking Changes

* (client) [#14342](https://github.com/cosmos/cosmos-sdk/pull/14342) `simd config` command is now a sub-command. Use `simd config --help` to learn more.
* (x/genutil) [#13535](https://github.com/cosmos/cosmos-sdk/pull/13535) Replace in `simd init`, the `--staking-bond-denom` flag with `--default-denom` which is used for all default denomination in the genesis, instead of only staking.
* (tx) [#12659](https://github.com/cosmos/cosmos-sdk/pull/12659) Remove broadcast mode `block`.
* (genesis) [#14149](https://github.com/cosmos/cosmos-sdk/pull/14149) Add `simd genesis` command, which contains all genesis-related sub-commands.
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ cosmovisor:
rosetta:
$(MAKE) -C tools/rosetta rosetta

.PHONY: build build-linux-amd64 build-linux-arm64 cosmovisor rosetta
confix:
$(MAKE) -C tools/confix confix

.PHONY: build build-linux-amd64 build-linux-arm64 cosmovisor rosetta confix


mocks: $(MOCKS_DIR)
Expand Down
97 changes: 0 additions & 97 deletions client/config/cmd.go

This file was deleted.

28 changes: 12 additions & 16 deletions client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (
"github.com/cosmos/cosmos-sdk/client"
)

// Default constants
const (
chainID = ""
keyringBackend = "os"
output = "text"
node = "tcp://localhost:26657"
broadcastMode = "sync"
)
func DefaultConfig() *ClientConfig {
return &ClientConfig{
ChainID: "",
KeyringBackend: "os",
Output: "text",
Node: "tcp://localhost:26657",
BroadcastMode: "sync",
}
}

type ClientConfig struct {
ChainID string `mapstructure:"chain-id" json:"chain-id"`
Expand All @@ -25,11 +26,6 @@ type ClientConfig struct {
BroadcastMode string `mapstructure:"broadcast-mode" json:"broadcast-mode"`
}

// defaultClientConfig returns the reference to ClientConfig with default values.
func defaultClientConfig() *ClientConfig {
return &ClientConfig{chainID, keyringBackend, output, node, broadcastMode}
}

func (c *ClientConfig) SetChainID(chainID string) {
c.ChainID = chainID
}
Expand All @@ -54,11 +50,11 @@ func (c *ClientConfig) SetBroadcastMode(broadcastMode string) {
func ReadFromClientConfig(ctx client.Context) (client.Context, error) {
configPath := filepath.Join(ctx.HomeDir, "config")
configFilePath := filepath.Join(configPath, "client.toml")
conf := defaultClientConfig()
conf := DefaultConfig()

// if config.toml file does not exist we create it and write default ClientConfig values into it.
// when config.toml does not exist create and init with default values
if _, err := os.Stat(configFilePath); os.IsNotExist(err) {
if err := ensureConfigPath(configPath); err != nil {
if err := os.MkdirAll(configPath, os.ModePerm); err != nil {
return ctx, fmt.Errorf("couldn't make client config: %v", err)
}

Expand Down
35 changes: 3 additions & 32 deletions client/config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package config_test

import (
"bytes"
"fmt"
"io"
"os"
"testing"

Expand All @@ -13,7 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/cosmos/cosmos-sdk/x/staking/client/cli"
stakingcli "github.com/cosmos/cosmos-sdk/x/staking/client/cli"
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -45,34 +43,7 @@ func initClientContext(t *testing.T, envVar string) (client.Context, func()) {
return clientCtx, func() { _ = os.RemoveAll(home) }
}

func TestConfigCmd(t *testing.T) {
clientCtx, cleanup := initClientContext(t, testNode1)
defer func() {
_ = os.Unsetenv(nodeEnv)
cleanup()
}()

// NODE=http://localhost:1 ./build/simd config node http://localhost:2
cmd := config.Cmd()
args := []string{"node", testNode2}
_, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
require.NoError(t, err)

// ./build/simd config node //http://localhost:1
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"node"})
require.NoError(t, cmd.Execute())
out, err := io.ReadAll(b)
require.NoError(t, err)
require.Equal(t, string(out), testNode1+"\n")
}

func TestConfigCmdEnvFlag(t *testing.T) {
const (
defaultNode = "http://localhost:26657"
)

tt := []struct {
name string
envVar string
Expand All @@ -81,7 +52,7 @@ func TestConfigCmdEnvFlag(t *testing.T) {
}{
{"env var is set with no flag", testNode1, []string{"validators"}, testNode1},
{"env var is set with a flag", testNode1, []string{"validators", fmt.Sprintf("--%s=%s", flags.FlagNode, testNode2)}, testNode2},
{"env var is not set with no flag", "", []string{"validators"}, defaultNode},
{"env var is not set with no flag", "", []string{"validators"}, "http://localhost:26657"},
{"env var is not set with a flag", "", []string{"validators", fmt.Sprintf("--%s=%s", flags.FlagNode, testNode2)}, testNode2},
}

Expand All @@ -103,7 +74,7 @@ func TestConfigCmdEnvFlag(t *testing.T) {

We dial http://localhost:2 cause a flag has the higher priority than env variable.
*/
cmd := cli.GetQueryCmd()
cmd := stakingcli.GetQueryCmd()
_, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
require.Error(t, err)
require.Contains(t, err.Error(), tc.expNode, "Output does not contain expected Node")
Expand Down
7 changes: 1 addition & 6 deletions client/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ func writeConfigToFile(configFilePath string, config *ClientConfig) error {
return os.WriteFile(configFilePath, buffer.Bytes(), 0o600)
}

// ensureConfigPath creates a directory configPath if it does not exist
func ensureConfigPath(configPath string) error {
return os.MkdirAll(configPath, os.ModePerm)
}

// getClientConfig reads values from client.toml file and unmarshalls them into ClientConfig
func getClientConfig(configPath string, v *viper.Viper) (*ClientConfig, error) {
v.AddConfigPath(configPath)
Expand All @@ -60,7 +55,7 @@ func getClientConfig(configPath string, v *viper.Viper) (*ClientConfig, error) {
return nil, err
}

conf := new(ClientConfig)
conf := DefaultConfig()
if err := v.Unmarshal(conf); err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ docs/docs/spec
docs/docs/architecture
docs/docs/tooling/01-cosmovisor.md
docs/docs/tooling/02-depinject.md
docs/docs/tooling/03-confix.md
docs/run-node/04-rosetta.md

# Misc
Expand Down
1 change: 1 addition & 0 deletions docs/docs/tooling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ This section provides documentation on various tooling used in development of a
* [Protocol Buffers](./00-protobuf.md)
* [Cosmovisor](./01-cosmovisor.md)
* [Depinject](./02-depinject.md)
* [Confix](./03-confix.md)
Loading