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: specify staking bond_denom when creating a new chain #9776

Merged
merged 32 commits into from Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
525b2d5
return MaxUint64 for Limit on InfiniteGasMeter and add a func to retu…
likhita-809 Jul 8, 2021
188851d
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk
likhita-809 Jul 9, 2021
4ebb8b7
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk
likhita-809 Jul 12, 2021
2ebdadd
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk
likhita-809 Jul 13, 2021
90c3f5c
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk
likhita-809 Jul 19, 2021
2ceb46d
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk
likhita-809 Jul 20, 2021
7474885
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk
likhita-809 Jul 23, 2021
b3d6b13
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk
likhita-809 Jul 26, 2021
6a80511
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk
likhita-809 Jul 26, 2021
e8addcb
add stakingBondDenom flag to init chain command
likhita-809 Jul 26, 2021
76a0de4
add changelog
likhita-809 Jul 26, 2021
984f36a
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Jul 27, 2021
fef4eb3
add tests for stakingBondDenom
likhita-809 Jul 27, 2021
50dc706
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Jul 27, 2021
8d66eb6
address review comments
likhita-809 Jul 27, 2021
28194b9
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Jul 27, 2021
b5c7560
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Jul 28, 2021
0d894c9
use tendermint json pkg for serializing data
likhita-809 Jul 28, 2021
370f510
fix something
likhita-809 Jul 28, 2021
3f26886
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Jul 28, 2021
04a7c46
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Jul 28, 2021
3874e2b
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Jul 28, 2021
73e72fd
address review comments
likhita-809 Jul 28, 2021
4de1f77
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Jul 28, 2021
b54c086
address review comment
likhita-809 Jul 28, 2021
4df9b2b
address one more comment
likhita-809 Jul 28, 2021
9a041dc
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Jul 28, 2021
10f7a66
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Jul 29, 2021
21b712e
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Jul 29, 2021
2e8b63e
apply review suggestions
likhita-809 Jul 30, 2021
1929665
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into li…
likhita-809 Jul 30, 2021
e7821a1
check for error on unmarshalJSONO
likhita-809 Jul 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -70,6 +70,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### CLI Breaking Changes

* [\#9776](https://github.com/cosmos/cosmos-sdk/pull/9776) Add flag `staking-bond-denom` to specify the staking bond denomination value when initializing a new chain.
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
* [\#9246](https://github.com/cosmos/cosmos-sdk/pull/9246) Removed the CLI flag `--setup-config-only` from the `testnet` command and added the subcommand `init-files`.
* [\#9371](https://github.com/cosmos/cosmos-sdk/pull/9371) Non-zero default fees/Server will error if there's an empty value for min-gas-price in app.toml

Expand Down
53 changes: 50 additions & 3 deletions x/genutil/client/cli/init.go
Expand Up @@ -6,12 +6,13 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/cosmos/go-bip39"
"github.com/pkg/errors"
"github.com/spf13/cobra"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/cli"
tmjson "github.com/tendermint/tendermint/libs/json"
tmos "github.com/tendermint/tendermint/libs/os"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/types"
Expand All @@ -20,9 +21,12 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/genutil"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/go-bip39"
)

const (
Expand All @@ -31,6 +35,9 @@ const (

// FlagSeed defines a flag to initialize the private validator key from a specific seed.
FlagRecover = "recover"

// FlagStakingBondDenom defines a flag to specify the staking token in the genesis file.
FlagStakingBondDenom = "staking-bond-denom"
)

type printInfo struct {
Expand Down Expand Up @@ -114,12 +121,51 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command {
genFile := config.GenesisFile()
overwrite, _ := cmd.Flags().GetBool(FlagOverwrite)

stakingBondDenom, _ := cmd.Flags().GetString(FlagStakingBondDenom)

if !overwrite && tmos.FileExists(genFile) {
return fmt.Errorf("genesis.json file already exists: %v", genFile)
}
appState, err := json.MarshalIndent(mbm.DefaultGenesis(cdc), "", " ")

var stakingGenState map[string]json.RawMessage
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved

if stakingBondDenom != "" {
stakingGenState = mbm.DefaultGenesis(cdc)
stakingRaw := stakingGenState[stakingtypes.ModuleName]
var (
initialStakingData simapp.GenesisState
finalStakingdata simapp.GenesisState
)

if err := tmjson.Unmarshal(stakingRaw, &initialStakingData); err != nil {
return err
}

bz, err := tmjson.Marshal(initialStakingData)
if err != nil {
return err
}

stakingStr := string(bz)
modifiedStakingStr := strings.Replace(stakingStr, sdk.DefaultBondDenom, stakingBondDenom, 1)
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
stakingbytes := []byte(modifiedStakingStr)
err = tmjson.Unmarshal(stakingbytes, &finalStakingdata)
if err != nil {
return err
}
stakingResult, err := tmjson.Marshal(finalStakingdata)
likhita-809 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
stakingGenState[stakingtypes.ModuleName] = stakingResult

} else {
stakingGenState = mbm.DefaultGenesis(cdc)
}

appState, err := json.MarshalIndent(stakingGenState, "", " ")
if err != nil {
return errors.Wrap(err, "Failed to marshall default genesis state")
return errors.Wrap(err, "Failed to marshal default genesis state")
}

genDoc := &types.GenesisDoc{}
Expand Down Expand Up @@ -152,6 +198,7 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command {
cmd.Flags().BoolP(FlagOverwrite, "o", false, "overwrite the genesis.json file")
cmd.Flags().Bool(FlagRecover, false, "provide seed phrase to recover existing key instead of creating")
cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")
cmd.Flags().String(FlagStakingBondDenom, "", "genesis file staking bond denomination, if left blank default value is 'stake'")

return cmd
}
24 changes: 24 additions & 0 deletions x/genutil/client/cli/init_test.go
Expand Up @@ -118,6 +118,30 @@ func TestInitRecover(t *testing.T) {
require.NoError(t, cmd.ExecuteContext(ctx))
}

func TestInitStakingBondDenom(t *testing.T) {
home := t.TempDir()
logger := log.NewNopLogger()
cfg, err := genutiltest.CreateDefaultTendermintConfig(home)
require.NoError(t, err)

serverCtx := server.NewContext(viper.New(), cfg, logger)
interfaceRegistry := types.NewInterfaceRegistry()
marshaler := codec.NewProtoCodec(interfaceRegistry)
clientCtx := client.Context{}.
WithCodec(marshaler).
WithLegacyAmino(makeCodec()).
WithHomeDir(home)

ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
ctx = context.WithValue(ctx, server.ServerContextKey, serverCtx)

cmd := genutilcli.InitCmd(testMbm, home)

cmd.SetArgs([]string{"appnode-test", fmt.Sprintf("--%s=%s --%s=testtoken", cli.HomeFlag, home, genutilcli.FlagStakingBondDenom)})
require.NoError(t, cmd.ExecuteContext(ctx))
}

func TestEmptyState(t *testing.T) {
home := t.TempDir()
logger := log.NewNopLogger()
Expand Down