Browse Source

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
pull/4025/head
Phil Salant 5 years ago
committed by Anton Kaliaev
parent
commit
05075ea5b7
25 changed files with 126 additions and 125 deletions
  1. +3
    -2
      abci/client/socket_client.go
  2. +1
    -1
      abci/example/example_test.go
  3. +2
    -2
      abci/server/socket_server.go
  4. +2
    -2
      abci/tests/benchmarks/simple/simple.go
  5. +4
    -4
      blockchain/v0/pool.go
  6. +35
    -35
      consensus/reactor_test.go
  7. +1
    -1
      libs/events/events_test.go
  8. +3
    -3
      libs/flowrate/flowrate.go
  9. +10
    -10
      libs/flowrate/io_test.go
  10. +2
    -1
      lite/proxy/proxy.go
  11. +9
    -9
      mempool/clist_mempool.go
  12. +2
    -2
      node/node.go
  13. +2
    -2
      p2p/conn/secret_connection.go
  14. +2
    -3
      p2p/conn/secret_connection_test.go
  15. +5
    -5
      p2p/pex/addrbook.go
  16. +2
    -2
      p2p/pex/known_address.go
  17. +2
    -2
      privval/socket_dialers.go
  18. +7
    -7
      rpc/client/rpc_test.go
  19. +11
    -11
      rpc/lib/client/ws_client.go
  20. +6
    -7
      rpc/lib/client/ws_client_test.go
  21. +4
    -4
      rpc/lib/rpc_test.go
  22. +2
    -2
      state/txindex/kv/kv.go
  23. +1
    -1
      store/store_test.go
  24. +2
    -1
      tools/tm-bench/main.go
  25. +6
    -6
      tools/tm-monitor/monitor/node.go

+ 3
- 2
abci/client/socket_client.go View File

