diff --git a/cmd/priv_val_server/main.go b/cmd/priv_val_server/main.go index 25a8bd4c3..57c3355f9 100644 --- a/cmd/priv_val_server/main.go +++ b/cmd/priv_val_server/main.go @@ -14,7 +14,7 @@ func main() { var ( chainID = flag.String("chain-id", "mychain", "chain id") listenAddr = flag.String("laddr", ":46659", "Validator listen address (0.0.0.0:0 means any interface, any port") - maxClients = flag.Int("clients", 3, "number of concurrently connected clients") + maxConn = flag.Int("clients", 3, "maximum of concurrent connections") privValPath = flag.String("priv", "", "priv val file path") logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "priv_val") @@ -25,7 +25,7 @@ func main() { "Starting private validator", "chainID", *chainID, "listenAddr", *listenAddr, - "maxClients", *maxClients, + "maxConn", *maxConn, "privPath", *privValPath, ) @@ -35,7 +35,7 @@ func main() { logger, *chainID, *listenAddr, - *maxClients, + *maxConn, privVal, nil, ) diff --git a/cmd/tendermint/commands/run_node.go b/cmd/tendermint/commands/run_node.go index 619a94b1d..481aa0729 100644 --- a/cmd/tendermint/commands/run_node.go +++ b/cmd/tendermint/commands/run_node.go @@ -16,6 +16,7 @@ func AddNodeFlags(cmd *cobra.Command) { // priv val flags cmd.Flags().String("priv_validator_addr", config.PrivValidatorAddr, "Socket address for private validator") + cmd.Flags().Int("priv_validator_max_conn", config.PrivValidatorMaxConn, "Limit of concurrent connections to the PrivValidator") // node flags cmd.Flags().Bool("fast_sync", config.FastSync, "Fast blockchain syncing") diff --git a/config/config.go b/config/config.go index 6a882185f..bdafa7a62 100644 --- a/config/config.go +++ b/config/config.go @@ -20,9 +20,11 @@ var ( defaultConfigFileName = "config.toml" defaultGenesisJSONName = "genesis.json" - defaultPrivValName = "priv_validator.json" - defaultNodeKeyName = "node_key.json" - defaultAddrBookName = "addrbook.json" + + defaultPrivValName = "priv_validator.json" + defaultPrivValMaxConn = 3 + defaultNodeKeyName = "node_key.json" + defaultAddrBookName = "addrbook.json" defaultConfigFilePath = filepath.Join(defaultConfigDir, defaultConfigFileName) defaultGenesisJSONPath = filepath.Join(defaultConfigDir, defaultGenesisJSONName) @@ -106,6 +108,9 @@ type BaseConfig struct { // TCP or UNIX socket address of the PrivValidator server PrivValidatorAddr string `mapstructure:"priv_validator_addr"` + // Limit of concurrent connections to the PrivValidator. + PrivValidatorMaxConn int `mapstructure:"priv_validator_max_conn"` + // 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"` @@ -142,18 +147,19 @@ func (c BaseConfig) ChainID() string { // DefaultBaseConfig returns a default base configuration for a Tendermint node func DefaultBaseConfig() BaseConfig { return BaseConfig{ - Genesis: defaultGenesisJSONPath, - PrivValidator: defaultPrivValPath, - NodeKey: defaultNodeKeyPath, - Moniker: defaultMoniker, - ProxyApp: "tcp://127.0.0.1:46658", - ABCI: "socket", - LogLevel: DefaultPackageLogLevels(), - ProfListenAddress: "", - FastSync: true, - FilterPeers: false, - DBBackend: "leveldb", - DBPath: "data", + Genesis: defaultGenesisJSONPath, + PrivValidator: defaultPrivValPath, + PrivValidatorMaxConn: defaultPrivValMaxConn, + NodeKey: defaultNodeKeyPath, + Moniker: defaultMoniker, + ProxyApp: "tcp://127.0.0.1:46658", + ABCI: "socket", + LogLevel: DefaultPackageLogLevels(), + ProfListenAddress: "", + FastSync: true, + FilterPeers: false, + DBBackend: "leveldb", + DBPath: "data", } } diff --git a/node/node.go b/node/node.go index 64e8c02c1..4a0afd852 100644 --- a/node/node.go +++ b/node/node.go @@ -34,6 +34,7 @@ import ( "github.com/tendermint/tendermint/state/txindex/kv" "github.com/tendermint/tendermint/state/txindex/null" "github.com/tendermint/tendermint/types" + priv_val "github.com/tendermint/tendermint/types/priv_validator" "github.com/tendermint/tendermint/version" _ "net/http/pprof" @@ -77,20 +78,8 @@ type NodeProvider func(*cfg.Config, log.Logger) (*Node, error) // PrivValidator, ClientCreator, GenesisDoc, and DBProvider. // It implements NodeProvider. func DefaultNewNode(config *cfg.Config, logger log.Logger) (*Node, error) { - var privVal types.PrivValidator - privVal = types.LoadOrGenPrivValidatorFS(config.PrivValidatorFile()) - /* TODO - if config.PrivValidatorAddr != "" { - pvsc := priv_val.NewPrivValidatorSocketClient(logger.With("module", "priv_val"), - config.PrivValidatorAddr) - pvsc.Start() - privVal = pvsc - } - */ - fmt.Println("PRIV", config.PrivValidatorAddr) - return NewNode(config, - privVal, + types.LoadOrGenPrivValidatorFS(config.PrivValidatorFile()), proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()), DefaultGenesisDocProviderFunc(config), DefaultDBProvider, @@ -184,20 +173,21 @@ func NewNode(config *cfg.Config, // reload the state (it may have been updated by the handshake) state = sm.LoadState(stateDB) - /* TODO - // Generate node PrivKey - privKey := crypto.GenPrivKeyEd25519() - if config.PrivValidatorAddr != "" { - pvsc := priv_val.NewPrivValidatorSocketClient( - logger.With("module", "priv_val"), - config.PrivValidatorAddr, - &privKey, + var ( + privKey = crypto.GenPrivKeyEd25519() + pvss = priv_val.NewPrivValidatorSocketServer( + logger.With("module", "priv_val"), + config.ChainID(), + config.PrivValidatorAddr, + config.PrivValidatorMaxConn, + priv_val.LoadPrivValidatorJSON(config.PrivValidatorFile()), + &privKey, + ) ) - pvsc.Start() - privValidator = pvsc + + pvss.Start() } - */ // Decide whether to fast-sync or not // We don't fast-sync when the only validator is us.