From 05075ea5b77adc028ef6c1f50cff065bf4f92b92 Mon Sep 17 00:00:00 2001 From: Phil Salant Date: Mon, 30 Sep 2019 20:12:51 -0400 Subject: [PATCH] linters: modify code to pass maligned and interfacer (#3959) * Fix maligned structs * Fix interfacer errors * Revert accidental go.mod and go.sum changes * Revert P2PConfig struct maligned reorder * Revert PeerRoundState struct maligned reordering * Revert RoundState struct maligned reordering * Reorder WSClient struct * Revert accidental type change * Clean up type change * Clean up type changes * Revert to types.ABCIApplicationServer in GRPCServer struct * Revert maligned changes to BaseConfig struct * Fix tests in io_test.go * Fix client_test package tests * Fix reactor tests in consensus package * Fix new interfacer errors --- abci/client/socket_client.go | 5 +- abci/example/example_test.go | 2 +- abci/server/socket_server.go | 4 +- abci/tests/benchmarks/simple/simple.go | 4 +- blockchain/v0/pool.go | 8 +-- consensus/reactor_test.go | 74 +++++++++++++------------- libs/events/events_test.go | 2 +- libs/flowrate/flowrate.go | 6 +-- libs/flowrate/io_test.go | 20 +++---- lite/proxy/proxy.go | 3 +- mempool/clist_mempool.go | 18 +++---- node/node.go | 4 +- p2p/conn/secret_connection.go | 4 +- p2p/conn/secret_connection_test.go | 5 +- p2p/pex/addrbook.go | 10 ++-- p2p/pex/known_address.go | 4 +- privval/socket_dialers.go | 4 +- rpc/client/rpc_test.go | 14 ++--- rpc/lib/client/ws_client.go | 22 ++++---- rpc/lib/client/ws_client_test.go | 13 +++-- rpc/lib/rpc_test.go | 8 +-- state/txindex/kv/kv.go | 4 +- store/store_test.go | 2 +- tools/tm-bench/main.go | 3 +- tools/tm-monitor/monitor/node.go | 12 ++--- 25 files changed, 128 insertions(+), 127 deletions(-) diff --git a/abci/client/socket_client.go b/abci/client/socket_client.go index 7b1e4cd8..062d50d4 100644 --- a/abci/client/socket_client.go +++ b/abci/client/socket_client.go @@ -5,6 +5,7 @@ import ( "container/list" "errors" "fmt" + "io" "net" "reflect" "sync" @@ -119,7 +120,7 @@ func (cli *socketClient) SetResponseCallback(resCb Callback) { //---------------------------------------- -func (cli *socketClient) sendRequestsRoutine(conn net.Conn) { +func (cli *socketClient) sendRequestsRoutine(conn io.Writer) { w := bufio.NewWriter(conn) for { @@ -151,7 +152,7 @@ func (cli *socketClient) sendRequestsRoutine(conn net.Conn) { } } -func (cli *socketClient) recvResponseRoutine(conn net.Conn) { +func (cli *socketClient) recvResponseRoutine(conn io.Reader) { r := bufio.NewReader(conn) // Buffer reads for { diff --git a/abci/example/example_test.go b/abci/example/example_test.go index 74510700..16354505 100644 --- a/abci/example/example_test.go +++ b/abci/example/example_test.go @@ -111,7 +111,7 @@ func dialerFunc(ctx context.Context, addr string) (net.Conn, error) { return cmn.Connect(addr) } -func testGRPCSync(t *testing.T, app *types.GRPCApplication) { +func testGRPCSync(t *testing.T, app types.ABCIApplicationServer) { numDeliverTxs := 2000 // Start the listener diff --git a/abci/server/socket_server.go b/abci/server/socket_server.go index 3e1d775d..8dbd934b 100644 --- a/abci/server/socket_server.go +++ b/abci/server/socket_server.go @@ -144,7 +144,7 @@ func (s *SocketServer) waitForClose(closeConn chan error, connID int) { } // Read requests from conn and deal with them -func (s *SocketServer) handleRequests(closeConn chan error, conn net.Conn, responses chan<- *types.Response) { +func (s *SocketServer) handleRequests(closeConn chan error, conn io.Reader, responses chan<- *types.Response) { var count int var bufReader = bufio.NewReader(conn) @@ -215,7 +215,7 @@ func (s *SocketServer) handleRequest(req *types.Request, responses chan<- *types } // Pull responses from 'responses' and write them to conn. -func (s *SocketServer) handleResponses(closeConn chan error, conn net.Conn, responses <-chan *types.Response) { +func (s *SocketServer) handleResponses(closeConn chan error, conn io.Writer, responses <-chan *types.Response) { var count int var bufWriter = bufio.NewWriter(conn) for { diff --git a/abci/tests/benchmarks/simple/simple.go b/abci/tests/benchmarks/simple/simple.go index b0819799..b5cfb044 100644 --- a/abci/tests/benchmarks/simple/simple.go +++ b/abci/tests/benchmarks/simple/simple.go @@ -3,8 +3,8 @@ package main import ( "bufio" "fmt" + "io" "log" - "net" "reflect" "github.com/tendermint/tendermint/abci/types" @@ -33,7 +33,7 @@ func main() { } } -func makeRequest(conn net.Conn, req *types.Request) (*types.Response, error) { +func makeRequest(conn io.ReadWriter, req *types.Request) (*types.Response, error) { var bufWriter = bufio.NewWriter(conn) // Write desired request diff --git a/blockchain/v0/pool.go b/blockchain/v0/pool.go index 7733dc5f..46684ecf 100644 --- a/blockchain/v0/pool.go +++ b/blockchain/v0/pool.go @@ -422,14 +422,14 @@ func (pool *BlockPool) debug() string { //------------------------------------- type bpPeer struct { + didTimeout bool + numPending int32 + height int64 pool *BlockPool id p2p.ID recvMonitor *flow.Monitor - height int64 - numPending int32 - timeout *time.Timer - didTimeout bool + timeout *time.Timer logger log.Logger } diff --git a/consensus/reactor_test.go b/consensus/reactor_test.go index 168f0792..afb793fd 100644 --- a/consensus/reactor_test.go +++ b/consensus/reactor_test.go @@ -640,19 +640,19 @@ func capture() { func TestNewRoundStepMessageValidateBasic(t *testing.T) { testCases := []struct { - testName string - messageHeight int64 - messageRound int - messageStep cstypes.RoundStepType - messageLastCommitRound int expectErr bool + messageRound int + messageLastCommitRound int + messageHeight int64 + testName string + messageStep cstypes.RoundStepType }{ - {"Valid Message", 0, 0, 0x01, 1, false}, - {"Invalid Message", -1, 0, 0x01, 1, true}, - {"Invalid Message", 0, -1, 0x01, 1, true}, - {"Invalid Message", 0, 0, 0x00, 1, true}, - {"Invalid Message", 0, 0, 0x00, 0, true}, - {"Invalid Message", 1, 0, 0x01, 0, true}, + {false, 0, 0, 0, "Valid Message", 0x01}, + {true, -1, 0, 0, "Invalid Message", 0x01}, + {true, 0, 0, -1, "Invalid Message", 0x01}, + {true, 0, 0, 1, "Invalid Message", 0x00}, + {true, 0, 0, 1, "Invalid Message", 0x00}, + {true, 0, -2, 2, "Invalid Message", 0x01}, } for _, tc := range testCases { @@ -770,18 +770,18 @@ func TestHasVoteMessageValidateBasic(t *testing.T) { ) testCases := []struct { - testName string - messageHeight int64 - messageRound int - messageType types.SignedMsgType - messageIndex int expectErr bool + messageRound int + messageIndex int + messageHeight int64 + testName string + messageType types.SignedMsgType }{ - {"Valid Message", 0, 0, validSignedMsgType, 0, false}, - {"Invalid Message", -1, 0, validSignedMsgType, 0, true}, - {"Invalid Message", 0, -1, validSignedMsgType, 0, true}, - {"Invalid Message", 0, 0, invalidSignedMsgType, 0, true}, - {"Invalid Message", 0, 0, validSignedMsgType, -1, true}, + {false, 0, 0, 0, "Valid Message", validSignedMsgType}, + {true, -1, 0, 0, "Invalid Message", validSignedMsgType}, + {true, 0, -1, 0, "Invalid Message", validSignedMsgType}, + {true, 0, 0, 0, "Invalid Message", invalidSignedMsgType}, + {true, 0, 0, -1, "Invalid Message", validSignedMsgType}, } for _, tc := range testCases { @@ -815,18 +815,18 @@ func TestVoteSetMaj23MessageValidateBasic(t *testing.T) { } testCases := []struct { - testName string - messageHeight int64 + expectErr bool messageRound int + messageHeight int64 + testName string messageType types.SignedMsgType messageBlockID types.BlockID - expectErr bool }{ - {"Valid Message", 0, 0, validSignedMsgType, validBlockID, false}, - {"Invalid Message", -1, 0, validSignedMsgType, validBlockID, true}, - {"Invalid Message", 0, -1, validSignedMsgType, validBlockID, true}, - {"Invalid Message", 0, 0, invalidSignedMsgType, validBlockID, true}, - {"Invalid Message", 0, 0, validSignedMsgType, invalidBlockID, true}, + {false, 0, 0, "Valid Message", validSignedMsgType, validBlockID}, + {true, -1, 0, "Invalid Message", validSignedMsgType, validBlockID}, + {true, 0, -1, "Invalid Message", validSignedMsgType, validBlockID}, + {true, 0, 0, "Invalid Message", invalidSignedMsgType, validBlockID}, + {true, 0, 0, "Invalid Message", validSignedMsgType, invalidBlockID}, } for _, tc := range testCases { @@ -861,19 +861,19 @@ func TestVoteSetBitsMessageValidateBasic(t *testing.T) { testBitArray := cmn.NewBitArray(1) testCases := []struct { - testName string - messageHeight int64 + expectErr bool messageRound int + messageHeight int64 + testName string messageType types.SignedMsgType messageBlockID types.BlockID messageVotes *cmn.BitArray - expectErr bool }{ - {"Valid Message", 0, 0, validSignedMsgType, validBlockID, testBitArray, false}, - {"Invalid Message", -1, 0, validSignedMsgType, validBlockID, testBitArray, true}, - {"Invalid Message", 0, -1, validSignedMsgType, validBlockID, testBitArray, true}, - {"Invalid Message", 0, 0, invalidSignedMsgType, validBlockID, testBitArray, true}, - {"Invalid Message", 0, 0, validSignedMsgType, invalidBlockID, testBitArray, true}, + {false, 0, 0, "Valid Message", validSignedMsgType, validBlockID, testBitArray}, + {true, -1, 0, "Invalid Message", validSignedMsgType, validBlockID, testBitArray}, + {true, 0, -1, "Invalid Message", validSignedMsgType, validBlockID, testBitArray}, + {true, 0, 0, "Invalid Message", invalidSignedMsgType, validBlockID, testBitArray}, + {true, 0, 0, "Invalid Message", validSignedMsgType, invalidBlockID, testBitArray}, } for _, tc := range testCases { diff --git a/libs/events/events_test.go b/libs/events/events_test.go index 8d87986c..e5a0e869 100644 --- a/libs/events/events_test.go +++ b/libs/events/events_test.go @@ -418,7 +418,7 @@ func sumReceivedNumbers(numbers, doneSum chan uint64) { // to `offset` + 999. It additionally returns the addition of all integers // sent on `doneChan` for assertion that all events have been sent, and enabling // the test to assert all events have also been received. -func fireEvents(evsw EventSwitch, event string, doneChan chan uint64, +func fireEvents(evsw Fireable, event string, doneChan chan uint64, offset uint64) { var sentSum uint64 for i := offset; i <= offset+uint64(999); i++ { diff --git a/libs/flowrate/flowrate.go b/libs/flowrate/flowrate.go index e233eae0..35ebfbde 100644 --- a/libs/flowrate/flowrate.go +++ b/libs/flowrate/flowrate.go @@ -108,9 +108,6 @@ const timeRemLimit = 999*time.Hour + 59*time.Minute + 59*time.Second // per second rounded to the nearest byte. type Status struct { Active bool // Flag indicating an active transfer - Start time.Time // Transfer start time - Duration time.Duration // Time period covered by the statistics - Idle time.Duration // Time since the last transfer of at least 1 byte Bytes int64 // Total number of bytes transferred Samples int64 // Total number of samples taken InstRate int64 // Instantaneous transfer rate @@ -118,6 +115,9 @@ type Status struct { AvgRate int64 // Average transfer rate (Bytes / Duration) PeakRate int64 // Maximum instantaneous transfer rate BytesRem int64 // Number of bytes remaining in the transfer + Start time.Time // Transfer start time + Duration time.Duration // Time period covered by the statistics + Idle time.Duration // Time since the last transfer of at least 1 byte TimeRem time.Duration // Estimated time to completion Progress Percent // Overall transfer progress } diff --git a/libs/flowrate/io_test.go b/libs/flowrate/io_test.go index d482a7b7..0bb1a591 100644 --- a/libs/flowrate/io_test.go +++ b/libs/flowrate/io_test.go @@ -79,14 +79,14 @@ func TestReader(t *testing.T) { status[5] = nextStatus(r.Monitor) // Timeout start = status[0].Start - // Active, Start, Duration, Idle, Bytes, Samples, InstRate, CurRate, AvgRate, PeakRate, BytesRem, TimeRem, Progress + // Active, Bytes, Samples, InstRate, CurRate, AvgRate, PeakRate, BytesRem, Start, Duration, Idle, TimeRem, Progress want := []Status{ - {true, start, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {true, start, _100ms, 0, 10, 1, 100, 100, 100, 100, 0, 0, 0}, - {true, start, _200ms, _100ms, 20, 2, 100, 100, 100, 100, 0, 0, 0}, - {true, start, _300ms, _200ms, 20, 3, 0, 90, 67, 100, 0, 0, 0}, - {false, start, _300ms, 0, 20, 3, 0, 0, 67, 100, 0, 0, 0}, - {false, start, _300ms, 0, 20, 3, 0, 0, 67, 100, 0, 0, 0}, + {true, 0, 0, 0, 0, 0, 0, 0, start, 0, 0, 0, 0}, + {true, 10, 1, 100, 100, 100, 100, 0, start, _100ms, 0, 0, 0}, + {true, 20, 2, 100, 100, 100, 100, 0, start, _200ms, _100ms, 0, 0}, + {true, 20, 3, 0, 90, 67, 100, 0, start, _300ms, _200ms, 0, 0}, + {false, 20, 3, 0, 0, 67, 100, 0, start, _300ms, 0, 0, 0}, + {false, 20, 3, 0, 0, 67, 100, 0, start, _300ms, 0, 0, 0}, } for i, s := range status { s := s @@ -138,10 +138,10 @@ func TestWriter(t *testing.T) { status := []Status{w.Status(), nextStatus(w.Monitor)} start = status[0].Start - // Active, Start, Duration, Idle, Bytes, Samples, InstRate, CurRate, AvgRate, PeakRate, BytesRem, TimeRem, Progress + // Active, Bytes, Samples, InstRate, CurRate, AvgRate, PeakRate, BytesRem, Start, Duration, Idle, TimeRem, Progress want := []Status{ - {true, start, _400ms, 0, 80, 4, 200, 200, 200, 200, 20, _100ms, 80000}, - {true, start, _500ms, _100ms, 100, 5, 200, 200, 200, 200, 0, 0, 100000}, + {true, 80, 4, 200, 200, 200, 200, 20, start, _400ms, 0, _100ms, 80000}, + {true, 100, 5, 200, 200, 200, 200, 0, start, _500ms, _100ms, 0, 100000}, } for i, s := range status { s := s diff --git a/lite/proxy/proxy.go b/lite/proxy/proxy.go index 80343a53..6d56c12c 100644 --- a/lite/proxy/proxy.go +++ b/lite/proxy/proxy.go @@ -8,6 +8,7 @@ import ( cmn "github.com/tendermint/tendermint/libs/common" "github.com/tendermint/tendermint/libs/log" + "github.com/tendermint/tendermint/rpc/client" rpcclient "github.com/tendermint/tendermint/rpc/client" "github.com/tendermint/tendermint/rpc/core" ctypes "github.com/tendermint/tendermint/rpc/core/types" @@ -88,7 +89,7 @@ func RPCRoutes(c rpcclient.Client) map[string]*rpcserver.RPCFunc { } } -func makeStatusFunc(c rpcclient.Client) func(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) { +func makeStatusFunc(c client.StatusClient) func(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) { return func(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) { return c.Status() } diff --git a/mempool/clist_mempool.go b/mempool/clist_mempool.go index ee47e52d..554839f1 100644 --- a/mempool/clist_mempool.go +++ b/mempool/clist_mempool.go @@ -29,6 +29,15 @@ import ( // mempool uses a concurrent list structure for storing transactions that can // be efficiently accessed by multiple concurrent readers. type CListMempool struct { + // Atomic integers + height int64 // the last block Update()'d to + txsBytes int64 // total size of mempool, in bytes + rechecking int32 // for re-checking filtered txs on Update() + + // notify listeners (ie. consensus) when txs are available + notifiedTxsAvailable bool + txsAvailable chan struct{} // fires once for each height, when the mempool is not empty + config *cfg.MempoolConfig proxyMtx sync.Mutex @@ -43,19 +52,10 @@ type CListMempool struct { recheckCursor *clist.CElement // next expected response recheckEnd *clist.CElement // re-checking stops here - // notify listeners (ie. consensus) when txs are available - notifiedTxsAvailable bool - txsAvailable chan struct{} // fires once for each height, when the mempool is not empty - // Map for quick access to txs to record sender in CheckTx. // txsMap: txKey -> CElement txsMap sync.Map - // Atomic integers - height int64 // the last block Update()'d to - txsBytes int64 // total size of mempool, in bytes - rechecking int32 // for re-checking filtered txs on Update() - // Keep a cache of already-seen txs. // This reduces the pressure on the proxyApp. cache txCache diff --git a/node/node.go b/node/node.go index 5c98ea5b..fc80c6b7 100644 --- a/node/node.go +++ b/node/node.go @@ -267,7 +267,7 @@ func createAndStartIndexerService(config *cfg.Config, dbProvider DBProvider, } func doHandshake(stateDB dbm.DB, state sm.State, blockStore sm.BlockStore, - genDoc *types.GenesisDoc, eventBus *types.EventBus, proxyApp proxy.AppConns, consensusLogger log.Logger) error { + genDoc *types.GenesisDoc, eventBus types.BlockEventPublisher, proxyApp proxy.AppConns, consensusLogger log.Logger) error { handshaker := cs.NewHandshaker(stateDB, state, blockStore, genDoc) handshaker.SetLogger(consensusLogger) @@ -457,7 +457,7 @@ func createTransport(config *cfg.Config, nodeInfo p2p.NodeInfo, nodeKey *p2p.Nod } func createSwitch(config *cfg.Config, - transport *p2p.MultiplexTransport, + transport p2p.Transport, p2pMetrics *p2p.Metrics, peerFilters []p2p.PeerFilterFunc, mempoolReactor *mempl.Reactor, diff --git a/p2p/conn/secret_connection.go b/p2p/conn/secret_connection.go index c8e450f5..7f906144 100644 --- a/p2p/conn/secret_connection.go +++ b/p2p/conn/secret_connection.go @@ -262,7 +262,7 @@ func genEphKeys() (ephPub, ephPriv *[32]byte) { return } -func shareEphPubKey(conn io.ReadWriteCloser, locEphPub *[32]byte) (remEphPub *[32]byte, err error) { +func shareEphPubKey(conn io.ReadWriter, locEphPub *[32]byte) (remEphPub *[32]byte, err error) { // Send our pubkey and receive theirs in tandem. var trs, _ = cmn.Parallel( @@ -416,7 +416,7 @@ type authSigMessage struct { Sig []byte } -func shareAuthSignature(sc *SecretConnection, pubKey crypto.PubKey, signature []byte) (recvMsg authSigMessage, err error) { +func shareAuthSignature(sc io.ReadWriter, pubKey crypto.PubKey, signature []byte) (recvMsg authSigMessage, err error) { // Send our info and receive theirs in tandem. var trs, _ = cmn.Parallel( diff --git a/p2p/conn/secret_connection_test.go b/p2p/conn/secret_connection_test.go index 0b7cc00c..743fcf4c 100644 --- a/p2p/conn/secret_connection_test.go +++ b/p2p/conn/secret_connection_test.go @@ -7,7 +7,6 @@ import ( "fmt" "io" "log" - "net" "os" "path/filepath" "strconv" @@ -189,7 +188,7 @@ func TestConcurrentRead(t *testing.T) { } } -func writeLots(t *testing.T, wg *sync.WaitGroup, conn net.Conn, txt string, n int) { +func writeLots(t *testing.T, wg *sync.WaitGroup, conn io.Writer, txt string, n int) { defer wg.Done() for i := 0; i < n; i++ { _, err := conn.Write([]byte(txt)) @@ -200,7 +199,7 @@ func writeLots(t *testing.T, wg *sync.WaitGroup, conn net.Conn, txt string, n in } } -func readLots(t *testing.T, wg *sync.WaitGroup, conn net.Conn, n int) { +func readLots(t *testing.T, wg *sync.WaitGroup, conn io.Reader, n int) { readBuffer := make([]byte, dataMaxSize) for i := 0; i < n; i++ { _, err := conn.Read(readBuffer) diff --git a/p2p/pex/addrbook.go b/p2p/pex/addrbook.go index a64eb28a..344df295 100644 --- a/p2p/pex/addrbook.go +++ b/p2p/pex/addrbook.go @@ -79,11 +79,6 @@ var _ AddrBook = (*addrBook)(nil) type addrBook struct { cmn.BaseService - // immutable after creation - filePath string - routabilityStrict bool - key string // random prefix for bucket placement - // accessed concurrently mtx sync.Mutex rand *cmn.Rand @@ -95,6 +90,11 @@ type addrBook struct { nOld int nNew int + // immutable after creation + filePath string + key string // random prefix for bucket placement + routabilityStrict bool + wg sync.WaitGroup } diff --git a/p2p/pex/known_address.go b/p2p/pex/known_address.go index acde385b..af40d6ff 100644 --- a/p2p/pex/known_address.go +++ b/p2p/pex/known_address.go @@ -11,11 +11,11 @@ import ( type knownAddress struct { Addr *p2p.NetAddress `json:"addr"` Src *p2p.NetAddress `json:"src"` + Buckets []int `json:"buckets"` Attempts int32 `json:"attempts"` + BucketType byte `json:"bucket_type"` LastAttempt time.Time `json:"last_attempt"` LastSuccess time.Time `json:"last_success"` - BucketType byte `json:"bucket_type"` - Buckets []int `json:"buckets"` } func newKnownAddress(addr *p2p.NetAddress, src *p2p.NetAddress) *knownAddress { diff --git a/privval/socket_dialers.go b/privval/socket_dialers.go index c92a1c8c..fb1f9477 100644 --- a/privval/socket_dialers.go +++ b/privval/socket_dialers.go @@ -5,7 +5,7 @@ import ( "time" "github.com/pkg/errors" - "github.com/tendermint/tendermint/crypto/ed25519" + "github.com/tendermint/tendermint/crypto" cmn "github.com/tendermint/tendermint/libs/common" p2pconn "github.com/tendermint/tendermint/p2p/conn" ) @@ -20,7 +20,7 @@ type SocketDialer func() (net.Conn, error) // DialTCPFn dials the given tcp addr, using the given timeoutReadWrite and // privKey for the authenticated encryption handshake. -func DialTCPFn(addr string, timeoutReadWrite time.Duration, privKey ed25519.PrivKeyEd25519) SocketDialer { +func DialTCPFn(addr string, timeoutReadWrite time.Duration, privKey crypto.PrivKey) SocketDialer { return func() (net.Conn, error) { conn, err := cmn.Connect(addr) if err == nil { diff --git a/rpc/client/rpc_test.go b/rpc/client/rpc_test.go index 8bcbd313..31896228 100644 --- a/rpc/client/rpc_test.go +++ b/rpc/client/rpc_test.go @@ -364,16 +364,16 @@ func TestTx(t *testing.T) { cases := []struct { valid bool - hash []byte prove bool + hash []byte }{ // only valid if correct hash provided - {true, txHash, false}, - {true, txHash, true}, - {false, anotherTxHash, false}, - {false, anotherTxHash, true}, - {false, nil, false}, - {false, nil, true}, + {true, false, txHash}, + {true, true, txHash}, + {false, false, anotherTxHash}, + {false, true, anotherTxHash}, + {false, false, nil}, + {false, true, nil}, } for i, c := range GetClients() { diff --git a/rpc/lib/client/ws_client.go b/rpc/lib/client/ws_client.go index 1779e9db..52de8d13 100644 --- a/rpc/lib/client/ws_client.go +++ b/rpc/lib/client/ws_client.go @@ -28,8 +28,6 @@ const ( // WSClient is a WebSocket client. The methods of WSClient are safe for use by // multiple goroutines. type WSClient struct { - cmn.BaseService - conn *websocket.Conn cdc *amino.Codec @@ -37,10 +35,6 @@ type WSClient struct { Endpoint string // /websocket/url/endpoint Dialer func(string, string) (net.Conn, error) - // Time between sending a ping and receiving a pong. See - // https://godoc.org/github.com/rcrowley/go-metrics#Timer. - PingPongLatencyTimer metrics.Timer - // Single user facing channel to read RPCResponses from, closed only when the client is being stopped. ResponsesCh chan types.RPCResponse @@ -53,15 +47,18 @@ type WSClient struct { reconnectAfter chan error // reconnect requests readRoutineQuit chan struct{} // a way for readRoutine to close writeRoutine + // Maximum reconnect attempts (0 or greater; default: 25). + maxReconnectAttempts int + + // Support both ws and wss protocols + protocol string + wg sync.WaitGroup mtx sync.RWMutex sentLastPingAt time.Time reconnecting bool - // Maximum reconnect attempts (0 or greater; default: 25). - maxReconnectAttempts int - // Time allowed to write a message to the server. 0 means block until operation succeeds. writeWait time.Duration @@ -71,8 +68,11 @@ type WSClient struct { // Send pings to server with this period. Must be less than readWait. If 0, no pings will be sent. pingPeriod time.Duration - // Support both ws and wss protocols - protocol string + cmn.BaseService + + // Time between sending a ping and receiving a pong. See + // https://godoc.org/github.com/rcrowley/go-metrics#Timer. + PingPongLatencyTimer metrics.Timer } // NewWSClient returns a new client. See the commentary on the func(*WSClient) diff --git a/rpc/lib/client/ws_client_test.go b/rpc/lib/client/ws_client_test.go index 4f2cc9ad..1babdae9 100644 --- a/rpc/lib/client/ws_client_test.go +++ b/rpc/lib/client/ws_client_test.go @@ -3,7 +3,6 @@ package rpcclient import ( "context" "encoding/json" - "net" "net/http" "net/http/httptest" "sync" @@ -65,7 +64,7 @@ func TestWSClientReconnectsAfterReadFailure(t *testing.T) { s := httptest.NewServer(h) defer s.Close() - c := startClient(t, s.Listener.Addr()) + c := startClient(t, s.Listener.Addr().String()) defer c.Stop() wg.Add(1) @@ -97,7 +96,7 @@ func TestWSClientReconnectsAfterWriteFailure(t *testing.T) { h := &myHandler{} s := httptest.NewServer(h) - c := startClient(t, s.Listener.Addr()) + c := startClient(t, s.Listener.Addr().String()) defer c.Stop() wg.Add(2) @@ -125,7 +124,7 @@ func TestWSClientReconnectFailure(t *testing.T) { h := &myHandler{} s := httptest.NewServer(h) - c := startClient(t, s.Listener.Addr()) + c := startClient(t, s.Listener.Addr().String()) defer c.Stop() go func() { @@ -174,7 +173,7 @@ func TestWSClientReconnectFailure(t *testing.T) { func TestNotBlockingOnStop(t *testing.T) { timeout := 2 * time.Second s := httptest.NewServer(&myHandler{}) - c := startClient(t, s.Listener.Addr()) + c := startClient(t, s.Listener.Addr().String()) c.Call(context.Background(), "a", make(map[string]interface{})) // Let the readRoutine get around to blocking time.Sleep(time.Second) @@ -194,8 +193,8 @@ func TestNotBlockingOnStop(t *testing.T) { } } -func startClient(t *testing.T, addr net.Addr) *WSClient { - c := NewWSClient(addr.String(), "/websocket") +func startClient(t *testing.T, addr string) *WSClient { + c := NewWSClient(addr, "/websocket") err := c.Start() require.Nil(t, err) c.SetLogger(log.TestingLogger()) diff --git a/rpc/lib/rpc_test.go b/rpc/lib/rpc_test.go index 9af5728a..782ba8ea 100644 --- a/rpc/lib/rpc_test.go +++ b/rpc/lib/rpc_test.go @@ -146,7 +146,7 @@ func setup() { time.Sleep(time.Second * 2) } -func echoViaHTTP(cl client.HTTPClient, val string) (string, error) { +func echoViaHTTP(cl client.JSONRPCCaller, val string) (string, error) { params := map[string]interface{}{ "arg": val, } @@ -157,7 +157,7 @@ func echoViaHTTP(cl client.HTTPClient, val string) (string, error) { return result.Value, nil } -func echoIntViaHTTP(cl client.HTTPClient, val int) (int, error) { +func echoIntViaHTTP(cl client.JSONRPCCaller, val int) (int, error) { params := map[string]interface{}{ "arg": val, } @@ -168,7 +168,7 @@ func echoIntViaHTTP(cl client.HTTPClient, val int) (int, error) { return result.Value, nil } -func echoBytesViaHTTP(cl client.HTTPClient, bytes []byte) ([]byte, error) { +func echoBytesViaHTTP(cl client.JSONRPCCaller, bytes []byte) ([]byte, error) { params := map[string]interface{}{ "arg": bytes, } @@ -179,7 +179,7 @@ func echoBytesViaHTTP(cl client.HTTPClient, bytes []byte) ([]byte, error) { return result.Value, nil } -func echoDataBytesViaHTTP(cl client.HTTPClient, bytes cmn.HexBytes) (cmn.HexBytes, error) { +func echoDataBytesViaHTTP(cl client.JSONRPCCaller, bytes cmn.HexBytes) (cmn.HexBytes, error) { params := map[string]interface{}{ "arg": bytes, } diff --git a/state/txindex/kv/kv.go b/state/txindex/kv/kv.go index 2695e18a..77453416 100644 --- a/state/txindex/kv/kv.go +++ b/state/txindex/kv/kv.go @@ -276,10 +276,10 @@ func lookForHeight(conditions []query.Condition) (height int64) { type queryRanges map[string]queryRange type queryRange struct { - key string lowerBound interface{} // int || time.Time - includeLowerBound bool upperBound interface{} // int || time.Time + key string + includeLowerBound bool includeUpperBound bool } diff --git a/store/store_test.go b/store/store_test.go index fd148f7b..73ab6858 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -169,8 +169,8 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) { block *types.Block parts *types.PartSet seenCommit *types.Commit - wantErr bool wantPanic string + wantErr bool corruptBlockInDB bool corruptCommitInDB bool diff --git a/tools/tm-bench/main.go b/tools/tm-bench/main.go index 432ebc8f..787096ef 100644 --- a/tools/tm-bench/main.go +++ b/tools/tm-bench/main.go @@ -12,6 +12,7 @@ import ( cmn "github.com/tendermint/tendermint/libs/common" "github.com/tendermint/tendermint/libs/log" + "github.com/tendermint/tendermint/rpc/client" tmrpc "github.com/tendermint/tendermint/rpc/client" ) @@ -133,7 +134,7 @@ Examples: printStatistics(stats, outputFormat) } -func latestBlockHeight(client tmrpc.Client) int64 { +func latestBlockHeight(client client.StatusClient) int64 { status, err := client.Status() if err != nil { fmt.Fprintln(os.Stderr, err) diff --git a/tools/tm-monitor/monitor/node.go b/tools/tm-monitor/monitor/node.go index c16f0609..1ccb3558 100644 --- a/tools/tm-monitor/monitor/node.go +++ b/tools/tm-monitor/monitor/node.go @@ -19,14 +19,14 @@ import ( const maxRestarts = 25 type Node struct { - rpcAddr string + IsValidator bool `json:"is_validator"` // validator or non-validator? + Online bool `json:"online"` + Height int64 `json:"height"` + rpcAddr string + Name string `json:"name"` - IsValidator bool `json:"is_validator"` // validator or non-validator? - pubKey crypto.PubKey + pubKey crypto.PubKey - Name string `json:"name"` - Online bool `json:"online"` - Height int64 `json:"height"` BlockLatency float64 `json:"block_latency" amino:"unsafe"` // ms, interval between block commits // em holds the ws connection. Each eventMeter callback is called in a separate go-routine.