@ -5,6 +5,7 @@ import (
"container/list" "container/list"
"errors" "errors"
"fmt" "fmt"
"io"
"net" "net"
"reflect" "reflect"
"sync" "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) w := bufio.NewWriter(conn)
for { 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 r := bufio.NewReader(conn) // Buffer reads
for { for {


+ 1
- 1
abci/example/example_test.go View File

@ -111,7 +111,7 @@ func dialerFunc(ctx context.Context, addr string) (net.Conn, error) {
return cmn.Connect(addr) return cmn.Connect(addr)
} }
func testGRPCSync(t *testing.T, app *types.GRPCApplication) {
func testGRPCSync(t *testing.T, app types.ABCIApplicationServer) {
numDeliverTxs := 2000 numDeliverTxs := 2000
// Start the listener // Start the listener


+ 2
- 2
abci/server/socket_server.go View File

@ -144,7 +144,7 @@ func (s *SocketServer) waitForClose(closeConn chan error, connID int) {
} }
// Read requests from conn and deal with them // 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 count int
var bufReader = bufio.NewReader(conn) 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. // 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 count int
var bufWriter = bufio.NewWriter(conn) var bufWriter = bufio.NewWriter(conn)
for { for {


+ 2
- 2
abci/tests/benchmarks/simple/simple.go View File

@ -3,8 +3,8 @@ package main
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"io"
"log" "log"
"net"
"reflect" "reflect"
"github.com/tendermint/tendermint/abci/types" "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) var bufWriter = bufio.NewWriter(conn)
// Write desired request // Write desired request


+ 4
- 4
blockchain/v0/pool.go View File

@ -422,14 +422,14 @@ func (pool *BlockPool) debug() string {
//------------------------------------- //-------------------------------------
type bpPeer struct { type bpPeer struct {
didTimeout bool
numPending int32
height int64
pool *BlockPool pool *BlockPool
id p2p.ID id p2p.ID
recvMonitor *flow.Monitor recvMonitor *flow.Monitor
height int64
numPending int32
timeout *time.Timer
didTimeout bool
timeout *time.Timer
logger log.Logger logger log.Logger
} }


+ 35
- 35
consensus/reactor_test.go View File

@ -640,19 +640,19 @@ func capture() {
func TestNewRoundStepMessageValidateBasic(t *testing.T) { func TestNewRoundStepMessageValidateBasic(t *testing.T) {
testCases := []struct { testCases := []struct {
testName string
messageHeight int64
expectErr bool
messageRound int messageRound int
messageStep cstypes.RoundStepType
messageLastCommitRound int messageLastCommitRound int
expectErr bool
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 { for _, tc := range testCases {
@ -770,18 +770,18 @@ func TestHasVoteMessageValidateBasic(t *testing.T) {
) )
testCases := []struct { testCases := []struct {
testName string
messageHeight int64
expectErr bool
messageRound int messageRound int
messageType types.SignedMsgType
messageIndex int messageIndex int
expectErr bool
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 { for _, tc := range testCases {
@ -815,18 +815,18 @@ func TestVoteSetMaj23MessageValidateBasic(t *testing.T) {
} }
testCases := []struct { testCases := []struct {
testName string
messageHeight int64
expectErr bool
messageRound int messageRound int
messageHeight int64
testName string
messageType types.SignedMsgType messageType types.SignedMsgType
messageBlockID types.BlockID 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 { for _, tc := range testCases {
@ -861,19 +861,19 @@ func TestVoteSetBitsMessageValidateBasic(t *testing.T) {
testBitArray := cmn.NewBitArray(1) testBitArray := cmn.NewBitArray(1)
testCases := []struct { testCases := []struct {
testName string
messageHeight int64
expectErr bool
messageRound int messageRound int
messageHeight int64
testName string
messageType types.SignedMsgType messageType types.SignedMsgType
messageBlockID types.BlockID messageBlockID types.BlockID
messageVotes *cmn.BitArray 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 { for _, tc := range testCases {


+ 1
- 1
libs/events/events_test.go View File

@ -418,7 +418,7 @@ func sumReceivedNumbers(numbers, doneSum chan uint64) {
// to `offset` + 999. It additionally returns the addition of all integers // to `offset` + 999. It additionally returns the addition of all integers
// sent on `doneChan` for assertion that all events have been sent, and enabling // sent on `doneChan` for assertion that all events have been sent, and enabling
// the test to assert all events have also been received. // 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) { offset uint64) {
var sentSum uint64 var sentSum uint64
for i := offset; i <= offset+uint64(999); i++ { for i := offset; i <= offset+uint64(999); i++ {


+ 3
- 3
libs/flowrate/flowrate.go View File

@ -108,9 +108,6 @@ const timeRemLimit = 999*time.Hour + 59*time.Minute + 59*time.Second
// per second rounded to the nearest byte. // per second rounded to the nearest byte.
type Status struct { type Status struct {
Active bool // Flag indicating an active transfer 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 Bytes int64 // Total number of bytes transferred
Samples int64 // Total number of samples taken Samples int64 // Total number of samples taken
InstRate int64 // Instantaneous transfer rate InstRate int64 // Instantaneous transfer rate
@ -118,6 +115,9 @@ type Status struct {
AvgRate int64 // Average transfer rate (Bytes / Duration) AvgRate int64 // Average transfer rate (Bytes / Duration)
PeakRate int64 // Maximum instantaneous transfer rate PeakRate int64 // Maximum instantaneous transfer rate
BytesRem int64 // Number of bytes remaining in the transfer 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 TimeRem time.Duration // Estimated time to completion
Progress Percent // Overall transfer progress Progress Percent // Overall transfer progress
} }


+ 10
- 10
libs/flowrate/io_test.go View File

@ -79,14 +79,14 @@ func TestReader(t *testing.T) {
status[5] = nextStatus(r.Monitor) // Timeout status[5] = nextStatus(r.Monitor) // Timeout
start = status[0].Start 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{ 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 { for i, s := range status {
s := s s := s
@ -138,10 +138,10 @@ func TestWriter(t *testing.T) {
status := []Status{w.Status(), nextStatus(w.Monitor)} status := []Status{w.Status(), nextStatus(w.Monitor)}
start = status[0].Start 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{ 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 { for i, s := range status {
s := s s := s


+ 2
- 1
lite/proxy/proxy.go View File

@ -8,6 +8,7 @@ import (
cmn "github.com/tendermint/tendermint/libs/common" cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/rpc/client"
rpcclient "github.com/tendermint/tendermint/rpc/client" rpcclient "github.com/tendermint/tendermint/rpc/client"
"github.com/tendermint/tendermint/rpc/core" "github.com/tendermint/tendermint/rpc/core"
ctypes "github.com/tendermint/tendermint/rpc/core/types" 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 func(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) {
return c.Status() return c.Status()
} }


+ 9
- 9
mempool/clist_mempool.go View File

@ -29,6 +29,15 @@ import (
// mempool uses a concurrent list structure for storing transactions that can // mempool uses a concurrent list structure for storing transactions that can
// be efficiently accessed by multiple concurrent readers. // be efficiently accessed by multiple concurrent readers.
type CListMempool struct { 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 config *cfg.MempoolConfig
proxyMtx sync.Mutex proxyMtx sync.Mutex
@ -43,19 +52,10 @@ type CListMempool struct {
recheckCursor *clist.CElement // next expected response recheckCursor *clist.CElement // next expected response
recheckEnd *clist.CElement // re-checking stops here 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. // Map for quick access to txs to record sender in CheckTx.
// txsMap: txKey -> CElement // txsMap: txKey -> CElement
txsMap sync.Map 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. // Keep a cache of already-seen txs.
// This reduces the pressure on the proxyApp. // This reduces the pressure on the proxyApp.
cache txCache cache txCache


+ 2
- 2
node/node.go View File

@ -267,7 +267,7 @@ func createAndStartIndexerService(config *cfg.Config, dbProvider DBProvider,
} }
func doHandshake(stateDB dbm.DB, state sm.State, blockStore sm.BlockStore, 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 := cs.NewHandshaker(stateDB, state, blockStore, genDoc)
handshaker.SetLogger(consensusLogger) handshaker.SetLogger(consensusLogger)
@ -457,7 +457,7 @@ func createTransport(config *cfg.Config, nodeInfo p2p.NodeInfo, nodeKey *p2p.Nod
} }
func createSwitch(config *cfg.Config, func createSwitch(config *cfg.Config,
transport *p2p.MultiplexTransport,
transport p2p.Transport,
p2pMetrics *p2p.Metrics, p2pMetrics *p2p.Metrics,
peerFilters []p2p.PeerFilterFunc, peerFilters []p2p.PeerFilterFunc,
mempoolReactor *mempl.Reactor, mempoolReactor *mempl.Reactor,


+ 2
- 2
p2p/conn/secret_connection.go View File

@ -262,7 +262,7 @@ func genEphKeys() (ephPub, ephPriv *[32]byte) {
return 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. // Send our pubkey and receive theirs in tandem.
var trs, _ = cmn.Parallel( var trs, _ = cmn.Parallel(
@ -416,7 +416,7 @@ type authSigMessage struct {
Sig []byte 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. // Send our info and receive theirs in tandem.
var trs, _ = cmn.Parallel( var trs, _ = cmn.Parallel(


+ 2
- 3
p2p/conn/secret_connection_test.go View File

@ -7,7 +7,6 @@ import (
"fmt" "fmt"
"io" "io"
"log" "log"
"net"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "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() defer wg.Done()
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
_, err := conn.Write([]byte(txt)) _, 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) readBuffer := make([]byte, dataMaxSize)
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
_, err := conn.Read(readBuffer) _, err := conn.Read(readBuffer)


+ 5
- 5
p2p/pex/addrbook.go View File

@ -79,11 +79,6 @@ var _ AddrBook = (*addrBook)(nil)
type addrBook struct { type addrBook struct {
cmn.BaseService cmn.BaseService
// immutable after creation
filePath string
routabilityStrict bool
key string // random prefix for bucket placement
// accessed concurrently // accessed concurrently
mtx sync.Mutex mtx sync.Mutex
rand *cmn.Rand rand *cmn.Rand
@ -95,6 +90,11 @@ type addrBook struct {
nOld int nOld int
nNew int nNew int
// immutable after creation
filePath string
key string // random prefix for bucket placement
routabilityStrict bool
wg sync.WaitGroup wg sync.WaitGroup
} }


+ 2
- 2
p2p/pex/known_address.go View File

@ -11,11 +11,11 @@ import (
type knownAddress struct { type knownAddress struct {
Addr *p2p.NetAddress `json:"addr"` Addr *p2p.NetAddress `json:"addr"`
Src *p2p.NetAddress `json:"src"` Src *p2p.NetAddress `json:"src"`
Buckets []int `json:"buckets"`
Attempts int32 `json:"attempts"` Attempts int32 `json:"attempts"`
BucketType byte `json:"bucket_type"`
LastAttempt time.Time `json:"last_attempt"` LastAttempt time.Time `json:"last_attempt"`
LastSuccess time.Time `json:"last_success"` LastSuccess time.Time `json:"last_success"`
BucketType byte `json:"bucket_type"`
Buckets []int `json:"buckets"`
} }
func newKnownAddress(addr *p2p.NetAddress, src *p2p.NetAddress) *knownAddress { func newKnownAddress(addr *p2p.NetAddress, src *p2p.NetAddress) *knownAddress {


+ 2
- 2
privval/socket_dialers.go View File

@ -5,7 +5,7 @@ import (
"time" "time"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto"
cmn "github.com/tendermint/tendermint/libs/common" cmn "github.com/tendermint/tendermint/libs/common"
p2pconn "github.com/tendermint/tendermint/p2p/conn" 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 // DialTCPFn dials the given tcp addr, using the given timeoutReadWrite and
// privKey for the authenticated encryption handshake. // 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) { return func() (net.Conn, error) {
conn, err := cmn.Connect(addr) conn, err := cmn.Connect(addr)
if err == nil { if err == nil {


+ 7
- 7
rpc/client/rpc_test.go View File

@ -364,16 +364,16 @@ func TestTx(t *testing.T) {
cases := []struct { cases := []struct {
valid bool valid bool
hash []byte
prove bool prove bool
hash []byte
}{ }{
// only valid if correct hash provided // 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() { for i, c := range GetClients() {


+ 11
- 11
rpc/lib/client/ws_client.go View File

@ -28,8 +28,6 @@ const (
// WSClient is a WebSocket client. The methods of WSClient are safe for use by // WSClient is a WebSocket client. The methods of WSClient are safe for use by
// multiple goroutines. // multiple goroutines.
type WSClient struct { type WSClient struct {
cmn.BaseService
conn *websocket.Conn conn *websocket.Conn
cdc *amino.Codec cdc *amino.Codec
@ -37,10 +35,6 @@ type WSClient struct {
Endpoint string // /websocket/url/endpoint Endpoint string // /websocket/url/endpoint
Dialer func(string, string) (net.Conn, error) 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. // Single user facing channel to read RPCResponses from, closed only when the client is being stopped.
ResponsesCh chan types.RPCResponse ResponsesCh chan types.RPCResponse
@ -53,15 +47,18 @@ type WSClient struct {
reconnectAfter chan error // reconnect requests reconnectAfter chan error // reconnect requests
readRoutineQuit chan struct{} // a way for readRoutine to close writeRoutine 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 wg sync.WaitGroup
mtx sync.RWMutex mtx sync.RWMutex
sentLastPingAt time.Time sentLastPingAt time.Time
reconnecting bool 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. // Time allowed to write a message to the server. 0 means block until operation succeeds.
writeWait time.Duration 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. // Send pings to server with this period. Must be less than readWait. If 0, no pings will be sent.
pingPeriod time.Duration 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) // NewWSClient returns a new client. See the commentary on the func(*WSClient)


+ 6
- 7
rpc/lib/client/ws_client_test.go View File

@ -3,7 +3,6 @@ package rpcclient
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"net"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"sync" "sync"
@ -65,7 +64,7 @@ func TestWSClientReconnectsAfterReadFailure(t *testing.T) {
s := httptest.NewServer(h) s := httptest.NewServer(h)
defer s.Close() defer s.Close()
c := startClient(t, s.Listener.Addr())
c := startClient(t, s.Listener.Addr().String())
defer c.Stop() defer c.Stop()
wg.Add(1) wg.Add(1)
@ -97,7 +96,7 @@ func TestWSClientReconnectsAfterWriteFailure(t *testing.T) {
h := &myHandler{} h := &myHandler{}
s := httptest.NewServer(h) s := httptest.NewServer(h)
c := startClient(t, s.Listener.Addr())
c := startClient(t, s.Listener.Addr().String())
defer c.Stop() defer c.Stop()
wg.Add(2) wg.Add(2)
@ -125,7 +124,7 @@ func TestWSClientReconnectFailure(t *testing.T) {
h := &myHandler{} h := &myHandler{}
s := httptest.NewServer(h) s := httptest.NewServer(h)
c := startClient(t, s.Listener.Addr())
c := startClient(t, s.Listener.Addr().String())
defer c.Stop() defer c.Stop()
go func() { go func() {
@ -174,7 +173,7 @@ func TestWSClientReconnectFailure(t *testing.T) {
func TestNotBlockingOnStop(t *testing.T) { func TestNotBlockingOnStop(t *testing.T) {
timeout := 2 * time.Second timeout := 2 * time.Second
s := httptest.NewServer(&myHandler{}) 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{})) c.Call(context.Background(), "a", make(map[string]interface{}))
// Let the readRoutine get around to blocking // Let the readRoutine get around to blocking
time.Sleep(time.Second) 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() err := c.Start()
require.Nil(t, err) require.Nil(t, err)
c.SetLogger(log.TestingLogger()) c.SetLogger(log.TestingLogger())


+ 4
- 4
rpc/lib/rpc_test.go View File

@ -146,7 +146,7 @@ func setup() {
time.Sleep(time.Second * 2) 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{}{ params := map[string]interface{}{
"arg": val, "arg": val,
} }
@ -157,7 +157,7 @@ func echoViaHTTP(cl client.HTTPClient, val string) (string, error) {
return result.Value, nil 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{}{ params := map[string]interface{}{
"arg": val, "arg": val,
} }
@ -168,7 +168,7 @@ func echoIntViaHTTP(cl client.HTTPClient, val int) (int, error) {
return result.Value, nil 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{}{ params := map[string]interface{}{
"arg": bytes, "arg": bytes,
} }
@ -179,7 +179,7 @@ func echoBytesViaHTTP(cl client.HTTPClient, bytes []byte) ([]byte, error) {
return result.Value, nil 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{}{ params := map[string]interface{}{
"arg": bytes, "arg": bytes,
} }


+ 2
- 2
state/txindex/kv/kv.go View File

@ -276,10 +276,10 @@ func lookForHeight(conditions []query.Condition) (height int64) {
type queryRanges map[string]queryRange type queryRanges map[string]queryRange
type queryRange struct { type queryRange struct {
key string
lowerBound interface{} // int || time.Time lowerBound interface{} // int || time.Time
includeLowerBound bool
upperBound interface{} // int || time.Time upperBound interface{} // int || time.Time
key string
includeLowerBound bool
includeUpperBound bool includeUpperBound bool
} }


+ 1
- 1
store/store_test.go View File

@ -169,8 +169,8 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
block *types.Block block *types.Block
parts *types.PartSet parts *types.PartSet
seenCommit *types.Commit seenCommit *types.Commit
wantErr bool
wantPanic string wantPanic string
wantErr bool
corruptBlockInDB bool corruptBlockInDB bool
corruptCommitInDB bool corruptCommitInDB bool


+ 2
- 1
tools/tm-bench/main.go View File

@ -12,6 +12,7 @@ import (
cmn "github.com/tendermint/tendermint/libs/common" cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/rpc/client"
tmrpc "github.com/tendermint/tendermint/rpc/client" tmrpc "github.com/tendermint/tendermint/rpc/client"
) )
@ -133,7 +134,7 @@ Examples:
printStatistics(stats, outputFormat) printStatistics(stats, outputFormat)
} }
func latestBlockHeight(client tmrpc.Client) int64 {
func latestBlockHeight(client client.StatusClient) int64 {
status, err := client.Status() status, err := client.Status()
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)


+ 6
- 6
tools/tm-monitor/monitor/node.go View File

@ -19,14 +19,14 @@ import (
const maxRestarts = 25 const maxRestarts = 25
type Node struct { 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 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. // em holds the ws connection. Each eventMeter callback is called in a separate go-routine.


Loading…
Cancel
Save