From 5cbb5d2541bf3e23f92544a0527efd9e363601da Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Mon, 21 Dec 2015 17:52:00 -0500 Subject: [PATCH 1/2] tendermint init --- cmd/tendermint/init.go | 23 +++++++++++++++++++++++ cmd/tendermint/main.go | 2 ++ config/tendermint/config.go | 4 ++-- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 cmd/tendermint/init.go diff --git a/cmd/tendermint/init.go b/cmd/tendermint/init.go new file mode 100644 index 00000000..f38a6f51 --- /dev/null +++ b/cmd/tendermint/init.go @@ -0,0 +1,23 @@ +package main + +import ( + "github.com/tendermint/tendermint/types" +) + +func init_files() { + privValidator := types.GenPrivValidator() + privValidator.SetFile(config.GetString("priv_validator_file")) + privValidator.Save() + + //TODO: chainID + genDoc := types.GenesisDoc{ + ChainID: "hi", + } + genDoc.Validators = []types.GenesisValidator{types.GenesisValidator{ + PubKey: privValidator.PubKey, + Amount: 10000, + }} + + genDoc.SaveAs(config.GetString("genesis_file")) + +} diff --git a/cmd/tendermint/main.go b/cmd/tendermint/main.go index a4ab2b96..6ccbc4d1 100644 --- a/cmd/tendermint/main.go +++ b/cmd/tendermint/main.go @@ -34,6 +34,8 @@ Commands: switch args[0] { case "node": node.RunNode() + case "init": + init_files() case "show_validator": show_validator() case "gen_validator": diff --git a/config/tendermint/config.go b/config/tendermint/config.go index b2e220fc..84452e2d 100644 --- a/config/tendermint/config.go +++ b/config/tendermint/config.go @@ -56,7 +56,7 @@ func GetConfig(rootDir string) cfg.Config { mapConfig.SetDefault("moniker", "anonymous") mapConfig.SetDefault("node_laddr", "0.0.0.0:46656") // mapConfig.SetDefault("seeds", "goldenalchemist.chaintest.net:46656") - mapConfig.SetDefault("fast_sync", true) + mapConfig.SetDefault("fast_sync", false) mapConfig.SetDefault("skip_upnp", false) mapConfig.SetDefault("addrbook_file", rootDir+"/addrbook.json") mapConfig.SetDefault("priv_validator_file", rootDir+"/priv_validator.json") @@ -77,7 +77,7 @@ proxy_app = "tcp://127.0.0.1:46658" moniker = "__MONIKER__" node_laddr = "0.0.0.0:46656" seeds = "" -fast_sync = true +fast_sync = false db_backend = "leveldb" log_level = "notice" rpc_laddr = "0.0.0.0:46657" From 6f5baa84140107dc51a9e05cc05cff149c1c4408 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Mon, 21 Dec 2015 18:13:42 -0500 Subject: [PATCH 2/2] rpc: add app_hash to /status --- rpc/core/net.go | 25 ------------------------- rpc/core/status.go | 30 ++++++++++++++++++++++++++++++ rpc/core/types/responses.go | 1 + 3 files changed, 31 insertions(+), 25 deletions(-) create mode 100644 rpc/core/status.go diff --git a/rpc/core/net.go b/rpc/core/net.go index 1413595c..d68a4e30 100644 --- a/rpc/core/net.go +++ b/rpc/core/net.go @@ -2,35 +2,10 @@ package core import ( ctypes "github.com/tendermint/tendermint/rpc/core/types" - "github.com/tendermint/tendermint/types" ) //----------------------------------------------------------------------------- -// TODO Move to status.go or node.go -func Status() (*ctypes.ResultStatus, error) { - latestHeight := blockStore.Height() - var ( - latestBlockMeta *types.BlockMeta - latestBlockHash []byte - latestBlockTime int64 - ) - if latestHeight != 0 { - latestBlockMeta = blockStore.LoadBlockMeta(latestHeight) - latestBlockHash = latestBlockMeta.Hash - latestBlockTime = latestBlockMeta.Header.Time.UnixNano() - } - - return &ctypes.ResultStatus{ - NodeInfo: p2pSwitch.NodeInfo(), - PubKey: privValidator.PubKey, - LatestBlockHash: latestBlockHash, - LatestBlockHeight: latestHeight, - LatestBlockTime: latestBlockTime}, nil -} - -//----------------------------------------------------------------------------- - func NetInfo() (*ctypes.ResultNetInfo, error) { listening := p2pSwitch.IsListening() listeners := []string{} diff --git a/rpc/core/status.go b/rpc/core/status.go new file mode 100644 index 00000000..bf3d69ff --- /dev/null +++ b/rpc/core/status.go @@ -0,0 +1,30 @@ +package core + +import ( + ctypes "github.com/tendermint/tendermint/rpc/core/types" + "github.com/tendermint/tendermint/types" +) + +func Status() (*ctypes.ResultStatus, error) { + latestHeight := blockStore.Height() + var ( + latestBlockMeta *types.BlockMeta + latestBlockHash []byte + latestAppHash []byte + latestBlockTime int64 + ) + if latestHeight != 0 { + latestBlockMeta = blockStore.LoadBlockMeta(latestHeight) + latestBlockHash = latestBlockMeta.Hash + latestAppHash = latestBlockMeta.Header.AppHash + latestBlockTime = latestBlockMeta.Header.Time.UnixNano() + } + + return &ctypes.ResultStatus{ + NodeInfo: p2pSwitch.NodeInfo(), + PubKey: privValidator.PubKey, + LatestBlockHash: latestBlockHash, + LatestAppHash: latestAppHash, + LatestBlockHeight: latestHeight, + LatestBlockTime: latestBlockTime}, nil +} diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index dccd0be9..2dc15328 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -21,6 +21,7 @@ type ResultStatus struct { NodeInfo *p2p.NodeInfo `json:"node_info"` PubKey crypto.PubKey `json:"pub_key"` LatestBlockHash []byte `json:"latest_block_hash"` + LatestAppHash []byte `json:"latest_app_hash"` LatestBlockHeight int `json:"latest_block_height"` LatestBlockTime int64 `json:"latest_block_time"` // nano }