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

WIP: Remove AppInit, other cleanup #2675

Closed
Closed
Show file tree
Hide file tree
Changes from 3 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
9 changes: 0 additions & 9 deletions cmd/gaia/app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strings"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
Expand Down Expand Up @@ -81,14 +80,6 @@ func (ga *GenesisAccount) ToAccount() (acc *auth.BaseAccount) {
}
}

// get app init parameters for server init command
func GaiaAppInit() server.AppInit {

return server.AppInit{
AppGenState: GaiaAppGenStateJSON,
}
}

// Create the core parameters for genesis initialization for gaia
// note that the pubkey input is this machines pubkey
func GaiaAppGenState(cdc *codec.Codec, genDoc tmtypes.GenesisDoc, appGenTxs []json.RawMessage) (
Expand Down
8 changes: 3 additions & 5 deletions cmd/gaia/cmd/gaiad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ func main() {
Short: "Gaia Daemon (server)",
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
}
appInit := app.GaiaAppInit()
rootCmd.AddCommand(gaiaInit.InitCmd(ctx, cdc, appInit))
rootCmd.AddCommand(gaiaInit.InitCmd(ctx, cdc))
rootCmd.AddCommand(gaiaInit.CollectGenTxsCmd(ctx, cdc))
rootCmd.AddCommand(gaiaInit.TestnetFilesCmd(ctx, cdc, server.AppInit{}))
rootCmd.AddCommand(gaiaInit.TestnetFilesCmd(ctx, cdc))
rootCmd.AddCommand(gaiaInit.GenTxCmd(ctx, cdc))

server.AddCommands(ctx, cdc, rootCmd, appInit,
newApp, exportAppStateAndTMValidators)
server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators)

// prepare and add flags
executor := cli.PrepareBaseCmd(rootCmd, "GA", app.DefaultNodeHome)
Expand Down
4 changes: 2 additions & 2 deletions cmd/gaia/init/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func CollectGenTxsCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
return err
}

toPrint.AppMessage = appMessage
toPrint.Message = appMessage
// print out some key information
return displayInfo(cdc, toPrint)
},
Expand Down Expand Up @@ -105,7 +105,7 @@ func genAppStateFromConfig(cdc *codec.Codec, config *cfg.Config, initCfg initCon
return
}

err = WriteGenesisFile(genFile, initCfg.ChainID, nil, appState)
err = server.WriteGenesisFile(genFile, initCfg.ChainID, nil, appState)
return
}

