diff --git a/docs/staking/testnet.rst b/docs/staking/testnet.rst index 484ec3b5d..027146893 100644 --- a/docs/staking/testnet.rst +++ b/docs/staking/testnet.rst @@ -1,109 +1,33 @@ Testnet Setup ============= +**Note:** THIS DOCUMENT IS OUT OF DATE + See the `installation guide <../sdk/install.html>`__ for details on installation. Here is a quick example to get you off your feet: -First, generate a new key with a name, and save the address: +First, generate a couple of genesis transactions to be incorparated into the genesis file, this will create two keys with the password ``1234567890`` :: - MYNAME= - gaiacli keys new $MYNAME + gaiad init gen-tx --name=foo --home=$HOME/.gaiad1 + gaiad init gen-tx --name=bar --home=$HOME/.gaiad2 gaiacli keys list - MYADDR= - -Now initialize a gaia chain: +**Note:** If you've already run these tests you may need to overwrite keys using the ``--OWK`` flag +When you list the keys you should see two addresses, we'll need these later so take note. +Now let's actually create the genesis files for both nodes: :: - gaiad init --home=$HOME/.gaiad1 - -you should see seed phrase for genesis account in the output & config & data folder in the home directory. - -In the config folder, there will be the following files: ``config.toml``, ``genesis.json``, ``node_key.json``, and ``priv_validator.json``. - -The genesis file should look like this: - -:: - - { - "genesis_time": "0001-01-01T00:00:00Z", - "chain_id": "test-chain-0TRiTa", - "validators": [ - { - "pub_key": { - "type": "AC26791624DE60", - "value": "" - }, - "power": 10, - "name": "" - } - ], - "app_hash": "", - "app_state": { - "accounts": [ - { - "address": "", - "coins": [ - { - "denom": "steak", - "amount": 9007199254740992 - } - ] - } - ] - } - } - -**Note:** We need to change the denomination of token from default to ``steak`` in the genesis file. - -Then, recover the genesis account with ``gaiacli``: - -:: - - gaiacli keys add --recover - -By now, you have set up the first node. This is great! - -We can add a second node on our local machine by initiating a node in a new directory, and copying in the ``genesis.json``: - -:: - - gaiad init --home=$HOME/.gaiad2 - -and replace the ``genesis.json`` and ``config.toml`` files: - -:: - - cp $HOME/.gaiad/config/genesis.json $HOME/.gaiad2/config - cp $HOME/.gaiad/config/config.toml $HOME/.gaiad2/config - -then, get the node id of first node: - -:: - - gaiad show_node_id --home=$HOME/.gaiad1 - -We need to also modify $HOME/.gaiad2/config.toml to set new seeds and ports. It should look like: - -:: - - proxy_app = "tcp://127.0.0.1:46668" - moniker = "anonymous" - fast_sync = true - db_backend = "leveldb" - log_level = "state:info,*:error" - - [rpc] - laddr = "tcp://0.0.0.0:46667" - - [p2p] - laddr = "tcp://0.0.0.0:46666" - persistent_peers = "@0.0.0.0:46656" + cp -a ~/.gaiad2/config/gentx/. ~/.gaiad1/config/gentx/ + cp -a ~/.gaiad1/config/gentx/. ~/.gaiad2/config/gentx/ + gaiad init --gen-txs --home=$HOME/.gaiad1 --chain-id=test-chain + gaiad init --gen-txs --home=$HOME/.gaiad2 --chain-id=test-chain +**Note:** If you've already run these tests you may need to overwrite genesis using the ``-o`` flag +What we just did is copy the genesis transactions between each of the nodes so there is a common genesis transaction set; then we created both genesis files independantly from each home directory. Importantly both nodes have independantly created their ``genesis.json`` and ``config.toml`` files, which should be identical between nodes. Great, now that we've initialized the chains, we can start both nodes in the background: @@ -122,25 +46,13 @@ Nice. We can also lookup the validator set: gaiacli validatorset -There is only **one** validator now. Let's add another one! - -First, we need to create a new account: +Then, we try to transfer some ``fermion`` to another account: :: - gaiacli keys new - -Check that we now have two accounts: - -:: - - gaiacli keys list - -Then, we try to transfer some ``steak`` to another account: - -:: - - gaiacli send --amount=1000steak --to=$MYADDR2 --name=$NAME --chain-id= --node=tcp://localhost:46657 --sequence=0 + gaiacli account + gaiacli account + gaiacli send --amount=10fermion --to= --name=foo --chain-id=test-chain --node=tcp://localhost:46657 --sequence=0 **Note:** We need to be careful with the ``chain-id`` and ``sequence`` @@ -148,35 +60,7 @@ Check the balance & sequence with: :: - gaiacli account $MYADDR - -We can see the balance of ``$MYADDR2`` is 1000 now. - -Finally, let's bond the validator in ``$HOME/gaiad2``. Get the pubkey first: - -:: - - cat $HOME/.gaiad2/config/priv_validator.json | jq .pub_key.value - -Go to `this website `__ to change pubkey from base64 to Hex. - -Ok, now we can bond some coins to that pubkey: - -:: - - gaiacli bond --stake=1steak --validator= --sequence=0 --chain-id= --name=test - -Nice. We can see there are now two validators: - -:: - - gaiacli validatorset - -Check the balance of ``$MYADDR2`` to see the difference: it has 1 less ``steak``! - -:: - - gaiacli account $MYADDR2 + gaiacli account To confirm for certain the new validator is active, check tendermint: @@ -188,6 +72,11 @@ Finally, to relinquish all your power, unbond some coins. You should see your Vo :: - gaiacli unbond --sequence=# --chain-id= --name=test + gaiacli unbond --sequence=1 --chain-id= --name=test That's it! + +**Note:** TODO demonstrate edit-candidacy +**Note:** TODO demonstrate delegation +**Note:** TODO demonstrate unbond of delegation +**Note:** TODO demonstrate unbond candidate diff --git a/server/init.go b/server/init.go index af735f092..2d8be85f8 100644 --- a/server/init.go +++ b/server/init.go @@ -48,7 +48,7 @@ var ( func GenTxCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { cmd := &cobra.Command{ Use: "gen-tx", - Short: "Create genesis transaction file (under [--home]/gentx-[nodeID].json)", + Short: "Create genesis transaction file (under [--home]/config/gentx/gentx-[nodeID].json)", Args: cobra.NoArgs, RunE: func(_ *cobra.Command, args []string) error { @@ -85,7 +85,12 @@ func GenTxCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { } genTxFile := json.RawMessage(bz) name := fmt.Sprintf("gentx-%v.json", nodeID) - file := filepath.Join(viper.GetString(tmcli.HomeFlag), name) + writePath := filepath.Join(viper.GetString(tmcli.HomeFlag), "config", "gentx") + file := filepath.Join(writePath, name) + err = cmn.EnsureDir(writePath, 0700) + if err != nil { + return err + } err = cmn.WriteFile(file, bz, 0644) if err != nil { return err @@ -144,14 +149,14 @@ func InitCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { var validators []tmtypes.GenesisValidator var persistentPeers string - genTxsDir := viper.GetString(flagGenTxs) - if genTxsDir != "" { + if viper.GetBool(flagGenTxs) { + genTxsDir := filepath.Join(viper.GetString(tmcli.HomeFlag), "config", "gentx") validators, appGenTxs, persistentPeers, err = processGenTxs(genTxsDir, cdc, appInit) if err != nil { return err } config.P2P.PersistentPeers = persistentPeers - configFilePath := filepath.Join(viper.GetString(tmcli.HomeFlag), "config", "config.toml") //TODO this is annoying should be easier to get + configFilePath := filepath.Join(viper.GetString(tmcli.HomeFlag), "config", "config.toml") cfg.WriteConfigFile(configFilePath, config) } else { appGenTx, am, validator, err := appInit.AppGenTx(cdc, pubKey) @@ -194,7 +199,7 @@ func InitCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { } cmd.Flags().BoolP(flagOverwrite, "o", false, "overwrite the genesis.json file") cmd.Flags().String(flagChainID, "", "genesis file chain-id, if left blank will be randomly created") - cmd.Flags().String(flagGenTxs, "", "directory containing the genesis transactions") + cmd.Flags().Bool(flagGenTxs, false, "apply genesis transactions from [--home]/config/gentx/") cmd.Flags().AddFlagSet(appInit.FlagsAppGenState) cmd.Flags().AddFlagSet(appInit.FlagsAppGenTx) // need to add this flagset for when no GenTx's provided cmd.AddCommand(GenTxCmd(ctx, cdc, appInit))