func (s *stresser) Stress() error { c := client.NewClientURI(fmt.Sprintf("http://%s", s.Endpoint)) for i := 0; i < s.N; i++ { // go func() { for { key := fmt.Sprintf("foo%d", rand.Intn(s.KeySuffixRange)) val := randStr(s.KeySize) txString := key + val var result ctypes.TMResult params := map[string]interface{}{ "tx": hex.EncodeToString([]byte(txString)), } _, err := c.Call("broadcast_tx", params, &result) // TODO: something smarter that waits for these txs to be confirmed s.mu.Lock() if err != nil { s.failure++ } else { s.success++ } s.mu.Unlock() } // }() } // <-ctx.Done() return nil }
func NewEthereumApplication(ctx *cli.Context) *EthereumApplication { cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx) ethereum, err := eth.New(cfg) if err != nil { utils.Fatalf("%v", err) } stateDB, err := ethereum.BlockChain().State() if err != nil { utils.Fatalf("%v", err) } ethApp := &EthereumApplication{ ethereum: ethereum, stateDB: stateDB, client: client.NewClientURI(fmt.Sprintf("http://%s", ctx.String(TendermintCoreHostFlag.Name))), } // NOTE: RPC/IPC should only be enabled on local nodes if !ctx.GlobalBool(utils.IPCDisabledFlag.Name) { if err := ethApp.StartIPC(ctx); err != nil { utils.Fatalf("%v", err) } } if ctx.GlobalBool(utils.RPCEnabledFlag.Name) { if err := ethApp.StartRPC(ctx); err != nil { utils.Fatalf("%v", err) } } return ethApp }
func dialSeeds(rpcAddr string, seeds []string) error { var result ctypes.TMResult c := client.NewClientURI(fmt.Sprintf("%s", rpcAddr)) args := map[string]interface{}{"seeds": seeds} _, err := c.Call("dial_seeds", args, &result) if err != nil { return errors.New("Error dialing seeds at rpc address " + rpcAddr) } return nil }
func NewETCDApplication(ctx *cli.Context) *ETCDApplication { // TODO... etcdApp := &ETCDApplication{ client: client.NewClientURI(fmt.Sprintf("http://%s", ctx.String(TendermintCoreHostFlag.Name))), } // TODO: Start RPC server, etc. return etcdApp }
// Start a new event meter, including the websocket connection // Also create the http rpc client for convenienve func (vs *ValidatorState) Start() error { // we need the lock because RPCAddr can be updated concurrently vs.Config.mtx.Lock() rpcAddr := vs.Config.RPCAddr vs.Config.mtx.Unlock() em := eventmeter.NewEventMeter(rpcAddr, UnmarshalEvent) if _, err := em.Start(); err != nil { return err } vs.em = em vs.client = client.NewClientURI(fmt.Sprintf("http://%s", rpcAddr)) return nil }
// initialize config and create new node func init() { chainID = config.GetString("chain_id") rpcAddr = config.GetString("rpc_laddr") requestAddr = "http://" + rpcAddr websocketAddr = "ws://" + rpcAddr + "/websocket" clientURI = client.NewClientURI(requestAddr) clientJSON = client.NewClientJSONRPC(requestAddr) // TODO: change consensus/state.go timeouts to be shorter // start a node ready := make(chan struct{}) go newNode(ready) <-ready }
// initialize config and create new node func init() { config = tendermint_test.ResetConfig("rpc_test_client_test") chainID = config.GetString("chain_id") rpcAddr = config.GetString("rpc_laddr") requestAddr = rpcAddr websocketAddr = rpcAddr websocketEndpoint = "/websocket" clientURI = client.NewClientURI(requestAddr) clientJSON = client.NewClientJSONRPC(requestAddr) // TODO: change consensus/state.go timeouts to be shorter // start a node ready := make(chan struct{}) go newNode(ready) <-ready }
func startTMCore(mach, app string, seeds []string, randomPort, noTMSP bool, image string) (*CoreInfo, error) { portString := "-p 46656:46656 -p 46657:46657" if randomPort { portString = "--publish-all" } // IF APP-USE-TCP // proxyApp := Fmt("tcp://%v_tmapp:46658", app) // tmspConditions := Fmt(` --link %v_tmapp `, app) // ELSE proxyApp := "unix:///data/tendermint/app/app.sock" tmspConditions := "" // END if noTMSP { proxyApp = "nilapp" // in-proc nil app tmspConditions = "" // tmcommon and tmapp weren't started } tmRoot := "/data/tendermint/core" args := []string{"ssh", mach, Fmt(`docker run -d %v --name %v_tmcore --volumes-from %v_tmcommon %v`+ `-e TMNAME="%v" -e TMSEEDS="%v" -e TMROOT="%v" -e PROXYAPP="%v" `+ `%v /data/tendermint/core/init.sh`, portString, app, app, tmspConditions, eB(mach), eB(strings.Join(seeds, ",")), tmRoot, eB(proxyApp), image)} if !runProcess("start-tmcore-"+mach, "docker-machine", args, true) { return nil, errors.New("Failed to start tmcore on machine " + mach) } // Give it some time to install and make repo. time.Sleep(time.Second * 10) // Get the node's validator info // Need to retry to wait until tendermint is installed for { args = []string{"ssh", mach, Fmt(`docker exec %v_tmcore tendermint show_validator --log_level=error`, app)} output, ok := runProcessGetResult("show-validator-tmcore-"+mach, "docker-machine", args, false) if !ok || output == "" { fmt.Println(Yellow(Fmt("tendermint not yet installed in %v. Waiting...", mach))) time.Sleep(time.Second * 5) continue } else { fmt.Println(Fmt("validator for %v: %v", mach, output)) // now grab the node's public address and port ip, err := getMachineIP(mach) if err != nil { return nil, err } coreInfo := &CoreInfo{ Validator: &Validator{ ID: mach, }, } var p2pPort, rpcPort = "46656", "46657" if randomPort { portMap, err := getContainerPortMap(mach, fmt.Sprintf("%v_tmcore", app)) if err != nil { return nil, err } p2pPort, ok = portMap["46656"] if !ok { return nil, errors.New("No port map found for p2p port 46656 on mach " + mach) } rpcPort, ok = portMap["46657"] if !ok { return nil, errors.New("No port map found for rpc port 46657 on mach " + mach) } } coreInfo.P2PAddr = fmt.Sprintf("%v:%v", ip, p2pPort) coreInfo.RPCAddr = fmt.Sprintf("%v:%v", ip, rpcPort) // get pubkey from rpc endpoint // try a few times in case the rpc server is slow to start var result ctypes.TMResult for i := 0; i < 10; i++ { time.Sleep(time.Second) c := client.NewClientURI(fmt.Sprintf("%s", coreInfo.RPCAddr)) if _, err = c.Call("status", nil, &result); err != nil { fmt.Println(Yellow(Fmt("Error getting rpc status for %v: %v", coreInfo.RPCAddr, err))) continue } status := result.(*ctypes.ResultStatus) coreInfo.Validator.PubKey = status.PubKey break } if err != nil { return nil, fmt.Errorf("Error getting PubKey from mach %s on %s: %v", mach, coreInfo.RPCAddr, err) } return coreInfo, nil } } return nil, nil }