Expand Down
54 changes: 11 additions & 43 deletions cmd/gaia/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package init
import (
"encoding/json"
"fmt"
"github.com/tendermint/tendermint/privval"
"os"
"path/filepath"

Expand All @@ -18,7 +17,6 @@ import (
"github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types"
)

const (
Expand All @@ -28,10 +26,10 @@ const (
)

type printInfo struct {
Moniker string `json:"moniker"`
ChainID string `json:"chain_id"`
NodeID string `json:"node_id"`
AppMessage json.RawMessage `json:"app_message"`
Moniker string `json:"moniker"`
ChainID string `json:"chain_id"`
NodeID string `json:"node_id"`
Message json.RawMessage `json:"message"`
}

// nolint: errcheck
Expand All @@ -46,7 +44,7 @@ func displayInfo(cdc *codec.Codec, info printInfo) error {

// get cmd to initialize all files for tendermint and application
// nolint
func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cobra.Command {
func InitCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "init",
Short: "Initialize private validator, p2p, genesis, and application configuration files",
Expand Down Expand Up @@ -74,15 +72,15 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cob
viper.GetBool(flagOverwrite)); err != nil {
return err
}
if err = WriteGenesisFile(genFile, chainID, nil, appState); err != nil {
if err = server.WriteGenesisFile(genFile, chainID, nil, appState); err != nil {
return err
}

toPrint := printInfo{
ChainID: chainID,
Moniker: config.Moniker,
NodeID: nodeID,
AppMessage: appState,
ChainID: chainID,
Moniker: config.Moniker,
NodeID: nodeID,
Message: appState,
}

cfg.WriteConfigFile(filepath.Join(config.RootDir, "config", "config.toml"), config)
Expand All @@ -105,40 +103,10 @@ func InitializeNodeValidatorFiles(config *cfg.Config) (nodeID string, valPubKey
return
}
nodeID = string(nodeKey.ID())
valPubKey = ReadOrCreatePrivValidator(config.PrivValidatorFile())
valPubKey = server.ReadOrCreatePrivValidator(config.PrivValidatorFile())
return
}

// WriteGenesisFile creates and writes the genesis configuration to disk. An
// error is returned if building or writing the configuration to file fails.
// nolint: unparam
func WriteGenesisFile(genesisFile, chainID string, validators []types.GenesisValidator, appState json.RawMessage) error {
genDoc := types.GenesisDoc{
ChainID: chainID,
Validators: validators,
AppState: appState,
}

if err := genDoc.ValidateAndComplete(); err != nil {
return err
}

return genDoc.SaveAs(genesisFile)
}

// read of create the private key file for this config
func ReadOrCreatePrivValidator(privValFile string) crypto.PubKey {
// private validator
var privValidator *privval.FilePV
if common.FileExists(privValFile) {
privValidator = privval.LoadFilePV(privValFile)
} else {
privValidator = privval.GenFilePV(privValFile)
privValidator.Save()
}
return privValidator.GetPubKey()
}

func initializeEmptyGenesis(cdc *codec.Codec, genFile string, chainID string,
overwrite bool) (appState json.RawMessage, err error) {
if !overwrite && common.FileExists(genFile) {
Expand Down
15 changes: 3 additions & 12 deletions cmd/gaia/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ func TestInitCmd(t *testing.T) {
require.Nil(t, err)
ctx := server.NewContext(cfg, logger)
cdc := app.MakeCodec()
appInit := server.AppInit{
AppGenState: mock.AppGenState,
}
cmd := InitCmd(ctx, cdc, appInit)
cmd := InitCmd(ctx, cdc)
err = cmd.RunE(nil, nil)
require.NoError(t, err)
}
Expand All @@ -58,10 +55,7 @@ func TestEmptyState(t *testing.T) {
require.Nil(t, err)
ctx := server.NewContext(cfg, logger)
cdc := app.MakeCodec()
appInit := server.AppInit{
AppGenState: mock.AppGenStateEmpty,
}
cmd := InitCmd(ctx, cdc, appInit)
cmd := InitCmd(ctx, cdc)
err = cmd.RunE(nil, nil)
require.NoError(t, err)

Expand Down Expand Up @@ -105,10 +99,7 @@ func TestStartStandAlone(t *testing.T) {
require.Nil(t, err)
ctx := server.NewContext(cfg, logger)
cdc := app.MakeCodec()
appInit := server.AppInit{
AppGenState: mock.AppGenState,
}
initCmd := InitCmd(ctx, cdc, appInit)
initCmd := InitCmd(ctx, cdc)
err = initCmd.RunE(nil, nil)
require.NoError(t, err)

Expand Down
5 changes: 2 additions & 3 deletions cmd/gaia/init/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ var (
const nodeDirPerm = 0755

// get cmd to initialize all files for tendermint testnet and application
func TestnetFilesCmd(ctx *server.Context, cdc *codec.Codec,
appInit server.AppInit) *cobra.Command {
func TestnetFilesCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {

cmd := &cobra.Command{
Use: "testnet",
Expand Down Expand Up @@ -137,7 +136,7 @@ func testnetWithConfig(config *cfg.Config, cdc *codec.Codec) error {
keyPass = app.DefaultKeyPass
}

addr, secret, err := server.GenerateSaveCoinKey(clientDir, nodeDirName, keyPass, true)
addr, secret, err := server.GenerateSaveAccountKeyAndSecret(clientDir, nodeDirName, keyPass, true)
if err != nil {
_ = os.RemoveAll(outDir)
return err
Expand Down
13 changes: 0 additions & 13 deletions docs/getting-started/join-testnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@ You can edit this `name` later, in the `~/.gaiad/config/config.toml` file:
moniker = "<your_custom_name>"
```

You can edit the `~/.gaiad/config/gaiad.toml` file in order to enable the anti spam mechanism and reject incoming transactions with less than a minimum fee:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we reintroduce this somewhere?


```
# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml

##### main base config options #####

# Validators reject any tx from the mempool with less than the minimum fee per gas.
minimum_fees = ""
```


Your full node has been initialized! Please skip to [Genesis & Seeds](#genesis-seeds).

## Upgrading From Previous Testnet
Expand Down
6 changes: 4 additions & 2 deletions docs/sdk/sdk-by-examples/simple-governance/bridging-it-all.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ To interact with our application, let us add the commands from the `simple_gover
The `simplegovd` command will run the daemon server as a background process. First, let us create some `utils` functions:

```go
// NOTE: This is outdated, AppInit has been removed.
// XXX: Update tutorial.
// cmd/simplegovd/main.go
// SimpleGovAppInit initial parameters
var SimpleGovAppInit = server.AppInit{
Expand Down Expand Up @@ -137,7 +139,7 @@ func main() {
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
}

server.AddCommands(ctx, cdc, rootCmd, SimpleGovAppInit,
server.AddCommands(ctx, cdc, rootCmd,
server.ConstructAppCreator(newApp, "simplegov"),
server.ConstructAppExporter(exportAppState, "simplegov"))

Expand Down Expand Up @@ -253,4 +255,4 @@ func MakeCodec() *codec.Codec {
cdc.RegisterConcrete(&types.AppAccount{}, "simpleGov/Account", nil)
return cdc
}
```
```
47 changes: 25 additions & 22 deletions examples/basecoin/cmd/basecoind/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/tendermint/tendermint/p2p"

"github.com/cosmos/cosmos-sdk/baseapp"
gaiaInit "github.com/cosmos/cosmos-sdk/cmd/gaia/init"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/examples/basecoin/app"
Expand Down Expand Up @@ -39,10 +37,9 @@ func main() {
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
}

appInit := server.DefaultAppInit
rootCmd.AddCommand(InitCmd(ctx, cdc, appInit))
rootCmd.AddCommand(InitCmd(ctx, cdc))

server.AddCommands(ctx, cdc, rootCmd, appInit,
server.AddCommands(ctx, cdc, rootCmd,
newApp, exportAppStateAndTMValidators)

// prepare and add flags
Expand All @@ -58,7 +55,7 @@ func main() {

// get cmd to initialize all files for tendermint and application
// nolint: errcheck
func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cobra.Command {
func InitCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "init",
Short: "Initialize genesis config, priv-validator file, and p2p-node file",
Expand All @@ -78,38 +75,44 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cob
}
nodeID := string(nodeKey.ID())

pk := gaiaInit.ReadOrCreatePrivValidator(config.PrivValidatorFile())
genTx, appMessage, validator, err := server.SimpleAppGenTx(cdc, pk)
if err != nil {
return err
pk := server.ReadOrCreatePrivValidator(config.PrivValidatorFile())
validator := tmtypes.GenesisValidator{
PubKey: pk,
Power: 10,
}

appState, err := appInit.AppGenState(
cdc, tmtypes.GenesisDoc{}, []json.RawMessage{genTx})
if err != nil {
return err
}
appStateJSON, err := cdc.MarshalJSON(appState)
addr, secret, err := server.GenerateAccountKeyAndSecret()
if err != nil {
return err
}
appStateJSON := (fmt.Sprintf(`{
"accounts": [{
"address": "%s",
"coins": [
{
"denom": "mycoin",
"amount": "9007199254740992"
}
]
}]
}`, addr))

toPrint := struct {
ChainID string `json:"chain_id"`
NodeID string `json:"node_id"`
AppMessage json.RawMessage `json:"app_message"`
ChainID string `json:"chain_id"`
NodeID string `json:"node_id"`
Message string `json:"message"`
}{
chainID,
nodeID,
appMessage,
fmt.Sprintf("Secret: %v", secret),
}
out, err := codec.MarshalJSONIndent(cdc, toPrint)
if err != nil {
return err
}
fmt.Fprintf(os.Stderr, "%s\n", string(out))
return gaiaInit.WriteGenesisFile(config.GenesisFile(), chainID,
[]tmtypes.GenesisValidator{validator}, appStateJSON)
return server.WriteGenesisFile(config.GenesisFile(), chainID,
[]tmtypes.GenesisValidator{validator}, []byte(appStateJSON))
},
}

Expand Down
Loading