Merge pull request #932 from tendermint/920-default-moniker-to-host-name
default moniker to the host name
This commit is contained in:
commit
b98098b1f0
|
@ -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()
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
|
@ -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
|
cmn.MustWriteFile(configFilePath, []byte(defaultConfig(defaultMoniker)), 0644)
|
||||||
// moniker := cfg.Prompt("Type hostname: ", "anonymous")
|
|
||||||
cmn.MustWriteFile(configFilePath, []byte(defaultConfig("anonymous")), 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(defaultMoniker)), 0644)
|
||||||
cmn.MustWriteFile(configFilePath, []byte(testConfig("anonymous")), 0644)
|
|
||||||
}
|
}
|
||||||
if !cmn.FileExists(genesisFilePath) {
|
if !cmn.FileExists(genesisFilePath) {
|
||||||
cmn.MustWriteFile(genesisFilePath, []byte(testGenesis), 0644)
|
cmn.MustWriteFile(genesisFilePath, []byte(testGenesis), 0644)
|
||||||
|
|
|
@ -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!
|
||||||
|
|
||||||
|
|
|
@ -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*: ``""``
|
||||||
|
|
|
@ -24,31 +24,31 @@ import (
|
||||||
//
|
//
|
||||||
// ```json
|
// ```json
|
||||||
// {
|
// {
|
||||||
// "error": "",
|
|
||||||
// "result": {
|
// "result": {
|
||||||
// "latest_block_time": 1.49631773695e+18,
|
// "syncing": false,
|
||||||
// "latest_block_height": 22924,
|
// "latest_block_time": "2017-12-07T18:19:47.617Z",
|
||||||
// "latest_app_hash": "9D16177BC71E445476174622EA559715C293740C",
|
// "latest_block_height": 6,
|
||||||
// "latest_block_hash": "75B36EEF96C277A592D8B14867098C58F68BB180",
|
// "latest_app_hash": "",
|
||||||
|
// "latest_block_hash": "A63D0C3307DEDCCFCC82ED411AE9108B70B29E02",
|
||||||
// "pub_key": {
|
// "pub_key": {
|
||||||
// "data": "68DFDA7E50F82946E7E8546BED37944A422CD1B831E70DF66BA3B8430593944D",
|
// "data": "8C9A68070CBE33F9C445862BA1E9D96A75CEB68C0CF6ADD3652D07DCAC5D0380",
|
||||||
// "type": "ed25519"
|
// "type": "ed25519"
|
||||||
// },
|
// },
|
||||||
// "node_info": {
|
// "node_info": {
|
||||||
// "other": [
|
// "other": [
|
||||||
// "wire_version=0.6.2",
|
// "wire_version=0.7.2",
|
||||||
// "p2p_version=0.5.0",
|
// "p2p_version=0.5.0",
|
||||||
// "consensus_version=v1/0.2.2",
|
// "consensus_version=v1/0.2.2",
|
||||||
// "rpc_version=0.7.0/3",
|
// "rpc_version=0.7.0/3",
|
||||||
// "tx_index=on",
|
// "tx_index=on",
|
||||||
// "rpc_addr=tcp://0.0.0.0:46657"
|
// "rpc_addr=tcp://0.0.0.0:46657"
|
||||||
// ],
|
// ],
|
||||||
// "version": "0.10.0-rc1-aa22bd84",
|
// "version": "0.13.0-14ccc8b",
|
||||||
// "listen_addr": "10.0.2.15:46656",
|
// "listen_addr": "10.0.2.15:46656",
|
||||||
// "remote_addr": "",
|
// "remote_addr": "",
|
||||||
// "network": "test-chain-6UTNIN",
|
// "network": "test-chain-qhVCa2",
|
||||||
// "moniker": "anonymous",
|
// "moniker": "vagrant-ubuntu-trusty-64",
|
||||||
// "pub_key": "659B9E54DD6EF9FEF28FAD40629AF0E4BD3C2563BB037132B054A176E00F1D94"
|
// "pub_key": "844981FE99ABB19F7816F2D5E94E8A74276AB1153760A7799E925C75401856C6"
|
||||||
// }
|
// }
|
||||||
// },
|
// },
|
||||||
// "id": "",
|
// "id": "",
|
||||||
|
|
Loading…
Reference in New Issue