Browse Source

Integrate PrivValidator socket server

pull/1204/head
Alexander Simmerl 7 years ago
parent
commit
a14aab67de
4 changed files with 39 additions and 42 deletions
  1. +3
    -3
      cmd/priv_val_server/main.go
  2. +1
    -0
      cmd/tendermint/commands/run_node.go
  3. +21
    -15
      config/config.go
  4. +14
    -24
      node/node.go

+ 3
- 3
cmd/priv_val_server/main.go View File

@ -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,
)


+ 1
- 0
cmd/tendermint/commands/run_node.go View File

@ -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")


+ 21
- 15
config/config.go View File

@ -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",
}
}


+ 14
- 24
node/node.go View File

@ -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.


Loading…
Cancel
Save