fixes for tools repo merge (#1945)

fixes for tools repo merge (#1943)
This commit is contained in:
Zach 2018-07-10 16:42:27 -04:00 committed by GitHub
parent 44dad6d70b
commit 8ce588d984
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 186 additions and 312 deletions

View File

@ -98,6 +98,6 @@ Each route is available as a GET request, as a JSONRPCv2 POST request, and via J
# Examples
* [Tendermint](https://github.com/tendermint/tendermint/blob/master/rpc/core/routes.go)
* [tm-monitor](https://github.com/tendermint/tools/blob/master/tm-monitor/rpc.go)
* [tm-monitor](https://github.com/tendermint/tendermint/blob/master/tools/tm-monitor/rpc.go)
*/
package rpc

View File

@ -1,12 +1,12 @@
FROM golang:latest
RUN mkdir -p /go/src/github.com/tendermint/tools/tm-bench
WORKDIR /go/src/github.com/tendermint/tools/tm-bench
RUN mkdir -p /go/src/github.com/tendermint/tendermint/tools/tm-bench
WORKDIR /go/src/github.com/tendermint/tendermint/tools/tm-bench
COPY Makefile /go/src/github.com/tendermint/tools/tm-bench/
COPY Makefile /go/src/github.com/tendermint/tendermint/tools/tm-bench/
RUN make get_tools
COPY . /go/src/github.com/tendermint/tools/tm-bench
COPY . /go/src/github.com/tendermint/tendermint/tools/tm-bench
RUN make get_vendor_deps

View File

@ -11,7 +11,7 @@
branch = "master"
name = "github.com/btcsuite/btcd"
packages = ["btcec"]
revision = "675abc5df3c5531bc741b56a765e35623459da6d"
revision = "fdfc19097e7ac6b57035062056f5b7b4638b8898"
[[projects]]
name = "github.com/davecgh/go-spew"
@ -80,7 +80,7 @@
branch = "master"
name = "github.com/golang/snappy"
packages = ["."]
revision = "553a641470496b2327abcac10b36396bd98e45c9"
revision = "2e65f85255dbc3072edf28d6b5b8efc472979f5a"
[[projects]]
name = "github.com/gorilla/websocket"
@ -113,13 +113,13 @@
version = "v0.8.0"
[[projects]]
branch = "master"
name = "github.com/prometheus/client_golang"
packages = [
"prometheus",
"prometheus/promhttp"
]
revision = "c5b7fccd204277076155f10851dad72b76a49317"
version = "v0.8.0"
revision = "ae27198cdd90bf12cd134ad79d1366a6cf49f632"
[[projects]]
branch = "master"
@ -146,7 +146,7 @@
"nfs",
"xfs"
]
revision = "7d6f385de8bea29190f15ba9931442a0eaef9af7"
revision = "ae68e2d4c00fed4943b5f6698d504a5fe083da8a"
[[projects]]
branch = "master"
@ -171,7 +171,7 @@
"leveldb/table",
"leveldb/util"
]
revision = "ae970a0732be3a1f5311da86118d37b9f4bd2a5a"
revision = "c4c61651e9e37fa117f53c5a906d3b63090d8445"
[[projects]]
branch = "master"
@ -190,6 +190,7 @@
version = "0.10.1"
[[projects]]
branch = "develop"
name = "github.com/tendermint/tendermint"
packages = [
"abci/client",
@ -201,9 +202,16 @@
"consensus",
"consensus/types",
"crypto",
"crypto/merkle",
"crypto/tmhash",
"evidence",
"libs/autofile",
"libs/clist",
"libs/common",
"libs/db",
"libs/events",
"libs/flowrate",
"libs/log",
"libs/pubsub",
"libs/pubsub/query",
"mempool",
@ -229,29 +237,14 @@
"types",
"version"
]
revision = "aa20c45ae99bb57a8efa2be7b09898e8967d1965"
version = "v0.21.1-rc1"
[[projects]]
branch = "develop"
name = "github.com/tendermint/tmlibs"
packages = [
"autofile",
"clist",
"common",
"db",
"flowrate",
"log",
"merkle",
"merkle/tmhash"
]
revision = "56f44670ebd5a4e99e55f3f7d6f4d360ef5f1973"
revision = "9d81a74429e093f3167875e0145ad957874c77d1"
[[projects]]
branch = "master"
name = "golang.org/x/crypto"
packages = [
"curve25519",
"internal/subtle",
"nacl/box",
"nacl/secretbox",
"openpgp/armor",
@ -260,7 +253,7 @@
"ripemd160",
"salsa20/salsa"
]
revision = "1f94bef427e370e425e55b172f3b5e300ef38304"
revision = "a49355c7e3f8fe157a85be2f77e6e269a0f89602"
[[projects]]
branch = "master"
@ -272,11 +265,10 @@
"http2/hpack",
"idna",
"internal/timeseries",
"lex/httplex",
"netutil",
"trace"
]
revision = "640f4622ab692b87c2f3a94265e6f579fe38263d"
revision = "292b43bbf7cb8d35ddf40f8d5100ef3837cced3f"
[[projects]]
name = "golang.org/x/text"
@ -303,16 +295,20 @@
branch = "master"
name = "google.golang.org/genproto"
packages = ["googleapis/rpc/status"]
revision = "86e600f69ee4704c6efbf6a2a40a5c10700e76c2"
revision = "e92b116572682a5b432ddd840aeaba2a559eeff1"
[[projects]]
name = "google.golang.org/grpc"
packages = [
".",
"balancer",
"balancer/base",
"balancer/roundrobin",
"codes",
"connectivity",
"credentials",
"encoding",
"encoding/proto",
"grpclb/grpc_lb_v1/messages",
"grpclog",
"internal",
@ -321,17 +317,19 @@
"naming",
"peer",
"resolver",
"resolver/dns",
"resolver/passthrough",
"stats",
"status",
"tap",
"transport"
]
revision = "5b3c4e850e90a4cf6a20ebd46c8b32a0a3afcb9e"
version = "v1.7.5"
revision = "d11072e7ca9811b1100b80ca0269ac831f06d024"
version = "v1.11.3"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "65c380641dcebca21a6343c9ea36bab5cbebff696e27c74d0735077f63272248"
inputs-digest = "bc54a74ffdfc09872726fcf5c72b5df882269dc1cd949ac3fbeac9a554fc25c6"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -45,10 +45,6 @@
name = "github.com/tendermint/tendermint"
branch = "develop"
[[constraint]]
name = "github.com/tendermint/tmlibs"
branch = "develop"
[prune]
go-tests = true
unused-packages = true

View File

@ -12,13 +12,11 @@ import (
"github.com/go-kit/kit/log/term"
metrics "github.com/rcrowley/go-metrics"
"github.com/tendermint/tendermint/libs/log"
tmrpc "github.com/tendermint/tendermint/rpc/client"
"github.com/tendermint/tmlibs/log"
)
var version = "0.3.0"
var logger = log.NewNopLogger()
type statistics struct {
@ -106,35 +104,32 @@ Examples:
"broadcast_tx_"+broadcastTxMethod,
)
endTime := time.Duration(duration) * time.Second
select {
case <-time.After(endTime):
for i, t := range transacters {
t.Stop()
numCrashes := countCrashes(t.connsBroken)
if numCrashes != 0 {
fmt.Printf("%d connections crashed on transacter #%d\n", numCrashes, i)
}
<-time.After(endTime)
for i, t := range transacters {
t.Stop()
numCrashes := countCrashes(t.connsBroken)
if numCrashes != 0 {
fmt.Printf("%d connections crashed on transacter #%d\n", numCrashes, i)
}
timeStop := time.Now()
logger.Info("Time stopped", "t", timeStop)
stats, err := calculateStatistics(
client,
initialHeight,
timeStart,
timeStop,
duration,
)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
printStatistics(stats, outputFormat)
return
}
timeStop := time.Now()
logger.Info("Time stopped", "t", timeStop)
stats, err := calculateStatistics(
client,
initialHeight,
timeStart,
timeStop,
duration,
)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
printStatistics(stats, outputFormat)
}
func latestBlockHeight(client tmrpc.Client) int64 {

View File

@ -16,14 +16,14 @@ import (
"github.com/gorilla/websocket"
"github.com/pkg/errors"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
"github.com/tendermint/tmlibs/log"
"github.com/tendermint/tendermint/libs/log"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
)
const (
sendTimeout = 10 * time.Second
// see https://github.com/tendermint/go-rpc/blob/develop/server/handlers.go#L313
// see https://github.com/tendermint/tendermint/blob/master/rpc/lib/server/handlers.go
pingPeriod = (30 * 9 / 10) * time.Second
)
@ -194,7 +194,7 @@ func (t *transacter) sendLoop(connIndex int) {
txNumber++
}
timeToSend := time.Now().Sub(startTime)
timeToSend := time.Since(startTime)
logger.Info(fmt.Sprintf("sent %d transactions", numTxSent), "took", timeToSend)
if timeToSend < 1*time.Second {
sleepTime := time.Second - timeToSend

View File

@ -1,11 +1,17 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
branch = "master"
name = "github.com/beorn7/perks"
packages = ["quantile"]
revision = "3a771d992973f24aa725d07868b467d1ddfceafb"
[[projects]]
branch = "master"
name = "github.com/btcsuite/btcd"
packages = ["btcec"]
revision = "2be2f12b358dc57d70b8f501b00be450192efbc3"
revision = "fdfc19097e7ac6b57035062056f5b7b4638b8898"
[[projects]]
name = "github.com/davecgh/go-spew"
@ -14,7 +20,6 @@
version = "v1.1.0"
[[projects]]
branch = "master"
name = "github.com/ebuchman/fail-test"
packages = ["."]
revision = "95f809107225be108efcf10a3509e4ea6ceef3c4"
@ -24,7 +29,11 @@
packages = [
"log",
"log/level",
"log/term"
"log/term",
"metrics",
"metrics/discard",
"metrics/internal/lv",
"metrics/prometheus"
]
revision = "4dc7be5d2d12881735283bcab7352178e190fc71"
version = "v0.6.0"
@ -70,7 +79,7 @@
branch = "master"
name = "github.com/golang/snappy"
packages = ["."]
revision = "553a641470496b2327abcac10b36396bd98e45c9"
revision = "2e65f85255dbc3072edf28d6b5b8efc472979f5a"
[[projects]]
name = "github.com/gorilla/websocket"
@ -90,6 +99,12 @@
packages = ["."]
revision = "b84e30acd515aadc4b783ad4ff83aff3299bdfe0"
[[projects]]
name = "github.com/matttproud/golang_protobuf_extensions"
packages = ["pbutil"]
revision = "c12348ce28de40eed0136aa2b644d0ee0650e56c"
version = "v1.0.1"
[[projects]]
name = "github.com/pkg/errors"
packages = ["."]
@ -102,11 +117,43 @@
revision = "792786c7400a136282c1664665ae0a8db921c6c2"
version = "v1.0.0"
[[projects]]
name = "github.com/prometheus/client_golang"
packages = ["prometheus"]
revision = "ae27198cdd90bf12cd134ad79d1366a6cf49f632"
[[projects]]
branch = "master"
name = "github.com/prometheus/client_model"
packages = ["go"]
revision = "99fa1f4be8e564e8a6b613da7fa6f46c9edafc6c"
[[projects]]
branch = "master"
name = "github.com/prometheus/common"
packages = [
"expfmt",
"internal/bitbucket.org/ww/goautoneg",
"model"
]
revision = "7600349dcfe1abd18d72d3a1770870d9800a7801"
[[projects]]
branch = "master"
name = "github.com/prometheus/procfs"
packages = [
".",
"internal/util",
"nfs",
"xfs"
]
revision = "ae68e2d4c00fed4943b5f6698d504a5fe083da8a"
[[projects]]
branch = "master"
name = "github.com/rcrowley/go-metrics"
packages = ["."]
revision = "d932a24a8ccb8fcadc993e5c6c58f93dac168294"
revision = "e2704e165165ec55d062f5919b4b29494e9fa790"
[[projects]]
name = "github.com/stretchr/testify"
@ -114,8 +161,8 @@
"assert",
"require"
]
revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71"
version = "v1.2.1"
revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686"
version = "v1.2.2"
[[projects]]
branch = "master"
@ -134,18 +181,7 @@
"leveldb/table",
"leveldb/util"
]
revision = "714f901b98fdb3aa954b4193d8cbd64a28d80cad"
[[projects]]
name = "github.com/tendermint/abci"
packages = [
"client",
"example/code",
"example/kvstore",
"types"
]
revision = "78a8905690ef54f9d57e3b2b0ee7ad3a04ef3f1f"
version = "v0.10.3"
revision = "c4c61651e9e37fa117f53c5a906d3b63090d8445"
[[projects]]
branch = "master"
@ -160,19 +196,27 @@
[[projects]]
name = "github.com/tendermint/go-amino"
packages = ["."]
revision = "42246108ff925a457fb709475070a03dfd3e2b5c"
version = "0.9.6"
[[projects]]
name = "github.com/tendermint/go-crypto"
packages = ["."]
revision = "915416979bf70efa4bcbf1c6cd5d64c5fff9fc19"
version = "v0.6.2"
revision = "2106ca61d91029c931fd54968c2bb02dc96b1412"
version = "0.10.1"
[[projects]]
name = "github.com/tendermint/tendermint"
packages = [
"abci/client",
"abci/example/code",
"abci/example/kvstore",
"abci/types",
"config",
"crypto",
"crypto/merkle",
"crypto/tmhash",
"libs/common",
"libs/db",
"libs/events",
"libs/flowrate",
"libs/log",
"libs/pubsub",
"libs/pubsub/query",
"p2p",
"p2p/conn",
"p2p/upnp",
@ -184,29 +228,15 @@
"state",
"types"
]
revision = "d0beaba7e8a5652506a34b5fab299cc2dc274c02"
version = "v0.19.0"
[[projects]]
name = "github.com/tendermint/tmlibs"
packages = [
"common",
"db",
"events",
"flowrate",
"log",
"merkle",
"pubsub",
"pubsub/query"
]
revision = "737154202faf75c70437f59ba5303f2eb09f5636"
version = "0.8.2-rc1"
revision = "2aa2b63cadc42cca1071c36adfd2f2ce14e1aa8f"
version = "v0.22.3"
[[projects]]
branch = "master"
name = "golang.org/x/crypto"
packages = [
"curve25519",
"internal/subtle",
"nacl/box",
"nacl/secretbox",
"openpgp/armor",
@ -215,10 +245,9 @@
"ripemd160",
"salsa20/salsa"
]
revision = "d6449816ce06963d9d136eee5a56fca5b0616e7e"
revision = "a49355c7e3f8fe157a85be2f77e6e269a0f89602"
[[projects]]
branch = "master"
name = "golang.org/x/net"
packages = [
"context",
@ -227,10 +256,10 @@
"http2/hpack",
"idna",
"internal/timeseries",
"lex/httplex",
"netutil",
"trace"
]
revision = "8d16fa6dc9a85c1cd3ed24ad08ff21cf94f10888"
revision = "292b43bbf7cb8d35ddf40f8d5100ef3837cced3f"
[[projects]]
name = "golang.org/x/text"
@ -257,16 +286,20 @@
branch = "master"
name = "google.golang.org/genproto"
packages = ["googleapis/rpc/status"]
revision = "7fd901a49ba6a7f87732eb344f6e3c5b19d1b200"
revision = "e92b116572682a5b432ddd840aeaba2a559eeff1"
[[projects]]
name = "google.golang.org/grpc"
packages = [
".",
"balancer",
"balancer/base",
"balancer/roundrobin",
"codes",
"connectivity",
"credentials",
"encoding",
"encoding/proto",
"grpclb/grpc_lb_v1/messages",
"grpclog",
"internal",
@ -275,17 +308,19 @@
"naming",
"peer",
"resolver",
"resolver/dns",
"resolver/passthrough",
"stats",
"status",
"tap",
"transport"
]
revision = "5b3c4e850e90a4cf6a20ebd46c8b32a0a3afcb9e"
version = "v1.7.5"
revision = "d11072e7ca9811b1100b80ca0269ac831f06d024"
version = "v1.11.3"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "c445a659655eae3fbc1355e7d3431aa7f4b78f2f052ecba723cf8dcefd6350c4"
inputs-digest = "b8644e2f33b8c04ed76a9cda1b6d7741a0e36844fdb0ce0d68717332779bcd75"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -37,21 +37,13 @@
name = "github.com/stretchr/testify"
version = "1.2.1"
[[constraint]]
name = "github.com/tendermint/go-crypto"
version = "~0.6.2"
[[constraint]]
name = "github.com/tendermint/go-amino"
version = "~0.9.6"
version = "~0.10.1"
[[constraint]]
name = "github.com/tendermint/tendermint"
version = "0.19.0"
[[override]]
name = "github.com/tendermint/tmlibs"
version = "~0.8.2-rc1"
version = "v0.22.3"
[prune]
go-tests = true

View File

@ -9,9 +9,10 @@ import (
"time"
metrics "github.com/rcrowley/go-metrics"
"github.com/tendermint/tendermint/libs/events"
"github.com/tendermint/tendermint/libs/log"
client "github.com/tendermint/tendermint/rpc/lib/client"
"github.com/tendermint/tmlibs/events"
"github.com/tendermint/tmlibs/log"
)
const (
@ -162,11 +163,8 @@ func (em *EventMeter) Subscribe(query string, cb EventCallbackFunc) error {
func (em *EventMeter) Unsubscribe(query string) error {
em.mtx.Lock()
defer em.mtx.Unlock()
if err := em.wsc.Unsubscribe(context.TODO(), query); err != nil {
return err
}
return nil
return em.wsc.Unsubscribe(context.TODO(), query)
}
// GetMetric fills in the latest data for an query and return a copy.

View File

@ -6,13 +6,11 @@ import (
"os"
"strings"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/log"
monitor "github.com/tendermint/tools/tm-monitor/monitor"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/log"
monitor "github.com/tendermint/tendermint/tools/tm-monitor/monitor"
)
var version = "0.4.0"
var logger = log.NewNopLogger()
func main() {

View File

@ -4,9 +4,9 @@ import (
stdlog "log"
"reflect"
"github.com/tendermint/tmlibs/log"
em "github.com/tendermint/tools/tm-monitor/eventmeter"
"github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/libs/log"
em "github.com/tendermint/tendermint/tools/tm-monitor/eventmeter"
)
type EventMeter struct {
@ -44,7 +44,7 @@ func (e *EventMeter) Call(callback string, args ...interface{}) {
type RpcClient struct {
Stubs map[string]interface{}
cdc *amino.Codec
cdc *amino.Codec
}
func (c *RpcClient) Call(method string, params map[string]interface{}, result interface{}) (interface{}, error) {
@ -66,4 +66,4 @@ func (c *RpcClient) Codec() *amino.Codec {
func (c *RpcClient) SetCodec(cdc *amino.Codec) {
c.cdc = cdc
}
}

View File

@ -7,8 +7,8 @@ import (
"time"
"github.com/pkg/errors"
"github.com/tendermint/tendermint/libs/log"
tmtypes "github.com/tendermint/tendermint/types"
"github.com/tendermint/tmlibs/log"
)
// waiting more than this many seconds for a block means we're unhealthy

View File

@ -7,12 +7,12 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
crypto "github.com/tendermint/go-crypto"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
tmtypes "github.com/tendermint/tendermint/types"
mock "github.com/tendermint/tools/tm-monitor/mock"
monitor "github.com/tendermint/tools/tm-monitor/monitor"
"github.com/tendermint/go-amino"
crypto "github.com/tendermint/tendermint/crypto"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
mock "github.com/tendermint/tendermint/tools/tm-monitor/mock"
monitor "github.com/tendermint/tendermint/tools/tm-monitor/monitor"
tmtypes "github.com/tendermint/tendermint/types"
)
func TestMonitorUpdatesNumberOfValidators(t *testing.T) {

View File

@ -5,8 +5,9 @@ import (
"time"
"github.com/stretchr/testify/assert"
monitor "github.com/tendermint/tendermint/tools/tm-monitor/monitor"
tmtypes "github.com/tendermint/tendermint/types"
monitor "github.com/tendermint/tools/tm-monitor/monitor"
)
func TestNetworkNewBlock(t *testing.T) {

View File

@ -6,13 +6,14 @@ import (
"time"
"github.com/pkg/errors"
crypto "github.com/tendermint/go-crypto"
crypto "github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/libs/events"
"github.com/tendermint/tendermint/libs/log"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpc_client "github.com/tendermint/tendermint/rpc/lib/client"
em "github.com/tendermint/tendermint/tools/tm-monitor/eventmeter"
tmtypes "github.com/tendermint/tendermint/types"
"github.com/tendermint/tmlibs/events"
"github.com/tendermint/tmlibs/log"
em "github.com/tendermint/tools/tm-monitor/eventmeter"
)
const maxRestarts = 25

View File

@ -6,13 +6,13 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
crypto "github.com/tendermint/go-crypto"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
tmtypes "github.com/tendermint/tendermint/types"
em "github.com/tendermint/tools/tm-monitor/eventmeter"
mock "github.com/tendermint/tools/tm-monitor/mock"
monitor "github.com/tendermint/tools/tm-monitor/monitor"
"github.com/tendermint/go-amino"
crypto "github.com/tendermint/tendermint/crypto"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
em "github.com/tendermint/tendermint/tools/tm-monitor/eventmeter"
mock "github.com/tendermint/tendermint/tools/tm-monitor/mock"
monitor "github.com/tendermint/tendermint/tools/tm-monitor/monitor"
tmtypes "github.com/tendermint/tendermint/types"
)
const (

View File

@ -4,9 +4,9 @@ import (
"errors"
"net/http"
"github.com/tendermint/tendermint/libs/log"
rpc "github.com/tendermint/tendermint/rpc/lib/server"
"github.com/tendermint/tmlibs/log"
monitor "github.com/tendermint/tools/tm-monitor/monitor"
monitor "github.com/tendermint/tendermint/tools/tm-monitor/monitor"
)
func startRPC(listenAddr string, m *monitor.Monitor, logger log.Logger) {
@ -16,7 +16,7 @@ func startRPC(listenAddr string, m *monitor.Monitor, logger log.Logger) {
wm := rpc.NewWebsocketManager(routes, nil)
mux.HandleFunc("/websocket", wm.WebsocketHandler)
rpc.RegisterRPCFuncs(mux, routes, cdc, logger)
if _, err := rpc.StartHTTPServer(listenAddr, mux, logger); err != nil {
if _, err := rpc.StartHTTPServer(listenAddr, mux, logger, rpc.Config{}); err != nil {
panic(err)
}
}

View File

@ -7,7 +7,7 @@ import (
"text/tabwriter"
"time"
monitor "github.com/tendermint/tools/tm-monitor/monitor"
monitor "github.com/tendermint/tendermint/tools/tm-monitor/monitor"
)
const (

View File

@ -1,140 +0,0 @@
package main
import (
"crypto/rand"
"encoding/binary"
"encoding/hex"
"flag"
"fmt"
"os"
"strconv"
"strings"
"sync"
"time"
"github.com/tendermint/go-rpc/client"
rpctypes "github.com/tendermint/go-rpc/types"
)
func main() {
flag.Parse()
args := flag.Args()
if len(args) < 2 {
fmt.Println("transact.go expects at least two arguments (ntxs, hosts)")
os.Exit(1)
}
nTxS, hostS := args[0], args[1]
nTxs, err := strconv.Atoi(nTxS)
if err != nil {
fmt.Println("ntxs must be an integer:", err)
os.Exit(1)
}
hosts := strings.Split(hostS, ",")
errCh := make(chan error, 1000)
wg := new(sync.WaitGroup)
wg.Add(len(hosts))
start := time.Now()
fmt.Printf("Sending %d txs on every host %v\n", nTxs, hosts)
for i, host := range hosts {
go broadcastTxsToHost(wg, errCh, i, host, nTxs, 0)
}
wg.Wait()
fmt.Println("Done broadcasting txs. Took", time.Since(start))
}
func broadcastTxsToHost(wg *sync.WaitGroup, errCh chan error, valI int, valHost string, nTxs int, txCount int) {
reconnectSleepSeconds := time.Second * 1
// thisStart := time.Now()
// cli := rpcclient.NewClientURI(valHost + ":26657")
fmt.Println("Connecting to host to broadcast txs", valI, valHost)
cli := rpcclient.NewWSClient(valHost, "/websocket")
if _, err := cli.Start(); err != nil {
if nTxs == 0 {
time.Sleep(reconnectSleepSeconds)
broadcastTxsToHost(wg, errCh, valI, valHost, nTxs, txCount)
return
}
fmt.Printf("Error starting websocket connection to val%d (%s): %v\n", valI, valHost, err)
os.Exit(1)
}
reconnect := make(chan struct{})
go func(count int) {
LOOP:
for {
ticker := time.NewTicker(reconnectSleepSeconds)
select {
case <-cli.ResultsCh:
count += 1
// nTxs == 0 means just loop forever
if nTxs > 0 && count == nTxs {
break LOOP
}
case err := <-cli.ErrorsCh:
fmt.Println("err: val", valI, valHost, err)
case <-cli.Quit:
broadcastTxsToHost(wg, errCh, valI, valHost, nTxs, count)
return
case <-reconnect:
broadcastTxsToHost(wg, errCh, valI, valHost, nTxs, count)
return
case <-ticker.C:
if nTxs == 0 {
cli.Stop()
broadcastTxsToHost(wg, errCh, valI, valHost, nTxs, count)
return
}
}
}
fmt.Printf("Received all responses from node %d (%s)\n", valI, valHost)
wg.Done()
}(txCount)
var i = 0
for {
/* if i%(nTxs/4) == 0 {
fmt.Printf("Have sent %d txs to node %d. Total time so far: %v\n", i, valI, time.Since(thisStart))
}*/
if !cli.IsRunning() {
return
}
tx := generateTx(i, valI)
if err := cli.WriteJSON(rpctypes.RPCRequest{
JSONRPC: "2.0",
ID: "",
Method: "broadcast_tx_async",
Params: []interface{}{hex.EncodeToString(tx)},
}); err != nil {
fmt.Printf("Error sending tx %d to validator %d: %v. Attempt reconnect\n", i, valI, err)
reconnect <- struct{}{}
return
}
i += 1
if nTxs > 0 && i >= nTxs {
break
} else if nTxs == 0 {
time.Sleep(time.Millisecond * 1)
}
}
fmt.Printf("Done sending %d txs to node s%d (%s)\n", nTxs, valI, valHost)
}
func generateTx(i, valI int) []byte {
// a tx encodes the validator index, the tx number, and some random junk
// TODO: read random bytes into more of the tx
tx := make([]byte, 250)
binary.PutUvarint(tx[:32], uint64(valI))
binary.PutUvarint(tx[32:64], uint64(i))
if _, err := rand.Read(tx[234:]); err != nil {
fmt.Println("err reading from crypto/rand", err)
os.Exit(1)
}
return tx
}