From d8fb226ec49fc29cf4694a46adac522f2b96925a Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sat, 29 Apr 2017 10:55:26 -0400 Subject: [PATCH] new config --- cmd/tendermint/commands/root.go | 4 +- cmd/tendermint/commands/run_node.go | 41 ++++++------- config/tendermint/config.go | 85 +++++++++++++-------------- config/tendermint/types.go | 89 +++++++++++++++++++++++++++++ node/node.go | 18 ++++-- 5 files changed, 164 insertions(+), 73 deletions(-) create mode 100644 config/tendermint/types.go diff --git a/cmd/tendermint/commands/root.go b/cmd/tendermint/commands/root.go index de5b71bd1..4a97c44fd 100644 --- a/cmd/tendermint/commands/root.go +++ b/cmd/tendermint/commands/root.go @@ -20,12 +20,12 @@ var RootCmd = &cobra.Command{ Short: "Tendermint Core (BFT Consensus) in Go", PersistentPreRun: func(cmd *cobra.Command, args []string) { // set the log level in the config and logger - config.Set("log_level", logLevel) + config.Set("node.log_level", logLevel) logger.SetLogLevel(logLevel) }, } func init() { //parse flag and set config - RootCmd.PersistentFlags().StringVar(&logLevel, "log_level", config.GetString("log_level"), "Log level") + RootCmd.PersistentFlags().StringVar(&logLevel, "log_level", config.GetString("node.log_level"), "Log level") } diff --git a/cmd/tendermint/commands/run_node.go b/cmd/tendermint/commands/run_node.go index b2b23af5c..2ddc50a02 100644 --- a/cmd/tendermint/commands/run_node.go +++ b/cmd/tendermint/commands/run_node.go @@ -7,6 +7,7 @@ import ( "github.com/spf13/cobra" + //cfg "github.com/tendermint/tendermint/config/tendermint" "github.com/tendermint/tendermint/node" "github.com/tendermint/tendermint/types" cmn "github.com/tendermint/tmlibs/common" @@ -36,23 +37,23 @@ var ( func init() { // configuration options - runNodeCmd.Flags().StringVar(&moniker, "moniker", config.GetString("moniker"), + runNodeCmd.Flags().StringVar(&moniker, "moniker", config.GetString("node.moniker"), "Node Name") - runNodeCmd.Flags().StringVar(&nodeLaddr, "node_laddr", config.GetString("node_laddr"), + runNodeCmd.Flags().StringVar(&nodeLaddr, "node_laddr", config.GetString("node.listen_addr"), "Node listen address. (0.0.0.0:0 means any interface, any port)") - runNodeCmd.Flags().StringVar(&seeds, "seeds", config.GetString("seeds"), + runNodeCmd.Flags().StringVar(&seeds, "seeds", config.GetString("network.seeds"), "Comma delimited host:port seed nodes") - runNodeCmd.Flags().BoolVar(&fastSync, "fast_sync", config.GetBool("fast_sync"), + runNodeCmd.Flags().BoolVar(&fastSync, "fast_sync", config.GetBool("blockchain.fast_sync"), "Fast blockchain syncing") - runNodeCmd.Flags().BoolVar(&skipUPNP, "skip_upnp", config.GetBool("skip_upnp"), + runNodeCmd.Flags().BoolVar(&skipUPNP, "skip_upnp", config.GetBool("network.skip_upnp"), "Skip UPNP configuration") - runNodeCmd.Flags().StringVar(&rpcLaddr, "rpc_laddr", config.GetString("rpc_laddr"), + runNodeCmd.Flags().StringVar(&rpcLaddr, "rpc_laddr", config.GetString("rpc.listen_addr"), "RPC listen address. Port required") - runNodeCmd.Flags().StringVar(&grpcLaddr, "grpc_laddr", config.GetString("grpc_laddr"), + runNodeCmd.Flags().StringVar(&grpcLaddr, "grpc_laddr", config.GetString("grpc.listen_addr"), "GRPC listen address (BroadcastTx only). Port required") - runNodeCmd.Flags().StringVar(&proxyApp, "proxy_app", config.GetString("proxy_app"), + runNodeCmd.Flags().StringVar(&proxyApp, "proxy_app", config.GetString("abci.proxy_app"), "Proxy app address, or 'nilapp' or 'dummy' for local testing.") - runNodeCmd.Flags().StringVar(&abciTransport, "abci", config.GetString("abci"), + runNodeCmd.Flags().StringVar(&abciTransport, "abci", config.GetString("abci.mode"), "Specify abci transport (socket | grpc)") // feature flags @@ -65,16 +66,16 @@ func init() { func setConfigFlags(cmd *cobra.Command, args []string) { // Merge parsed flag values onto config - config.Set("moniker", moniker) - config.Set("node_laddr", nodeLaddr) - config.Set("seeds", seeds) - config.Set("fast_sync", fastSync) - config.Set("skip_upnp", skipUPNP) - config.Set("rpc_laddr", rpcLaddr) - config.Set("grpc_laddr", grpcLaddr) - config.Set("proxy_app", proxyApp) - config.Set("abci", abciTransport) - config.Set("pex_reactor", pex) + config.Set("node.moniker", moniker) + config.Set("node.listen_addr", nodeLaddr) + config.Set("network.seeds", seeds) + config.Set("network.skip_upnp", skipUPNP) + config.Set("network.pex_reactor", pex) + config.Set("blockchain.fast_sync", fastSync) + config.Set("rpc.listen_addr", rpcLaddr) + config.Set("rpc.grpc_listen_addr", grpcLaddr) + config.Set("abci.proxy_app", proxyApp) + config.Set("abci.mode", abciTransport) } // Users wishing to: @@ -113,7 +114,7 @@ func runNode(cmd *cobra.Command, args []string) error { } // Create & start node - n := node.NewNodeDefault(config) + n := node.NewNodeDefault(config) //tmConfig) if _, err := n.Start(); err != nil { return fmt.Errorf("Failed to start node: %v", err) } else { diff --git a/config/tendermint/config.go b/config/tendermint/config.go index 9011e0154..0ac3e1f74 100644 --- a/config/tendermint/config.go +++ b/config/tendermint/config.go @@ -53,59 +53,54 @@ func GetConfig(rootDir string) *viper.Viper { //config.WatchConfig() // Set defaults or panic - if config.IsSet("chain_id") { + if config.IsSet("chain.chain_id") { cmn.Exit("Cannot set 'chain_id' via config.toml") } - if config.IsSet("revision_file") { - cmn.Exit("Cannot set 'revision_file' via config.toml. It must match what's in the Makefile") - } //mapConfig.SetRequired("chain_id") // blows up if you try to use it before setting. - config.SetDefault("genesis_file", rootDir+"/genesis.json") - config.SetDefault("proxy_app", "tcp://127.0.0.1:46658") - config.SetDefault("abci", "socket") - config.SetDefault("moniker", "anonymous") - config.SetDefault("node_laddr", "tcp://0.0.0.0:46656") - config.SetDefault("seeds", "") - // config.SetDefault("seeds", "goldenalchemist.chaintest.net:46656") - config.SetDefault("fast_sync", true) - config.SetDefault("skip_upnp", false) - config.SetDefault("addrbook_file", rootDir+"/addrbook.json") - config.SetDefault("addrbook_strict", true) // disable to allow connections locally - config.SetDefault("pex_reactor", false) // enable for peer exchange - config.SetDefault("priv_validator_file", rootDir+"/priv_validator.json") - config.SetDefault("db_backend", "leveldb") - config.SetDefault("db_dir", rootDir+"/data") - config.SetDefault("log_level", "info") - config.SetDefault("rpc_laddr", "tcp://0.0.0.0:46657") - config.SetDefault("grpc_laddr", "") - config.SetDefault("prof_laddr", "") - config.SetDefault("revision_file", rootDir+"/revision") - config.SetDefault("cs_wal_file", rootDir+"/data/cs.wal/wal") - config.SetDefault("cs_wal_light", false) - config.SetDefault("filter_peers", false) - - config.SetDefault("block_size", 10000) // max number of txs - config.SetDefault("block_part_size", 65536) // part size 64K - config.SetDefault("disable_data_hash", false) + config.SetDefault("node.moniker", "anonymous") + config.SetDefault("node.log_level", "info") + config.SetDefault("node.prof_laddr", "") + config.SetDefault("chain.genesis_file", rootDir+"/genesis.json") + config.SetDefault("abci.proxy_app", "tcp://127.0.0.1:46658") + config.SetDefault("abci.mode", "socket") + config.SetDefault("abci.filter_peers", false) + config.SetDefault("network.listen_addr", "tcp://0.0.0.0:46656") + config.SetDefault("network.seeds", "") + config.SetDefault("network.skip_upnp", false) + config.SetDefault("blockchain.fast_sync", true) + config.SetDefault("network.addrbook_file", rootDir+"/addrbook.json") + config.SetDefault("network.addrbook_strict", true) // disable to allow connections locally + config.SetDefault("network.pex_reactor", false) // enable for peer exchange + config.SetDefault("node.priv_validator_file", rootDir+"/priv_validator.json") + config.SetDefault("db.backend", "leveldb") + config.SetDefault("db.dir", rootDir+"/data") + config.SetDefault("rpc.listen_addr", "tcp://0.0.0.0:46657") + config.SetDefault("rpc.grpc_listen_addr", "") + config.SetDefault("consensus.wal_file", rootDir+"/data/cs.wal/wal") + config.SetDefault("consensus.wal_light", false) + + config.SetDefault("block.max_txs", 10000) // max number of txs + config.SetDefault("block.part_size", 65536) // part size 64K + config.SetDefault("block.disable_data_hash", false) // all timeouts are in ms - config.SetDefault("timeout_handshake", 10000) - config.SetDefault("timeout_propose", 3000) - config.SetDefault("timeout_propose_delta", 500) - config.SetDefault("timeout_prevote", 1000) - config.SetDefault("timeout_prevote_delta", 500) - config.SetDefault("timeout_precommit", 1000) - config.SetDefault("timeout_precommit_delta", 500) - config.SetDefault("timeout_commit", 1000) + config.SetDefault("consensus.timeout_handshake", 10000) + config.SetDefault("consensus.timeout_propose", 3000) + config.SetDefault("consensus.timeout_propose_delta", 500) + config.SetDefault("consensus.timeout_prevote", 1000) + config.SetDefault("consensus.timeout_prevote_delta", 500) + config.SetDefault("consensus.timeout_precommit", 1000) + config.SetDefault("consensus.timeout_precommit_delta", 500) + config.SetDefault("consensus.timeout_commit", 1000) // make progress asap (no `timeout_commit`) on full precommit votes - config.SetDefault("skip_timeout_commit", false) - config.SetDefault("mempool_recheck", true) - config.SetDefault("mempool_recheck_empty", true) - config.SetDefault("mempool_broadcast", true) - config.SetDefault("mempool_wal_dir", rootDir+"/data/mempool.wal") + config.SetDefault("consensus.skip_timeout_commit", false) + config.SetDefault("mempool.recheck", true) + config.SetDefault("mempool.recheck_empty", true) + config.SetDefault("mempool.broadcast", true) + config.SetDefault("mempool.wal_dir", rootDir+"/data/mempool.wal") - config.SetDefault("tx_index", "kv") + config.SetDefault("db.tx_index", "kv") return config } diff --git a/config/tendermint/types.go b/config/tendermint/types.go new file mode 100644 index 000000000..7f0d421d8 --- /dev/null +++ b/config/tendermint/types.go @@ -0,0 +1,89 @@ +package tendermint + +type Config struct { + Node NodeConfig `mapstructure:"node"` + Chain ChainConfig `mapstructure:"chain"` + ABCI ABCIConfig `mapstructure:"abci"` + Network NetworkConfig `mapstructure:"network"` + Blockchain BlockchainConfig `mapstructure:"blockchain"` + Consensus ConsensusConfig `mapstructure:"consensus"` + Block BlockConfig `mapstructure:"block"` + Mempool MempoolConfig `mapstructure:"mempool"` + RPC RPCConfig `mapstructure:"rpc"` + DB DBConfig `mapstructure:"db"` +} + +type NodeConfig struct { + Moniker string `mapstructure:"moniker"` // "anonymous" + PrivValidatorFile string `mapstructure:"priv_validator_file"` // rootDir+"/priv_validator.json") + + LogLevel string `mapstructure:"log_level"` // info + ProfListenAddr string `mapstructure:"prof_laddr"` // "" +} + +type ChainConfig struct { + ChainID string `mapstructure:"chain_id"` + GenesisFile string `mapstructure:"genesis_file"` // rootDir/genesis.json +} + +type ABCIConfig struct { + ProxyApp string `mapstructure:"proxy_app"` // tcp://0.0.0.0:46658 + Mode string `mapstructure:"mode"` // socket + + FilterPeers bool `mapstructure:"filter_peers"` // false +} + +type NetworkConfig struct { + ListenAddr string `mapstructure:"listen_adddr"` // "tcp://0.0.0.0:46656") + Seeds string `mapstructure:"seeds"` // []string ... + SkipUPNP bool `mapstructure:"skip_upnp"` + AddrBookFile string `mapstructure:"addr_book_file"` // rootDir+"/addrbook.json") + AddrBookString bool `mapstructure:"addr_book_string"` // true + PexReactor bool `mapstructure:"pex_reactor"` // false +} + +type BlockchainConfig struct { + FastSync bool `mapstructure:"fast_sync"` // true +} + +type ConsensusConfig struct { + WalFile string `mapstructure:"wal_file"` //rootDir+"/data/cs.wal/wal") + WalLight bool `mapstructure:"wal_light"` // false + + // all timeouts are in ms + TimeoutPropose int `mapstructure:"timeout_propose"` // 3000 + TimeoutProposeDelta int `mapstructure:"timeout_propose_delta"` // 500 + TimeoutPrevote int `mapstructure:"timeout_prevote"` // 1000 + TimeoutPrevoteDelta int `mapstructure:"timeout_prevote_delta"` // 500 + TimeoutPrecommit int `mapstructure:"timeout_precommit"` // 1000 + TimeoutPrecommitDelta int `mapstructure:"timeout_precommit_delta"` // 500 + TimeoutCommit int `mapstructure:"timeout_commit"` // 1000 + + // make progress asap (no `timeout_commit`) on full precommit votes + SkipTimeoutCommit bool `mapstructure:"skip_timeout_commit"` // false +} + +type BlockConfig struct { + MaxTxs int `mapstructure:"max_txs"` // 10000 + PartSize int `mapstructure:"part_size"` // 65536 + DisableDataHash bool `mapstructure:"disable_data_hash"` // false +} + +type MempoolConfig struct { + Recheck bool `mapstructure:"recheck"` // true + RecheckEmpty bool `mapstructure:"recheck_empty"` // true + Broadcast bool `mapstructure:"broadcast"` // true + WalDir string `mapstructure:"wal_dir"` // rootDir+"/data/mempool.wal") +} + +type RPCConfig struct { + RPCListenAddress string `mapstructure:"rpc_listen_addr"` // "tcp://0.0.0.0:46657") + GRPCListenAddress string `mapstructure:"grpc_listen_addr"` // "" +} + +type DBConfig struct { + Backend string `mapstructure:"backend"` // leveldb + Dir string `mapstructure:"dir"` // rootDir/data + + TxIndex string `mapstructure:"tx_index"` // "kv" +} diff --git a/node/node.go b/node/node.go index 764c89b87..c4000a1fe 100644 --- a/node/node.go +++ b/node/node.go @@ -13,6 +13,7 @@ import ( crypto "github.com/tendermint/go-crypto" wire "github.com/tendermint/go-wire" bc "github.com/tendermint/tendermint/blockchain" + tmcfg "github.com/tendermint/tendermint/config/tendermint" "github.com/tendermint/tendermint/consensus" mempl "github.com/tendermint/tendermint/mempool" p2p "github.com/tendermint/tendermint/p2p" @@ -67,21 +68,26 @@ func NewNodeDefault(config *viper.Viper) *Node { config.GetString("abci"), config.GetString("db_dir"), )) + // config.ABCI.ProxyApp, config.ABCI.Mode, config.DB.Dir)) } func NewNode(config *viper.Viper, privValidator *types.PrivValidator, clientCreator proxy.ClientCreator) *Node { + tmConfig := new(tmcfg.Config) + if err := config.Unmarshal(tmConfig); err != nil { + panic(err) + } + // Get BlockStore - blockStoreDB := dbm.NewDB("blockstore", config.GetString("db_backend"), config.GetString("db_dir")) + blockStoreDB := dbm.NewDB("blockstore", tmConfig.DB.Backend, tmConfig.DB.Dir) blockStore := bc.NewBlockStore(blockStoreDB) // Get State - stateDB := dbm.NewDB("state", config.GetString("db_backend"), config.GetString("db_dir")) - state := sm.GetState(stateDB, config.GetString("genesis_file")) + stateDB := dbm.NewDB("state", tmConfig.DB.Backend, tmConfig.DB.Dir) + state := sm.GetState(stateDB, tmConfig.Chain.GenesisFile) // add the chainid and number of validators to the global config config.Set("chain_id", state.ChainID) - config.Set("num_vals", state.Validators.Size()) // Create the proxyApp, which manages connections (consensus, mempool, query) // and sync tendermint and the app by replaying any necessary blocks @@ -95,9 +101,9 @@ func NewNode(config *viper.Viper, privValidator *types.PrivValidator, clientCrea // Transaction indexing var txIndexer txindex.TxIndexer - switch config.GetString("tx_index") { + switch tmConfig.DB.TxIndex { case "kv": - store := dbm.NewDB("tx_index", config.GetString("db_backend"), config.GetString("db_dir")) + store := dbm.NewDB("tx_index", tmConfig.DB.Backend, tmConfig.DB.Dir) txIndexer = kv.NewTxIndex(store) default: txIndexer = &null.TxIndex{}