OSDN Git Service

Removed validate.config. and Modified config.
authorgguoss <1536310027@qq.com>
Tue, 29 Aug 2017 08:35:09 +0000 (16:35 +0800)
committergguoss <1536310027@qq.com>
Tue, 29 Aug 2017 08:35:09 +0000 (16:35 +0800)
cmd/bytom/commands/init.go
cmd/bytom/commands/run_node.go
config/config.go
config/config_test.go
config/toml.go
node/node.go
types/genesis.go

index 5ca80da..bcd6b89 100644 (file)
@@ -9,7 +9,7 @@ import (
        cmn "github.com/tendermint/tmlibs/common"
 )
 
-var initFilesCmd = &cobra.Command{
+var initFilesCmd = &cobra.Command {
        Use:   "init",
        Short: "Initialize blockchain",
        Run:   initFiles,
@@ -20,28 +20,15 @@ func init() {
 }
 
 func initFiles(cmd *cobra.Command, args []string) {
-       privValFile := config.PrivValidatorFile()
-       if _, err := os.Stat(privValFile); os.IsNotExist(err) {
-               privValidator := types.GenPrivValidator()
-               privValidator.SetFile(privValFile)
-               privValidator.Save()
-
-               genFile := config.GenesisFile()
-
-               if _, err := os.Stat(genFile); os.IsNotExist(err) {
-                       genDoc := types.GenesisDoc{
-                               ChainID: cmn.Fmt("chain0"),
-                       }
-                       genDoc.Validators = []types.GenesisValidator{types.GenesisValidator{
-                               PubKey: privValidator.PubKey,
-                               Amount: 10,
-                       }}
-
-                       genDoc.SaveAs(genFile)
+       genFile := config.GenesisFile()
+
+       if _, err := os.Stat(genFile); os.IsNotExist(err) {
+               genDoc := types.GenesisDoc{
+                       ChainID: cmn.Fmt("bytom"),
                }
 
-               logger.Info("Initialized tendermint", "genesis", config.GenesisFile(), "priv_validator", config.PrivValidatorFile())
-       } else {
-               logger.Info("Already initialized", "priv_validator", config.PrivValidatorFile())
+               genDoc.SaveAs(genFile)
        }
+
+       logger.Info("Initialized bytom", "genesis", config.GenesisFile())
 }
index e8a288c..e1891b3 100644 (file)
@@ -30,10 +30,6 @@ func init() {
 
 func runNode(cmd *cobra.Command, args []string) error {
 
-       // Wait until the genesis doc becomes available
-       // This is for Mintnet compatibility.
-       // TODO: If Mintnet gets deprecated or genesis_file is
-       // always available, remove.
        genDocFile := config.GenesisFile()
        if !cmn.FileExists(genDocFile) {
                logger.Info(cmn.Fmt("Waiting for genesis file %v...", genDocFile))
index f75695d..ff7105d 100644 (file)
@@ -3,9 +3,9 @@ package config
 import (
        "fmt"
        "path/filepath"
-       "time"
+       //"time"
 
-       "github.com/bytom/types"
+       //"github.com/bytom/types"
 )
 
 type Config struct {
@@ -15,8 +15,6 @@ type Config struct {
        // Options for services
        RPC       *RPCConfig       `mapstructure:"rpc"`
        P2P       *P2PConfig       `mapstructure:"p2p"`
-       Mempool   *MempoolConfig   `mapstructure:"mempool"`
-       Consensus *ConsensusConfig `mapstructure:"consensus"`
 }
 
 func DefaultConfig() *Config {
@@ -24,8 +22,6 @@ func DefaultConfig() *Config {
                BaseConfig: DefaultBaseConfig(),
                RPC:        DefaultRPCConfig(),
                P2P:        DefaultP2PConfig(),
-               Mempool:    DefaultMempoolConfig(),
-               Consensus:  DefaultConsensusConfig(),
        }
 }
 
@@ -34,8 +30,6 @@ func TestConfig() *Config {
                BaseConfig: TestBaseConfig(),
                RPC:        TestRPCConfig(),
                P2P:        TestP2PConfig(),
-               Mempool:    DefaultMempoolConfig(),
-               Consensus:  TestConsensusConfig(),
        }
 }
 
@@ -44,15 +38,12 @@ func (cfg *Config) SetRoot(root string) *Config {
        cfg.BaseConfig.RootDir = root
        cfg.RPC.RootDir = root
        cfg.P2P.RootDir = root
-       cfg.Mempool.RootDir = root
-       cfg.Consensus.RootDir = root
        return cfg
 }
 
 //-----------------------------------------------------------------------------
 // BaseConfig
 
-// BaseConfig struct for a Tendermint node
 type BaseConfig struct {
        // The root directory for all data.
        // This should be set in viper so it can unmarshal into this struct
@@ -70,13 +61,6 @@ type BaseConfig struct {
        // A custom human readable name for this node
        Moniker string `mapstructure:"moniker"`
 
-       // TCP or UNIX socket address of the ABCI application,
-       // or the name of an ABCI application compiled in with the Tendermint binary
-       ProxyApp string `mapstructure:"proxy_app"`
-
-       // Mechanism to connect to the ABCI application: socket | grpc
-       ABCI string `mapstructure:"abci"`
-
        // Output level for logging
        LogLevel string `mapstructure:"log_level"`
 
@@ -88,8 +72,6 @@ type BaseConfig struct {
        // and verifying their commits
        FastSync bool `mapstructure:"fast_sync"`
 
-       // If true, query the ABCI app on connecting to a new peer
-       // so the app can decide if we should keep the connection or not
        FilterPeers bool `mapstructure:"filter_peers"` // false
 
        // What indexer to use for transactions
@@ -105,10 +87,7 @@ type BaseConfig struct {
 func DefaultBaseConfig() BaseConfig {
        return BaseConfig{
                Genesis:           "genesis.json",
-               PrivValidator:     "priv_validator.json",
                Moniker:           "anonymous",
-               ProxyApp:          "tcp://127.0.0.1:46658",
-               ABCI:              "socket",
                LogLevel:          DefaultPackageLogLevels(),
                ProfListenAddress: "",
                FastSync:          true,
@@ -121,8 +100,7 @@ func DefaultBaseConfig() BaseConfig {
 
 func TestBaseConfig() BaseConfig {
        conf := DefaultBaseConfig()
-       conf.ChainID = "tendermint_test"
-       conf.ProxyApp = "dummy"
+       conf.ChainID = "bytom_test"
        conf.FastSync = false
        conf.DBBackend = "memdb"
        return conf
@@ -132,10 +110,6 @@ func (b BaseConfig) GenesisFile() string {
        return rootify(b.Genesis, b.RootDir)
 }
 
-func (b BaseConfig) PrivValidatorFile() string {
-       return rootify(b.PrivValidator, b.RootDir)
-}
-
 func (b BaseConfig) DBDir() string {
        return rootify(b.DBPath, b.RootDir)
 }
@@ -216,124 +190,6 @@ func (p *P2PConfig) AddrBookFile() string {
 }
 
 //-----------------------------------------------------------------------------
-// MempoolConfig
-
-type MempoolConfig struct {
-       RootDir      string `mapstructure:"home"`
-       Recheck      bool   `mapstructure:"recheck"`
-       RecheckEmpty bool   `mapstructure:"recheck_empty"`
-       Broadcast    bool   `mapstructure:"broadcast"`
-       WalPath      string `mapstructure:"wal_dir"`
-}
-
-func DefaultMempoolConfig() *MempoolConfig {
-       return &MempoolConfig{
-               Recheck:      true,
-               RecheckEmpty: true,
-               Broadcast:    true,
-               WalPath:      "data/mempool.wal",
-       }
-}
-
-func (m *MempoolConfig) WalDir() string {
-       return rootify(m.WalPath, m.RootDir)
-}
-
-//-----------------------------------------------------------------------------
-// ConsensusConfig
-
-// ConsensusConfig holds timeouts and details about the WAL, the block structure,
-// and timeouts in the consensus protocol.
-type ConsensusConfig struct {
-       RootDir  string `mapstructure:"home"`
-       WalPath  string `mapstructure:"wal_file"`
-       WalLight bool   `mapstructure:"wal_light"`
-       walFile  string // overrides WalPath if set
-
-       // All timeouts are in ms
-       TimeoutPropose        int `mapstructure:"timeout_propose"`
-       TimeoutProposeDelta   int `mapstructure:"timeout_propose_delta"`
-       TimeoutPrevote        int `mapstructure:"timeout_prevote"`
-       TimeoutPrevoteDelta   int `mapstructure:"timeout_prevote_delta"`
-       TimeoutPrecommit      int `mapstructure:"timeout_precommit"`
-       TimeoutPrecommitDelta int `mapstructure:"timeout_precommit_delta"`
-       TimeoutCommit         int `mapstructure:"timeout_commit"`
-
-       // Make progress as soon as we have all the precommits (as if TimeoutCommit = 0)
-       SkipTimeoutCommit bool `mapstructure:"skip_timeout_commit"`
-
-       // BlockSize
-       MaxBlockSizeTxs   int `mapstructure:"max_block_size_txs"`
-       MaxBlockSizeBytes int `mapstructure:"max_block_size_bytes"`
-
-       // TODO: This probably shouldn't be exposed but it makes it
-       // easy to write tests for the wal/replay
-       BlockPartSize int `mapstructure:"block_part_size"`
-}
-
-// Wait this long for a proposal
-func (cfg *ConsensusConfig) Propose(round int) time.Duration {
-       return time.Duration(cfg.TimeoutPropose+cfg.TimeoutProposeDelta*round) * time.Millisecond
-}
-
-// After receiving any +2/3 prevote, wait this long for stragglers
-func (cfg *ConsensusConfig) Prevote(round int) time.Duration {
-       return time.Duration(cfg.TimeoutPrevote+cfg.TimeoutPrevoteDelta*round) * time.Millisecond
-}
-
-// After receiving any +2/3 precommits, wait this long for stragglers
-func (cfg *ConsensusConfig) Precommit(round int) time.Duration {
-       return time.Duration(cfg.TimeoutPrecommit+cfg.TimeoutPrecommitDelta*round) * time.Millisecond
-}
-
-// After receiving +2/3 precommits for a single block (a commit), wait this long for stragglers in the next height's RoundStepNewHeight
-func (cfg *ConsensusConfig) Commit(t time.Time) time.Time {
-       return t.Add(time.Duration(cfg.TimeoutCommit) * time.Millisecond)
-}
-
-func DefaultConsensusConfig() *ConsensusConfig {
-       return &ConsensusConfig{
-               WalPath:               "data/cs.wal/wal",
-               WalLight:              false,
-               TimeoutPropose:        3000,
-               TimeoutProposeDelta:   500,
-               TimeoutPrevote:        1000,
-               TimeoutPrevoteDelta:   500,
-               TimeoutPrecommit:      1000,
-               TimeoutPrecommitDelta: 500,
-               TimeoutCommit:         1000,
-               SkipTimeoutCommit:     false,
-               MaxBlockSizeTxs:       10000,
-               MaxBlockSizeBytes:     1,                          // TODO
-               BlockPartSize:         types.DefaultBlockPartSize, // TODO: we shouldnt be importing types
-       }
-}
-
-func TestConsensusConfig() *ConsensusConfig {
-       config := DefaultConsensusConfig()
-       config.TimeoutPropose = 2000
-       config.TimeoutProposeDelta = 1
-       config.TimeoutPrevote = 10
-       config.TimeoutPrevoteDelta = 1
-       config.TimeoutPrecommit = 10
-       config.TimeoutPrecommitDelta = 1
-       config.TimeoutCommit = 10
-       config.SkipTimeoutCommit = true
-       return config
-}
-
-func (c *ConsensusConfig) WalFile() string {
-       if c.walFile != "" {
-               return c.walFile
-       }
-       return rootify(c.WalPath, c.RootDir)
-}
-
-func (c *ConsensusConfig) SetWalFile(walFile string) {
-       c.walFile = walFile
-}
-
-//-----------------------------------------------------------------------------
 // Utils
 
 // helper function to make config creation independent of root dir
index 6379960..673b4a4 100644 (file)
@@ -12,17 +12,13 @@ func TestDefaultConfig(t *testing.T) {
        // set up some defaults
        cfg := DefaultConfig()
        assert.NotNil(cfg.P2P)
-       assert.NotNil(cfg.Mempool)
-       assert.NotNil(cfg.Consensus)
 
        // check the root dir stuff...
        cfg.SetRoot("/foo")
        cfg.Genesis = "bar"
        cfg.DBPath = "/opt/data"
-       cfg.Mempool.WalPath = "wal/mem/"
 
        assert.Equal("/foo/bar", cfg.GenesisFile())
        assert.Equal("/opt/data", cfg.DBDir())
-       assert.Equal("/foo/wal/mem", cfg.Mempool.WalDir())
 
 }
index 4a5a353..1976e69 100644 (file)
@@ -28,7 +28,6 @@ func EnsureRoot(rootDir string) {
 var defaultConfigTmpl = `# This is a TOML config file.
 # For more information, see https://github.com/toml-lang/toml
 
-proxy_app = "tcp://127.0.0.1:46658"
 moniker = "__MONIKER__"
 fast_sync = true
 db_backend = "leveldb"
@@ -91,7 +90,6 @@ func ResetTestRoot(testName string) *Config {
 var testConfigTmpl = `# This is a TOML config file.
 # For more information, see https://github.com/toml-lang/toml
 
-proxy_app = "dummy"
 moniker = "__MONIKER__"
 fast_sync = false
 db_backend = "memdb"
index dd77f25..a6ad390 100644 (file)
@@ -49,7 +49,6 @@ type Node struct {
 
        // config
        config        *cfg.Config
-       privValidator *types.PrivValidator // local node's validator key
 
        // network
        privKey  crypto.PrivKeyEd25519 // local node's p2p key
@@ -89,9 +88,7 @@ var (
 
 
 func NewNodeDefault(config *cfg.Config, logger log.Logger) *Node {
-       // Get PrivValidator
-       privValidator := types.LoadOrGenPrivValidator(config.PrivValidatorFile(), logger)
-       return NewNode(config, privValidator, logger)
+       return NewNode(config, logger)
 }
 
 func RedirectHandler(next http.Handler) http.Handler {
@@ -160,7 +157,7 @@ func rpcInit(h *bc.BlockchainReactor) {
        coreHandler.Set(h)
 }
 
-func NewNode(config *cfg.Config, privValidator *types.PrivValidator, logger log.Logger) *Node {
+func NewNode(config *cfg.Config, logger log.Logger) *Node {
        // Get store
     tx_db := dbm.NewDB("txdb", config.DBBackend, config.DBDir())
     store := txdb.NewStore(tx_db)
@@ -238,7 +235,6 @@ func NewNode(config *cfg.Config, privValidator *types.PrivValidator, logger log.
 
        node := &Node{
                config:        config,
-               privValidator: privValidator,
 
                privKey:  privKey,
                sw:       sw,
@@ -331,7 +327,6 @@ func (n *Node) ConfigureRPC() {
        //rpccore.SetConsensusState(n.consensusState)
        //rpccore.SetMempool(n.mempoolReactor.Mempool)
        rpccore.SetSwitch(n.sw)
-       //rpccore.SetPubKey(n.privValidator.PubKey)
        //rpccore.SetGenesisDoc(n.genesisDoc)
        rpccore.SetAddrBook(n.addrBook)
        //rpccore.SetProxyAppQuery(n.proxyApp.Query())
@@ -383,11 +378,6 @@ func (n *Node) EventSwitch() types.EventSwitch {
        return n.evsw
 }
 
-// XXX: for convenience
-func (n *Node) PrivValidator() *types.PrivValidator {
-       return n.privValidator
-}
-
 func (n *Node) makeNodeInfo() *p2p.NodeInfo {
        nodeInfo := &p2p.NodeInfo{
                PubKey:  n.privKey.PubKey().Unwrap().(crypto.PubKeyEd25519),
index 75999f6..23d439e 100644 (file)
@@ -26,7 +26,7 @@ type GenesisValidator struct {
 type GenesisDoc struct {
        GenesisTime time.Time          `json:"genesis_time"`
        ChainID     string             `json:"chain_id"`
-       Validators  []GenesisValidator `json:"validators"`
+//     Validators  []GenesisValidator `json:"validators"`
        AppHash     data.Bytes         `json:"app_hash"`
 }