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-21 17:08:17 -04:00
nm "github.com/tendermint/tendermint/node"
2017-01-15 16:59:10 -08:00
)
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" )
2018-01-04 19:51:27 -05:00
// priv val flags
2018-02-28 09:35:52 -05:00
cmd . Flags ( ) . String ( "priv_validator_laddr" , config . PrivValidatorListenAddr , "Socket address to listen on for connections from external priv_validator process" )
2018-01-04 19:51:27 -05:00
2017-09-13 00:18:07 +02:00
// node flags
cmd . Flags ( ) . Bool ( "fast_sync" , config . FastSync , "Fast blockchain syncing" )
// abci flags
2018-02-27 14:01:10 +00:00
cmd . Flags ( ) . String ( "proxy_app" , config . ProxyApp , "Proxy app address, or 'nilapp' or 'kvstore' for local testing." )
2017-09-13 00:18:07 +02:00
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)" )
2018-03-07 12:14:53 +04:00
cmd . Flags ( ) . String ( "p2p.seeds" , config . P2P . Seeds , "Comma-delimited ID@host:port seed nodes" )
cmd . Flags ( ) . String ( "p2p.persistent_peers" , config . P2P . PersistentPeers , "Comma-delimited ID@host:port persistent peers" )
2017-09-13 00:18:07 +02:00
cmd . Flags ( ) . Bool ( "p2p.skip_upnp" , config . P2P . SkipUPNP , "Skip UPNP configuration" )
2017-12-11 14:37:57 -05:00
cmd . Flags ( ) . Bool ( "p2p.pex" , config . P2P . PexReactor , "Enable/disable Peer-Exchange" )
2018-02-08 17:20:55 +04:00
cmd . Flags ( ) . Bool ( "p2p.seed_mode" , config . P2P . SeedMode , "Enable/disable seed mode" )
2018-03-07 12:14:53 +04:00
cmd . Flags ( ) . String ( "p2p.private_peer_ids" , config . P2P . PrivatePeerIDs , "Comma-delimited private peer IDs" )
2017-09-13 00:18:07 +02:00
// 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" )
}
2018-03-26 23:27:20 +09:00
// NewRunNodeCmd returns the command that allows the CLI to start a node.
// It can be used with a custom PrivValidator and in-process ABCI application.
2017-09-21 21:44:36 -04:00
func NewRunNodeCmd ( nodeProvider nm . NodeProvider ) * 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 {
// Create & start node
2017-09-21 21:44:36 -04:00
n , err := nodeProvider ( config , logger )
2017-09-20 18:29:36 -04:00
if err != nil {
return fmt . Errorf ( "Failed to create node: %v" , err )
}
2017-09-13 00:18:07 +02:00
2017-11-06 13:20:39 -05:00
if err := n . Start ( ) ; err != nil {
2017-08-31 10:34:45 +02:00
return fmt . Errorf ( "Failed to start node: %v" , err )
}
2018-04-02 10:21:17 +02:00
logger . Info ( "Started node" , "nodeInfo" , n . Switch ( ) . NodeInfo ( ) )
2017-08-31 10:34:45 +02:00
// 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
}