diff --git a/benchmarks/codec_test.go b/benchmarks/codec_test.go index d8e4bc82..779fadd1 100644 --- a/benchmarks/codec_test.go +++ b/benchmarks/codec_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/go-crypto" proto "github.com/tendermint/tendermint/benchmarks/proto" @@ -32,7 +32,7 @@ func BenchmarkEncodeStatusWire(b *testing.B) { LatestBlockTime: time.Unix(0, 1234), }, ValidatorInfo: ctypes.ValidatorInfo{ - PubKey: nodeKey.PubKey(), + PubKey: nodeKey.PubKey(), }, } b.StartTimer() diff --git a/benchmarks/experiments/Makefile b/benchmarks/experiments/Makefile new file mode 100644 index 00000000..5a0be42b --- /dev/null +++ b/benchmarks/experiments/Makefile @@ -0,0 +1,26 @@ +DIST_DIRS := find * -type d -exec +VERSION := $(shell perl -ne '/^var version.*"([^"]+)".*$$/ && print "v$$1\n"' main.go) +GOTOOLS = \ + github.com/mitchellh/gox + +tools: + go get $(GOTOOLS) + +get_vendor_deps: + @hash glide 2>/dev/null || go get github.com/Masterminds/glide + glide install + +build: + go build + +install: + go install + +test: + go test -race + +clean: + rm -f ./experiments + rm -rf ./dist + +.PHONY: tools get_vendor_deps build install test clean diff --git a/benchmarks/experiments/glide.yaml b/benchmarks/experiments/glide.yaml new file mode 100644 index 00000000..ed4d0ef7 --- /dev/null +++ b/benchmarks/experiments/glide.yaml @@ -0,0 +1,12 @@ +package: github.com/tendermint/tendermint/benchmarks/experiments +import: +- package: github.com/tendermint/tendermint + version: v0.16.0 + subpackages: + - rpc/client + - rpc/lib/types + - types +- package: github.com/tendermint/tmlibs + version: v0.7.0 + subpackages: + - log diff --git a/benchmarks/experiments/main.go b/benchmarks/experiments/main.go new file mode 100644 index 00000000..f3691602 --- /dev/null +++ b/benchmarks/experiments/main.go @@ -0,0 +1,126 @@ +package main + +import ( + "encoding/binary" + "fmt" + "math/rand" + "os" + "sync" + "time" + + "context" + + "github.com/tendermint/tendermint/rpc/client" + "github.com/tendermint/tendermint/types" + "github.com/tendermint/tmlibs/log" +) + +var logger = log.NewNopLogger() +var finishedTasks = 0 +var mutex = &sync.Mutex{} + +func main() { + + var endpoint = "tcp://0.0.0.0:46657" + + var httpClient = getHTTPClient(endpoint) + + var res, err = httpClient.Status() + if err != nil { + logger.Info("something wrong happens", err) + } + logger.Info("received status", res) + + go monitorTask(endpoint) + + txCount := 10 + var clientNumber = 10 + for i := 0; i < clientNumber; i++ { + go clientTask(i, txCount, endpoint) + } + for finishedTasks < clientNumber+1 { + } + fmt.Printf("Done: %d\n", finishedTasks) +} + +func clientTask(id, txCount int, endpoint string) { + var httpClient = getHTTPClient(endpoint) + for i := 0; i < txCount; i++ { + var _, err = httpClient.BroadcastTxSync(generateTx(id, rand.Int())) + if err != nil { + fmt.Printf("Something wrong happened: %s\n", err) + } + } + fmt.Printf("Finished client task: %d\n", id) + + mutex.Lock() + finishedTasks++ + mutex.Unlock() +} + +func getHTTPClient(rpcAddr string) *client.HTTP { + return client.NewHTTP(rpcAddr, "/websocket") +} + +func generateTx(i, valI int) []byte { + // a tx encodes the validator index, the tx number, and some random junk + tx := make([]byte, 250) + binary.PutUvarint(tx[:32], uint64(valI)) + binary.PutUvarint(tx[32:64], uint64(i)) + if _, err := rand.Read(tx[65:]); err != nil { + fmt.Println("err reading from crypto/rand", err) + os.Exit(1) + } + return tx +} + +func monitorTask(endpoint string) { + fmt.Println("Monitor task started...") + var duration = 5 * time.Second + + const subscriber = "monitor" + ctx, cancel := context.WithTimeout(context.Background(), duration) + defer cancel() + evts := make(chan interface{}) + + var httpClient = getHTTPClient(endpoint) + httpClient.Start() + + evtTyp := types.EventNewBlockHeader + + // register for the next event of this type + query := types.QueryForEvent(evtTyp) + err := httpClient.Subscribe(ctx, subscriber, query, evts) + if err != nil { + fmt.Println("error when subscribing", err) + } + + // make sure to unregister after the test is over + defer httpClient.UnsubscribeAll(ctx, subscriber) + + totalNumOfCommittedTxs := int64(0) + + for { + fmt.Println("Starting main loop", err) + select { + case evt := <-evts: + event := evt.(types.TMEventData) + header, ok := event.Unwrap().(types.EventDataNewBlockHeader) + if ok { + fmt.Println("received header\n", header.Header.StringIndented("")) + } else { + fmt.Println("not able to unwrap header") + } + // Do some metric computation with header + totalNumOfCommittedTxs += header.Header.NumTxs + + case <-ctx.Done(): + fmt.Printf("Finished monitor task. Received %d transactions \n", totalNumOfCommittedTxs) + + mutex.Lock() + finishedTasks++ + mutex.Unlock() + return + } + } +} diff --git a/blockchain/reactor.go b/blockchain/reactor.go index 33dfdd28..523cd3aa 100644 --- a/blockchain/reactor.go +++ b/blockchain/reactor.go @@ -5,7 +5,7 @@ import ( "reflect" "time" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/tendermint/p2p" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" diff --git a/blockchain/wire.go b/blockchain/wire.go index 55b4e60a..6fb6f638 100644 --- a/blockchain/wire.go +++ b/blockchain/wire.go @@ -1,7 +1,7 @@ package blockchain import ( - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/go-crypto" ) diff --git a/cmd/tendermint/commands/show_node_id.go b/cmd/tendermint/commands/show_node_id.go index 1d94933e..02ab1a9b 100644 --- a/cmd/tendermint/commands/show_node_id.go +++ b/cmd/tendermint/commands/show_node_id.go @@ -6,7 +6,6 @@ import ( "github.com/spf13/cobra" "github.com/tendermint/tendermint/p2p" - ) // ShowNodeIDCmd dumps node's ID to the standard output. diff --git a/cmd/tendermint/commands/show_validator.go b/cmd/tendermint/commands/show_validator.go index 6ead4bad..b354683b 100644 --- a/cmd/tendermint/commands/show_validator.go +++ b/cmd/tendermint/commands/show_validator.go @@ -2,6 +2,7 @@ package commands import ( "fmt" + "github.com/spf13/cobra" privval "github.com/tendermint/tendermint/types/priv_validator" diff --git a/cmd/tendermint/commands/wire.go b/cmd/tendermint/commands/wire.go index 4c133a8c..743f7975 100644 --- a/cmd/tendermint/commands/wire.go +++ b/cmd/tendermint/commands/wire.go @@ -1,7 +1,7 @@ package commands import ( - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/go-crypto" ) diff --git a/consensus/wal.go b/consensus/wal.go index 694e2516..b127eea1 100644 --- a/consensus/wal.go +++ b/consensus/wal.go @@ -10,7 +10,7 @@ import ( "github.com/pkg/errors" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/tendermint/types" auto "github.com/tendermint/tmlibs/autofile" cmn "github.com/tendermint/tmlibs/common" diff --git a/consensus/wire.go b/consensus/wire.go index 81223c68..1da33933 100644 --- a/consensus/wire.go +++ b/consensus/wire.go @@ -1,7 +1,7 @@ package consensus import ( - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/go-crypto" ) diff --git a/evidence/reactor.go b/evidence/reactor.go index a6aa66b1..c63f9fb3 100644 --- a/evidence/reactor.go +++ b/evidence/reactor.go @@ -5,7 +5,7 @@ import ( "reflect" "time" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/tmlibs/log" "github.com/tendermint/tendermint/p2p" diff --git a/evidence/wire.go b/evidence/wire.go index 842e0707..5d66ea5d 100644 --- a/evidence/wire.go +++ b/evidence/wire.go @@ -1,7 +1,7 @@ package evidence import ( - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/go-crypto" "github.com/tendermint/tendermint/types" ) diff --git a/lite/files/wire.go b/lite/files/wire.go index 99f98931..e2e0bedf 100644 --- a/lite/files/wire.go +++ b/lite/files/wire.go @@ -1,7 +1,7 @@ package files import ( - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/go-crypto" ) diff --git a/lite/proxy/proxy.go b/lite/proxy/proxy.go index fe10399d..7aadcf7a 100644 --- a/lite/proxy/proxy.go +++ b/lite/proxy/proxy.go @@ -3,7 +3,7 @@ package proxy import ( "net/http" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/tmlibs/log" rpcclient "github.com/tendermint/tendermint/rpc/client" diff --git a/mempool/reactor.go b/mempool/reactor.go index 54a3c32f..4afd9d3a 100644 --- a/mempool/reactor.go +++ b/mempool/reactor.go @@ -6,7 +6,7 @@ import ( "time" abci "github.com/tendermint/abci/types" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/tmlibs/clist" "github.com/tendermint/tmlibs/log" diff --git a/mempool/wire.go b/mempool/wire.go index ed089726..3fbbeab1 100644 --- a/mempool/wire.go +++ b/mempool/wire.go @@ -1,8 +1,6 @@ package mempool -import ( - "github.com/tendermint/go-amino" -) +import amino "github.com/tendermint/go-amino" var cdc = amino.NewCodec() diff --git a/p2p/conn/connection_test.go b/p2p/conn/connection_test.go index a927d695..24d25f9c 100644 --- a/p2p/conn/connection_test.go +++ b/p2p/conn/connection_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/tmlibs/log" ) diff --git a/p2p/conn/wire.go b/p2p/conn/wire.go index 02d67f6f..37d6e4dd 100644 --- a/p2p/conn/wire.go +++ b/p2p/conn/wire.go @@ -1,7 +1,7 @@ package conn import ( - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/go-crypto" ) diff --git a/p2p/pex/pex_reactor.go b/p2p/pex/pex_reactor.go index 70ae7ed1..a0cfe591 100644 --- a/p2p/pex/pex_reactor.go +++ b/p2p/pex/pex_reactor.go @@ -7,7 +7,7 @@ import ( "sync" "time" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/tendermint/p2p" diff --git a/p2p/pex/wire.go b/p2p/pex/wire.go index 57fc9385..abce9b6c 100644 --- a/p2p/pex/wire.go +++ b/p2p/pex/wire.go @@ -1,8 +1,6 @@ package pex -import ( - "github.com/tendermint/go-amino" -) +import amino "github.com/tendermint/go-amino" var cdc *amino.Codec = amino.NewCodec() diff --git a/p2p/wire.go b/p2p/wire.go index a90ac851..98d8efbc 100644 --- a/p2p/wire.go +++ b/p2p/wire.go @@ -1,7 +1,7 @@ package p2p import ( - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/go-crypto" ) diff --git a/rpc/client/helpers_test.go b/rpc/client/helpers_test.go index d5c31dda..8b843fcd 100644 --- a/rpc/client/helpers_test.go +++ b/rpc/client/helpers_test.go @@ -32,7 +32,7 @@ func TestWaitForHeight(t *testing.T) { // now set current block height to 10 m.Call = mock.Call{ - Response: &ctypes.ResultStatus{SyncInfo: ctypes.SyncInfo{LatestBlockHeight: 10} }, + Response: &ctypes.ResultStatus{SyncInfo: ctypes.SyncInfo{LatestBlockHeight: 10}}, } // we will not wait for more than 10 blocks diff --git a/rpc/core/types/wire.go b/rpc/core/types/wire.go index 6648364b..54bf0284 100644 --- a/rpc/core/types/wire.go +++ b/rpc/core/types/wire.go @@ -1,7 +1,7 @@ package core_types import ( - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/go-crypto" "github.com/tendermint/tendermint/types" ) diff --git a/rpc/lib/client/args_test.go b/rpc/lib/client/args_test.go index 4442ac2b..68cd5d51 100644 --- a/rpc/lib/client/args_test.go +++ b/rpc/lib/client/args_test.go @@ -5,8 +5,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" ) type Tx []byte diff --git a/rpc/lib/client/http_client.go b/rpc/lib/client/http_client.go index e26d8f27..19204792 100644 --- a/rpc/lib/client/http_client.go +++ b/rpc/lib/client/http_client.go @@ -12,8 +12,8 @@ import ( "strings" "github.com/pkg/errors" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" types "github.com/tendermint/tendermint/rpc/lib/types" ) diff --git a/rpc/lib/client/ws_client.go b/rpc/lib/client/ws_client.go index a95ce17d..fe0455e0 100644 --- a/rpc/lib/client/ws_client.go +++ b/rpc/lib/client/ws_client.go @@ -13,7 +13,7 @@ import ( "github.com/pkg/errors" metrics "github.com/rcrowley/go-metrics" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" types "github.com/tendermint/tendermint/rpc/lib/types" cmn "github.com/tendermint/tmlibs/common" ) diff --git a/rpc/lib/rpc_test.go b/rpc/lib/rpc_test.go index f34b09f6..23b407fb 100644 --- a/rpc/lib/rpc_test.go +++ b/rpc/lib/rpc_test.go @@ -17,7 +17,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/tmlibs/log" diff --git a/rpc/lib/server/handlers.go b/rpc/lib/server/handlers.go index 07ccfb6f..35156956 100644 --- a/rpc/lib/server/handlers.go +++ b/rpc/lib/server/handlers.go @@ -17,7 +17,7 @@ import ( "github.com/gorilla/websocket" "github.com/pkg/errors" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" types "github.com/tendermint/tendermint/rpc/lib/types" cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/tmlibs/log" diff --git a/rpc/lib/server/handlers_test.go b/rpc/lib/server/handlers_test.go index 92a2d990..ef438f5f 100644 --- a/rpc/lib/server/handlers_test.go +++ b/rpc/lib/server/handlers_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" rs "github.com/tendermint/tendermint/rpc/lib/server" types "github.com/tendermint/tendermint/rpc/lib/types" "github.com/tendermint/tmlibs/log" diff --git a/rpc/lib/server/parse_test.go b/rpc/lib/server/parse_test.go index f4323ef5..bda40a64 100644 --- a/rpc/lib/server/parse_test.go +++ b/rpc/lib/server/parse_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" cmn "github.com/tendermint/tmlibs/common" ) diff --git a/rpc/lib/test/main.go b/rpc/lib/test/main.go index 604cbd3d..d4af3e73 100644 --- a/rpc/lib/test/main.go +++ b/rpc/lib/test/main.go @@ -5,7 +5,7 @@ import ( "net/http" "os" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" rpcserver "github.com/tendermint/tendermint/rpc/lib/server" cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/tmlibs/log" diff --git a/rpc/lib/types/types.go b/rpc/lib/types/types.go index 5fa723bb..486eea97 100644 --- a/rpc/lib/types/types.go +++ b/rpc/lib/types/types.go @@ -7,7 +7,7 @@ import ( "strings" "github.com/pkg/errors" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" tmpubsub "github.com/tendermint/tmlibs/pubsub" ) diff --git a/rpc/lib/types/types_test.go b/rpc/lib/types/types_test.go index 9dd1b7a1..43030932 100644 --- a/rpc/lib/types/types_test.go +++ b/rpc/lib/types/types_test.go @@ -8,7 +8,7 @@ import ( "github.com/pkg/errors" "github.com/stretchr/testify/assert" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" ) type SampleResult struct { diff --git a/scripts/wire2amino.go b/scripts/wire2amino.go index 94908287..3cc10d33 100644 --- a/scripts/wire2amino.go +++ b/scripts/wire2amino.go @@ -8,7 +8,7 @@ import ( "path/filepath" "time" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" crypto "github.com/tendermint/go-crypto" cmn "github.com/tendermint/tmlibs/common" diff --git a/state/txindex/kv/wire.go b/state/txindex/kv/wire.go index ccca7525..09ecb14e 100644 --- a/state/txindex/kv/wire.go +++ b/state/txindex/kv/wire.go @@ -1,8 +1,6 @@ package kv -import ( - "github.com/tendermint/go-amino" -) +import amino "github.com/tendermint/go-amino" var cdc = amino.NewCodec() diff --git a/state/wire.go b/state/wire.go index 3e8b544d..b89042f6 100644 --- a/state/wire.go +++ b/state/wire.go @@ -1,7 +1,7 @@ package state import ( - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/go-crypto" ) diff --git a/types/canonical_json.go b/types/canonical_json.go index 95ade9c6..49b35219 100644 --- a/types/canonical_json.go +++ b/types/canonical_json.go @@ -3,7 +3,7 @@ package types import ( "time" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" cmn "github.com/tendermint/tmlibs/common" ) diff --git a/types/events.go b/types/events.go index 342d4bc2..1bb61d8c 100644 --- a/types/events.go +++ b/types/events.go @@ -3,7 +3,7 @@ package types import ( "fmt" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" tmpubsub "github.com/tendermint/tmlibs/pubsub" tmquery "github.com/tendermint/tmlibs/pubsub/query" ) diff --git a/types/evidence.go b/types/evidence.go index ee7f44a5..15b5d54d 100644 --- a/types/evidence.go +++ b/types/evidence.go @@ -4,7 +4,7 @@ import ( "bytes" "fmt" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/go-crypto" "github.com/tendermint/tmlibs/merkle" ) diff --git a/types/genesis_test.go b/types/genesis_test.go index 17ebf1cf..bed4b90f 100644 --- a/types/genesis_test.go +++ b/types/genesis_test.go @@ -1,9 +1,10 @@ package types import ( + "testing" + "github.com/stretchr/testify/assert" "github.com/tendermint/go-crypto" - "testing" ) func TestGenesisBad(t *testing.T) { diff --git a/types/priv_validator/socket.go b/types/priv_validator/socket.go index 9f59a815..21b3f515 100644 --- a/types/priv_validator/socket.go +++ b/types/priv_validator/socket.go @@ -7,7 +7,7 @@ import ( "net" "time" - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/go-crypto" cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/tmlibs/log" diff --git a/types/priv_validator/wire.go b/types/priv_validator/wire.go index 68891083..5c00f02c 100644 --- a/types/priv_validator/wire.go +++ b/types/priv_validator/wire.go @@ -1,7 +1,7 @@ package privval import ( - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/go-crypto" ) diff --git a/types/wire.go b/types/wire.go index bd5c4497..cc589065 100644 --- a/types/wire.go +++ b/types/wire.go @@ -1,7 +1,7 @@ package types import ( - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/go-crypto" )