Browse Source

Merge pull request #932 from tendermint/920-default-moniker-to-host-name

default moniker to the host name
pull/942/head
Ethan Buchman 7 years ago
committed by GitHub
parent
commit
b98098b1f0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 38 deletions
  1. +3
    -0
      cmd/tendermint/commands/root_test.go
  2. +17
    -1
      config/config.go
  3. +2
    -5
      config/toml.go
  4. +2
    -2
      config/toml_test.go
  5. +2
    -1
      docs/specification/configuration.rst
  6. +29
    -29
      rpc/core/status.go

+ 3
- 0
cmd/tendermint/commands/root_test.go View File

@ -32,6 +32,9 @@ func isolate(cmds ...*cobra.Command) cli.Executable {
if err := os.Unsetenv("TM_HOME"); err != nil { if err := os.Unsetenv("TM_HOME"); err != nil {
panic(err) panic(err)
} }
if err := os.RemoveAll(defaultRoot); err != nil {
panic(err)
}
viper.Reset() viper.Reset()
config = cfg.DefaultConfig() config = cfg.DefaultConfig()


+ 17
- 1
config/config.go View File

@ -2,6 +2,7 @@ package config
import ( import (
"fmt" "fmt"
"os"
"path/filepath" "path/filepath"
"time" "time"
) )
@ -108,7 +109,7 @@ func DefaultBaseConfig() BaseConfig {
return BaseConfig{ return BaseConfig{
Genesis: "genesis.json", Genesis: "genesis.json",
PrivValidator: "priv_validator.json", PrivValidator: "priv_validator.json",
Moniker: "anonymous",
Moniker: defaultMoniker,
ProxyApp: "tcp://127.0.0.1:46658", ProxyApp: "tcp://127.0.0.1:46658",
ABCI: "socket", ABCI: "socket",
LogLevel: DefaultPackageLogLevels(), LogLevel: DefaultPackageLogLevels(),
@ -456,3 +457,18 @@ func rootify(path, root string) string {
} }
return filepath.Join(root, path) 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
}

+ 2
- 5
config/toml.go View File

@ -23,9 +23,7 @@ func EnsureRoot(rootDir string) {
// Write default config file if missing. // Write default config file if missing.
if !cmn.FileExists(configFilePath) { 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. // Write default config file if missing.
if !cmn.FileExists(configFilePath) { 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) { if !cmn.FileExists(genesisFilePath) {
cmn.MustWriteFile(genesisFilePath, []byte(testGenesis), 0644) cmn.MustWriteFile(genesisFilePath, []byte(testGenesis), 0644)


+ 2
- 2
config/toml_test.go View File

@ -32,7 +32,7 @@ func TestEnsureRoot(t *testing.T) {
// make sure config is set properly // make sure config is set properly
data, err := ioutil.ReadFile(filepath.Join(tmpDir, "config.toml")) data, err := ioutil.ReadFile(filepath.Join(tmpDir, "config.toml"))
require.Nil(err) require.Nil(err)
assert.Equal([]byte(defaultConfig("anonymous")), data)
assert.Equal([]byte(defaultConfig(defaultMoniker)), data)
ensureFiles(t, tmpDir, "data") ensureFiles(t, tmpDir, "data")
} }
@ -49,7 +49,7 @@ func TestEnsureTestRoot(t *testing.T) {
// make sure config is set properly // make sure config is set properly
data, err := ioutil.ReadFile(filepath.Join(rootDir, "config.toml")) data, err := ioutil.ReadFile(filepath.Join(rootDir, "config.toml"))
require.Nil(err) 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! // TODO: make sure the cfg returned and testconfig are the same!


+ 2
- 1
docs/specification/configuration.rst View File

@ -21,7 +21,8 @@ The main config parameters are defined
- ``genesis_file``: The location of the genesis file. *Default*: - ``genesis_file``: The location of the genesis file. *Default*:
``"$TMHOME/genesis.json"`` ``"$TMHOME/genesis.json"``
- ``log_level``: *Default*: ``"state:info,*:error"`` - ``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*: - ``priv_validator_file``: Validator private key file. *Default*:
``"$TMHOME/priv_validator.json"`` ``"$TMHOME/priv_validator.json"``
- ``prof_laddr``: Profile listen address. *Default*: ``""`` - ``prof_laddr``: Profile listen address. *Default*: ``""``


+ 29
- 29
rpc/core/status.go View File

@ -24,35 +24,35 @@ import (
// //
// ```json // ```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) { func Status() (*ctypes.ResultStatus, error) {


Loading…
Cancel
Save