github.com/lazyledger/lazyledger-core@v0.35.0-dev.0.20210613111200-4c651f053571/abci/example/dummyapp/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 "time" 8 9 dummy "github.com/lazyledger/lazyledger-core/abci/example/dummyapp/app" 10 cmd "github.com/lazyledger/lazyledger-core/cmd/tendermint/commands" 11 "github.com/lazyledger/lazyledger-core/cmd/tendermint/commands/debug" 12 cfg "github.com/lazyledger/lazyledger-core/config" 13 "github.com/lazyledger/lazyledger-core/ipfs" 14 "github.com/lazyledger/lazyledger-core/libs/cli" 15 "github.com/lazyledger/lazyledger-core/libs/log" 16 "github.com/lazyledger/lazyledger-core/node" 17 "github.com/lazyledger/lazyledger-core/p2p" 18 "github.com/lazyledger/lazyledger-core/privval" 19 "github.com/lazyledger/lazyledger-core/proxy" 20 ) 21 22 var ( 23 randTxs uint32 24 txSize uint32 25 msgSize uint32 26 randMsgs uint32 27 28 sleepDuringPreprocess time.Duration 29 30 runNodeCmd = cmd.NewRunNodeCmd(DummyNode) 31 ) 32 33 func init() { 34 runNodeCmd.Short = "Run dummyapp" 35 36 runNodeCmd.PersistentFlags().DurationVar( 37 &sleepDuringPreprocess, 38 "dummy.sleep", 250*time.Millisecond, 39 "duration to sleep during preprocess phase, e.g. 500ms, 1s") 40 41 runNodeCmd.PersistentFlags().Uint32Var(&randTxs, "dummy.txs", 10, "generate random transactions") 42 runNodeCmd.PersistentFlags().Uint32Var(&txSize, "dummy.tx-size", 50, "size of random transactions") 43 44 runNodeCmd.PersistentFlags().Uint32Var(&randMsgs, "dummy.msgs", 16, "generate random messages") 45 runNodeCmd.PersistentFlags().Uint32Var(&msgSize, "dummy.msg-size", 128, "size of random messages") 46 } 47 48 func main() { 49 // copy of the tendermint rootCmd 50 rootCmd := *cmd.RootCmd 51 rootCmd.Use = "dummyapp" 52 rootCmd.Short = "Simple KVStore running tendermint and optionally generating random data for testing" 53 rootCmd.AddCommand( 54 cmd.GenValidatorCmd, 55 cmd.InitFilesCmd, 56 cmd.ProbeUpnpCmd, 57 cmd.LightCmd, 58 cmd.ReplayCmd, 59 cmd.ReplayConsoleCmd, 60 cmd.ResetAllCmd, 61 cmd.ResetPrivValidatorCmd, 62 cmd.ShowValidatorCmd, 63 cmd.TestnetFilesCmd, 64 cmd.ShowNodeIDCmd, 65 cmd.GenNodeKeyCmd, 66 cmd.VersionCmd, 67 debug.DebugCmd, 68 cli.NewCompletionCmd(&rootCmd, true), 69 ) 70 71 // Create & start node 72 rootCmd.AddCommand(runNodeCmd) 73 74 cmd := cli.PrepareBaseCmd(&rootCmd, "TM", os.ExpandEnv(filepath.Join("$HOME", cfg.DefaultTendermintDir))) 75 if err := cmd.Execute(); err != nil { 76 panic(err) 77 } 78 } 79 80 // DummyNode implements NodeProvider. 81 func DummyNode(config *cfg.Config, ipfs ipfs.APIProvider, logger log.Logger) (*node.Node, error) { 82 nodeKey, err := p2p.LoadOrGenNodeKey(config.NodeKeyFile()) 83 if err != nil { 84 return nil, fmt.Errorf("failed to load or gen node key %s: %w", config.NodeKeyFile(), err) 85 } 86 87 pval, err := privval.LoadOrGenFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile()) 88 if err != nil { 89 return nil, err 90 } 91 app := dummy.NewApplication( 92 dummy.RandMessagesOnPreprocess(randTxs, txSize, randMsgs, msgSize), 93 dummy.SleepDuration(sleepDuringPreprocess), 94 ) 95 96 return node.NewNode(config, 97 pval, 98 nodeKey, 99 proxy.NewLocalClientCreator(app), 100 node.DefaultGenesisDocProviderFunc(config), 101 node.DefaultDBProvider, 102 ipfs, 103 node.DefaultMetricsProvider(config.Instrumentation), 104 logger, 105 ) 106 }