mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-12 04:41:22 +00:00
86 lines
3.2 KiB
Go
86 lines
3.2 KiB
Go
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
cfg "github.com/tendermint/tendermint/config"
|
|
"github.com/tendermint/tendermint/node"
|
|
"github.com/tendermint/tendermint/proxy"
|
|
"github.com/tendermint/tendermint/types"
|
|
)
|
|
|
|
// 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")
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// 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.
|
|
func NewRunNodeCmd(signerAndApp FuncSignerAndApp) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
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
|
|
privVal, clientCreator := signerAndApp(config)
|
|
n := node.NewNode(config, privVal, clientCreator, logger.With("module", "node"))
|
|
|
|
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
|
|
},
|
|
}
|
|
|
|
AddNodeFlags(cmd)
|
|
return cmd
|
|
}
|