diff --git a/INSTALL/README.md b/INSTALL/README.md index 9e02efbf..751d346c 100644 --- a/INSTALL/README.md +++ b/INSTALL/README.md @@ -25,4 +25,6 @@ WARNING: THIS STEP WILL GIVE CONTROL OF THE CURRENT USER TO THE DEV TEAM. ### Install/Update Tendermint go get -u github.com/tendermint/tendermint/cmd/tendermint - tendermint node + mkdir -p ~/.tendermint + cp $GOPATH/src/github.com/tendermint/tendermint/config/tendermint/genesis.json ~/.tendermint/ + tendermint node --seeds="goldenalchemist.chaintest.net:46656" diff --git a/cmd/tendermint/flags.go b/cmd/tendermint/flags.go index 4570973f..ff402c33 100644 --- a/cmd/tendermint/flags.go +++ b/cmd/tendermint/flags.go @@ -24,7 +24,7 @@ func parseFlags(config cfg.Config, args []string) { flags.BoolVar(&printHelp, "help", false, "Print this help message.") flags.StringVar(&moniker, "moniker", config.GetString("moniker"), "Node Name") flags.StringVar(&nodeLaddr, "node_laddr", config.GetString("node_laddr"), "Node listen address. (0.0.0.0:0 means any interface, any port)") - flags.StringVar(&seeds, "seeds", config.GetString("seeds"), "Comma delimited seed nodes") + flags.StringVar(&seeds, "seeds", config.GetString("seeds"), "Comma delimited host:port seed nodes") flags.BoolVar(&fastSync, "fast_sync", config.GetBool("fast_sync"), "Fast blockchain syncing") flags.BoolVar(&skipUPNP, "skip_upnp", config.GetBool("skip_upnp"), "Skip UPNP configuration") flags.StringVar(&rpcLaddr, "rpc_laddr", config.GetString("rpc_laddr"), "RPC listen address. Port required") diff --git a/cmd/tendermint/main.go b/cmd/tendermint/main.go index dd4388c0..f84187c6 100644 --- a/cmd/tendermint/main.go +++ b/cmd/tendermint/main.go @@ -16,13 +16,14 @@ func main() { fmt.Println(`Tendermint Commands: - node Run the tendermint node - gen_account Generate new account keypair - gen_validator Generate new validator keypair - get_account Get account balance - send_tx Sign and publish a SendTx - probe_upnp Test UPnP functionality - version Show version info + node Run the tendermint node + show_validator Show this node's validator info + gen_account Generate new account keypair + gen_validator Generate new validator keypair + get_account Get account balance + send_tx Sign and publish a SendTx + probe_upnp Test UPnP functionality + version Show version info `) return } @@ -35,6 +36,8 @@ Commands: switch args[0] { case "node": node.RunNode() + case "show_validator": + show_validator() case "gen_account": gen_account() case "gen_validator": diff --git a/cmd/tendermint/show_validator.go b/cmd/tendermint/show_validator.go new file mode 100644 index 00000000..0c743f71 --- /dev/null +++ b/cmd/tendermint/show_validator.go @@ -0,0 +1,14 @@ +package main + +import ( + "fmt" + + "github.com/tendermint/tendermint/types" + "github.com/tendermint/tendermint/wire" +) + +func show_validator() { + privValidatorFile := config.GetString("priv_validator_file") + privValidator := types.LoadOrGenPrivValidator(privValidatorFile) + fmt.Println(string(wire.JSONBytes(privValidator.PubKey))) +} diff --git a/config/tendermint/config.go b/config/tendermint/config.go index c5b49fed..e8abcebb 100644 --- a/config/tendermint/config.go +++ b/config/tendermint/config.go @@ -25,7 +25,6 @@ func initTMRoot(rootDir string) { EnsureDir(rootDir) configFilePath := path.Join(rootDir, "config.toml") - genesisFilePath := path.Join(rootDir, "genesis.json") // Write default config file if missing. if !FileExists(configFilePath) { @@ -33,9 +32,6 @@ func initTMRoot(rootDir string) { // moniker := cfg.Prompt("Type hostname: ", "anonymous") MustWriteFile(configFilePath, []byte(defaultConfig("anonymous"))) } - if !FileExists(genesisFilePath) { - MustWriteFile(genesisFilePath, []byte(defaultGenesis)) - } } func GetConfig(rootDir string) cfg.Config { @@ -88,7 +84,7 @@ var defaultConfigTmpl = `# This is a TOML config file. moniker = "__MONIKER__" node_laddr = "0.0.0.0:46656" -seeds = "goldenalchemist.chaintest.net:46656" +seeds = "" fast_sync = true db_backend = "leveldb" log_level = "notice" @@ -99,79 +95,3 @@ func defaultConfig(moniker string) (defaultConfig string) { defaultConfig = strings.Replace(defaultConfigTmpl, "__MONIKER__", moniker, -1) return } - -var defaultGenesis = `{ - "chain_id": "tendermint_testnet_11.c", - "accounts": [ - { - "address": "9FCBA7F840A0BFEBBE755E853C9947270A912D04", - "amount": 1991999998000000 - }, - { - "address": "964B1493BBE3312278B7DEB94C39149F7899A345", - "amount": 100000000000000 - }, - { - "address": "B9FA4AB462B9C6BF6A62DB4AE77C9E7087209A04", - "amount": 1000000000000 - }, - { - "address": "F171824590D69386F709E7B6704B369C5A370D60", - "amount": 1000000000000 - }, - { - "address": "56EFE746A13D9A6054AC89C3E2A361C2DB8B9EAE", - "amount": 1000000000000 - }, - { - "address": "7C2E032D8407EDF66A04D88CF0E1D9B15D98AE2D", - "amount": 1000000000000 - }, - { - "address": "636EF5823E082AD66EBC203FD4DFB1031F0C61CA", - "amount": 1000000000000 - }, - { - "address": "9008419E6351360A59B124E707E4CA2A5BFB9BE6", - "amount": 1000000000000 - }, - { - "address": "C78F48919B8A4030AD3E5ED643F8D2302E41953D", - "amount": 1000000000000 - }, - { - "address": "5290AC90CE2422DDC3F91F6A246F7E3C542EA51A", - "amount": 1000000000000 - }, - { - "address": "A88A61069B6660F30F65E8786AFDD4F1D8F625E9", - "amount": 1000000 - }, - { - "address": "EE2EE9247973B4AFC3867CFE5F415410AC251B61", - "amount": 1000000 - } - ], - "validators": [ - { - "pub_key": [1, "178EC6008A4364508979C70CBF100BD4BCBAA12DDE6251F5F486B4FD09014F06"], - "amount": 100000000000 - }, - { - "pub_key": [1, "2A77777CC51467DE42350D4A8F34720D527734189BE64C7A930DD169E1FED3C6"], - "amount": 100000000000 - }, - { - "pub_key": [1, "3718E69D09B11B3AD3FA31AEF07EC416D2AEED241CACE7B0F30AE9803FFB0F08"], - "amount": 100000000000 - }, - { - "pub_key": [1, "C6B0440DEACD1E4CF1C736CEB8E38E788B700BA2B2045A55CB657A455CF5F889"], - "amount": 100000000000 - }, - { - "pub_key": [1, "3BA1190D54F91EFBF8B0125F7EC116AD4BA2894B6EE38564A5D5FD3230D91F7B"], - "amount": 100000000000 - } - ] -}` diff --git a/config/tendermint/genesis.json b/config/tendermint/genesis.json new file mode 100644 index 00000000..eca00696 --- /dev/null +++ b/config/tendermint/genesis.json @@ -0,0 +1,75 @@ +{ + "chain_id": "tendermint_testnet_11.c", + "accounts": [ + { + "address": "9FCBA7F840A0BFEBBE755E853C9947270A912D04", + "amount": 1991999998000000 + }, + { + "address": "964B1493BBE3312278B7DEB94C39149F7899A345", + "amount": 100000000000000 + }, + { + "address": "B9FA4AB462B9C6BF6A62DB4AE77C9E7087209A04", + "amount": 1000000000000 + }, + { + "address": "F171824590D69386F709E7B6704B369C5A370D60", + "amount": 1000000000000 + }, + { + "address": "56EFE746A13D9A6054AC89C3E2A361C2DB8B9EAE", + "amount": 1000000000000 + }, + { + "address": "7C2E032D8407EDF66A04D88CF0E1D9B15D98AE2D", + "amount": 1000000000000 + }, + { + "address": "636EF5823E082AD66EBC203FD4DFB1031F0C61CA", + "amount": 1000000000000 + }, + { + "address": "9008419E6351360A59B124E707E4CA2A5BFB9BE6", + "amount": 1000000000000 + }, + { + "address": "C78F48919B8A4030AD3E5ED643F8D2302E41953D", + "amount": 1000000000000 + }, + { + "address": "5290AC90CE2422DDC3F91F6A246F7E3C542EA51A", + "amount": 1000000000000 + }, + { + "address": "A88A61069B6660F30F65E8786AFDD4F1D8F625E9", + "amount": 1000000 + }, + { + "address": "EE2EE9247973B4AFC3867CFE5F415410AC251B61", + "amount": 1000000 + } + ], + "validators": [ + { + "pub_key": [1, "178EC6008A4364508979C70CBF100BD4BCBAA12DDE6251F5F486B4FD09014F06"], + "amount": 100000000000 + }, + { + "pub_key": [1, "2A77777CC51467DE42350D4A8F34720D527734189BE64C7A930DD169E1FED3C6"], + "amount": 100000000000 + }, + { + "pub_key": [1, "3718E69D09B11B3AD3FA31AEF07EC416D2AEED241CACE7B0F30AE9803FFB0F08"], + "amount": 100000000000 + }, + { + "pub_key": [1, "C6B0440DEACD1E4CF1C736CEB8E38E788B700BA2B2045A55CB657A455CF5F889"], + "amount": 100000000000 + }, + { + "pub_key": [1, "3BA1190D54F91EFBF8B0125F7EC116AD4BA2894B6EE38564A5D5FD3230D91F7B"], + "amount": 100000000000 + } + ] +} diff --git a/node/node.go b/node/node.go index 8e39b769..1ca41b93 100644 --- a/node/node.go +++ b/node/node.go @@ -5,7 +5,6 @@ import ( "math/rand" "net" "net/http" - "os" "strconv" "strings" "time" @@ -76,18 +75,8 @@ func NewNode() *Node { config.Set("chain_id", state.ChainID) // Get PrivValidator - var privValidator *types.PrivValidator privValidatorFile := config.GetString("priv_validator_file") - if _, err := os.Stat(privValidatorFile); err == nil { - privValidator = types.LoadPrivValidator(privValidatorFile) - log.Notice("Loaded PrivValidator", - "file", privValidatorFile, "privValidator", privValidator) - } else { - privValidator = types.GenPrivValidator() - privValidator.SetFile(privValidatorFile) - privValidator.Save() - log.Notice("Generated PrivValidator", "file", privValidatorFile) - } + privValidator := types.LoadOrGenPrivValidator(privValidatorFile) // Generate node PrivKey privKey := acm.GenPrivKeyEd25519() @@ -298,6 +287,19 @@ func makeNodeInfo(sw *p2p.Switch, privKey acm.PrivKeyEd25519) *types.NodeInfo { //------------------------------------------------------------------------------ func RunNode() { + + // Wait until the genesis doc becomes available + genDocFile := config.GetString("genesis_file") + if !FileExists(genDocFile) { + log.Notice(Fmt("Waiting for genesis file %v...", genDocFile)) + for { + time.Sleep(time.Second) + if FileExists(genDocFile) { + break + } + } + } + // Create & start node n := NewNode() l := p2p.NewDefaultListener("tcp", config.GetString("node_laddr")) diff --git a/types/priv_validator.go b/types/priv_validator.go index b4e88064..0cfb0021 100644 --- a/types/priv_validator.go +++ b/types/priv_validator.go @@ -6,6 +6,7 @@ import ( "fmt" "io/ioutil" "math" + "os" "sync" acm "github.com/tendermint/tendermint/account" @@ -79,6 +80,21 @@ func LoadPrivValidator(filePath string) *PrivValidator { return privVal } +func LoadOrGenPrivValidator(filePath string) *PrivValidator { + var privValidator *PrivValidator + if _, err := os.Stat(filePath); err == nil { + privValidator = LoadPrivValidator(filePath) + log.Notice("Loaded PrivValidator", + "file", filePath, "privValidator", privValidator) + } else { + privValidator = GenPrivValidator() + privValidator.SetFile(filePath) + privValidator.Save() + log.Notice("Generated PrivValidator", "file", filePath) + } + return privValidator +} + func (privVal *PrivValidator) SetFile(filePath string) { privVal.mtx.Lock() defer privVal.mtx.Unlock()