diff --git a/cmd/tendermint/commands/root_test.go b/cmd/tendermint/commands/root_test.go index b4e30d980..8217ee166 100644 --- a/cmd/tendermint/commands/root_test.go +++ b/cmd/tendermint/commands/root_test.go @@ -32,6 +32,9 @@ func isolate(cmds ...*cobra.Command) cli.Executable { if err := os.Unsetenv("TM_HOME"); err != nil { panic(err) } + if err := os.RemoveAll(defaultRoot); err != nil { + panic(err) + } viper.Reset() config = cfg.DefaultConfig() diff --git a/config/config.go b/config/config.go index ea3fa13e4..783758896 100644 --- a/config/config.go +++ b/config/config.go @@ -2,6 +2,7 @@ package config import ( "fmt" + "os" "path/filepath" "time" ) @@ -108,7 +109,7 @@ func DefaultBaseConfig() BaseConfig { return BaseConfig{ Genesis: "genesis.json", PrivValidator: "priv_validator.json", - Moniker: "anonymous", + Moniker: defaultMoniker, ProxyApp: "tcp://127.0.0.1:46658", ABCI: "socket", LogLevel: DefaultPackageLogLevels(), @@ -456,3 +457,18 @@ func rootify(path, root string) string { } return filepath.Join(root, path) } + +//----------------------------------------------------------------------------- +// Moniker + +var defaultMoniker = getDefaultMoniker() + +// getDefaultMoniker returns a default moniker, which is the host name. If runtime +// fails to get the host name, "anonymous" will be returned. +func getDefaultMoniker() string { + moniker, err := os.Hostname() + if err != nil { + moniker = "anonymous" + } + return moniker +} diff --git a/config/toml.go b/config/toml.go index ec70ab75d..735f45c12 100644 --- a/config/toml.go +++ b/config/toml.go @@ -23,9 +23,7 @@ func EnsureRoot(rootDir string) { // Write default config file if missing. if !cmn.FileExists(configFilePath) { - // Ask user for moniker - // moniker := cfg.Prompt("Type hostname: ", "anonymous") - cmn.MustWriteFile(configFilePath, []byte(defaultConfig("anonymous")), 0644) + cmn.MustWriteFile(configFilePath, []byte(defaultConfig(defaultMoniker)), 0644) } } @@ -81,8 +79,7 @@ func ResetTestRoot(testName string) *Config { // Write default config file if missing. if !cmn.FileExists(configFilePath) { - // Ask user for moniker - cmn.MustWriteFile(configFilePath, []byte(testConfig("anonymous")), 0644) + cmn.MustWriteFile(configFilePath, []byte(testConfig(defaultMoniker)), 0644) } if !cmn.FileExists(genesisFilePath) { cmn.MustWriteFile(genesisFilePath, []byte(testGenesis), 0644) diff --git a/config/toml_test.go b/config/toml_test.go index bf3bf58f7..f927a14ca 100644 --- a/config/toml_test.go +++ b/config/toml_test.go @@ -32,7 +32,7 @@ func TestEnsureRoot(t *testing.T) { // make sure config is set properly data, err := ioutil.ReadFile(filepath.Join(tmpDir, "config.toml")) require.Nil(err) - assert.Equal([]byte(defaultConfig("anonymous")), data) + assert.Equal([]byte(defaultConfig(defaultMoniker)), data) ensureFiles(t, tmpDir, "data") } @@ -49,7 +49,7 @@ func TestEnsureTestRoot(t *testing.T) { // make sure config is set properly data, err := ioutil.ReadFile(filepath.Join(rootDir, "config.toml")) require.Nil(err) - assert.Equal([]byte(testConfig("anonymous")), data) + assert.Equal([]byte(testConfig(defaultMoniker)), data) // TODO: make sure the cfg returned and testconfig are the same! diff --git a/docs/specification/configuration.rst b/docs/specification/configuration.rst index 94801136f..74b41d09d 100644 --- a/docs/specification/configuration.rst +++ b/docs/specification/configuration.rst @@ -21,7 +21,8 @@ The main config parameters are defined - ``genesis_file``: The location of the genesis file. *Default*: ``"$TMHOME/genesis.json"`` - ``log_level``: *Default*: ``"state:info,*:error"`` -- ``moniker``: Name of this node. *Default*: ``"anonymous"`` +- ``moniker``: Name of this node. *Default*: the host name or ``"anonymous"`` + if runtime fails to get the host name - ``priv_validator_file``: Validator private key file. *Default*: ``"$TMHOME/priv_validator.json"`` - ``prof_laddr``: Profile listen address. *Default*: ``""`` diff --git a/rpc/core/status.go b/rpc/core/status.go index 0cb7acc1f..653c37f50 100644 --- a/rpc/core/status.go +++ b/rpc/core/status.go @@ -24,35 +24,35 @@ import ( // // ```json // { -// "error": "", -// "result": { -// "latest_block_time": 1.49631773695e+18, -// "latest_block_height": 22924, -// "latest_app_hash": "9D16177BC71E445476174622EA559715C293740C", -// "latest_block_hash": "75B36EEF96C277A592D8B14867098C58F68BB180", -// "pub_key": { -// "data": "68DFDA7E50F82946E7E8546BED37944A422CD1B831E70DF66BA3B8430593944D", -// "type": "ed25519" -// }, -// "node_info": { -// "other": [ -// "wire_version=0.6.2", -// "p2p_version=0.5.0", -// "consensus_version=v1/0.2.2", -// "rpc_version=0.7.0/3", -// "tx_index=on", -// "rpc_addr=tcp://0.0.0.0:46657" -// ], -// "version": "0.10.0-rc1-aa22bd84", -// "listen_addr": "10.0.2.15:46656", -// "remote_addr": "", -// "network": "test-chain-6UTNIN", -// "moniker": "anonymous", -// "pub_key": "659B9E54DD6EF9FEF28FAD40629AF0E4BD3C2563BB037132B054A176E00F1D94" -// } -// }, -// "id": "", -// "jsonrpc": "2.0" +// "result": { +// "syncing": false, +// "latest_block_time": "2017-12-07T18:19:47.617Z", +// "latest_block_height": 6, +// "latest_app_hash": "", +// "latest_block_hash": "A63D0C3307DEDCCFCC82ED411AE9108B70B29E02", +// "pub_key": { +// "data": "8C9A68070CBE33F9C445862BA1E9D96A75CEB68C0CF6ADD3652D07DCAC5D0380", +// "type": "ed25519" +// }, +// "node_info": { +// "other": [ +// "wire_version=0.7.2", +// "p2p_version=0.5.0", +// "consensus_version=v1/0.2.2", +// "rpc_version=0.7.0/3", +// "tx_index=on", +// "rpc_addr=tcp://0.0.0.0:46657" +// ], +// "version": "0.13.0-14ccc8b", +// "listen_addr": "10.0.2.15:46656", +// "remote_addr": "", +// "network": "test-chain-qhVCa2", +// "moniker": "vagrant-ubuntu-trusty-64", +// "pub_key": "844981FE99ABB19F7816F2D5E94E8A74276AB1153760A7799E925C75401856C6" +// } +// }, +// "id": "", +// "jsonrpc": "2.0" // } // ``` func Status() (*ctypes.ResultStatus, error) {