2017-02-23 00:21:13 -05:00
package commands
2017-01-15 16:59:10 -08:00
import (
2017-04-15 16:40:52 -04:00
"fmt"
2017-01-15 16:59:10 -08:00
2017-02-23 00:21:13 -05:00
"github.com/spf13/cobra"
2017-09-18 17:40:24 -04:00
cfg "github.com/tendermint/tendermint/config"
2017-01-15 16:59:10 -08:00
"github.com/tendermint/tendermint/node"
2017-08-31 10:34:45 +02:00
"github.com/tendermint/tendermint/proxy"
2017-01-15 16:59:10 -08:00
"github.com/tendermint/tendermint/types"
)
2017-09-13 00:18:07 +02:00
// AddNodeFlags exposes some common configuration options on the command-line
// These are exposed for convenience of commands embedding a tendermint node
func AddNodeFlags ( cmd * cobra . Command ) {
// bind flags
cmd . Flags ( ) . String ( "moniker" , config . Moniker , "Node Name" )
// node flags
cmd . Flags ( ) . Bool ( "fast_sync" , config . FastSync , "Fast blockchain syncing" )
// abci flags
cmd . Flags ( ) . String ( "proxy_app" , config . ProxyApp , "Proxy app address, or 'nilapp' or 'dummy' for local testing." )
cmd . Flags ( ) . String ( "abci" , config . ABCI , "Specify abci transport (socket | grpc)" )
// rpc flags
cmd . Flags ( ) . String ( "rpc.laddr" , config . RPC . ListenAddress , "RPC listen address. Port required" )
cmd . Flags ( ) . String ( "rpc.grpc_laddr" , config . RPC . GRPCListenAddress , "GRPC listen address (BroadcastTx only). Port required" )
cmd . Flags ( ) . Bool ( "rpc.unsafe" , config . RPC . Unsafe , "Enabled unsafe rpc methods" )
// p2p flags
cmd . Flags ( ) . String ( "p2p.laddr" , config . P2P . ListenAddress , "Node listen address. (0.0.0.0:0 means any interface, any port)" )
cmd . Flags ( ) . String ( "p2p.seeds" , config . P2P . Seeds , "Comma delimited host:port seed nodes" )
cmd . Flags ( ) . Bool ( "p2p.skip_upnp" , config . P2P . SkipUPNP , "Skip UPNP configuration" )
cmd . Flags ( ) . Bool ( "p2p.pex" , config . P2P . PexReactor , "Enable Peer-Exchange (dev feature)" )
// consensus flags
cmd . Flags ( ) . Bool ( "consensus.create_empty_blocks" , config . Consensus . CreateEmptyBlocks , "Set this to false to only produce blocks when there are txs or when the AppHash changes" )
}
2017-09-18 17:40:24 -04:00
// FuncSignerAndApp takes a config and returns a PrivValidator and ClientCreator.
// It allows other projects to make Tendermint binaries with custom signers and applications.
type FuncSignerAndApp func ( * cfg . Config ) ( * types . PrivValidator , proxy . ClientCreator )
func DefaultSignerAndApp ( config * cfg . Config ) ( * types . PrivValidator , proxy . ClientCreator ) {
privValidator := types . LoadOrGenPrivValidator ( config . PrivValidatorFile ( ) )
clientCreator := proxy . DefaultClientCreator ( config . ProxyApp , config . ABCI , config . DBDir ( ) )
return privValidator , clientCreator
}
2017-09-13 00:18:07 +02:00
// NewRunNodeCmd returns the command that allows the CLI to start a
2017-09-18 17:40:24 -04:00
// node. It can be used with a custom PrivValidator and in-process ABCI application.
func NewRunNodeCmd ( signerAndApp FuncSignerAndApp ) * cobra . Command {
2017-09-13 08:32:53 +02:00
cmd := & cobra . Command {
2017-08-31 10:34:45 +02:00
Use : "node" ,
Short : "Run the tendermint node" ,
RunE : func ( cmd * cobra . Command , args [ ] string ) error {
genDocFile := config . GenesisFile ( )
genDoc , err := types . GenesisDocFromFile ( genDocFile )
if err != nil {
return err
}
config . ChainID = genDoc . ChainID
// Create & start node
2017-09-18 17:40:24 -04:00
privVal , clientCreator := signerAndApp ( config )
n := node . NewNode ( config , privVal , clientCreator , logger . With ( "module" , "node" ) )
2017-09-13 00:18:07 +02:00
2017-08-31 10:34:45 +02:00
if _ , err := n . Start ( ) ; err != nil {
return fmt . Errorf ( "Failed to start node: %v" , err )
} else {
logger . Info ( "Started node" , "nodeInfo" , n . Switch ( ) . NodeInfo ( ) )
}
// Trap signal, run forever.
n . RunForever ( )
return nil
} ,
}
2017-09-13 08:32:53 +02:00
AddNodeFlags ( cmd )
return cmd
2017-08-31 10:34:45 +02:00
}