diff --git a/abci/client/grpc_client.go b/abci/client/grpc_client.go index f853a4254..01583bc1f 100644 --- a/abci/client/grpc_client.go +++ b/abci/client/grpc_client.go @@ -31,7 +31,7 @@ type grpcClient struct { resCb func(*types.Request, *types.Response) // listens to all callbacks } -func NewGRPCClient(addr string, mustConnect bool) *grpcClient { +func NewGRPCClient(addr string, mustConnect bool) Client { cli := &grpcClient{ addr: addr, mustConnect: mustConnect, diff --git a/abci/client/local_client.go b/abci/client/local_client.go index f50d4eae1..3946bfbc5 100644 --- a/abci/client/local_client.go +++ b/abci/client/local_client.go @@ -21,7 +21,7 @@ type localClient struct { Callback } -func NewLocalClient(mtx *sync.Mutex, app types.Application) *localClient { +func NewLocalClient(mtx *sync.Mutex, app types.Application) Client { if mtx == nil { mtx = new(sync.Mutex) } diff --git a/abci/client/socket_client.go b/abci/client/socket_client.go index 2e765119b..7898a8f26 100644 --- a/abci/client/socket_client.go +++ b/abci/client/socket_client.go @@ -43,7 +43,7 @@ type socketClient struct { } -func NewSocketClient(addr string, mustConnect bool) *socketClient { +func NewSocketClient(addr string, mustConnect bool) Client { cli := &socketClient{ reqQueue: make(chan *ReqRes, reqQueueSize), flushTimer: timer.NewThrottleTimer("socketClient", flushThrottleMS), diff --git a/abci/client/socket_client_test.go b/abci/client/socket_client_test.go index c4877ce70..37bc2b57a 100644 --- a/abci/client/socket_client_test.go +++ b/abci/client/socket_client_test.go @@ -16,8 +16,12 @@ import ( "github.com/tendermint/tendermint/libs/service" ) +type errorStopper interface { + StopForError(error) +} + func TestSocketClientStopForErrorDeadlock(t *testing.T) { - c := abcicli.NewSocketClient(":80", false) + c := abcicli.NewSocketClient(":80", false).(errorStopper) err := errors.New("foo-tendermint") // See Issue https://github.com/tendermint/abci/issues/114 diff --git a/consensus/common_test.go b/consensus/common_test.go index c6cd18193..0403ccaf3 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -71,7 +71,7 @@ type validatorStub struct { var testMinPower int64 = 10 -func NewValidatorStub(privValidator types.PrivValidator, valIndex int) *validatorStub { +func newValidatorStub(privValidator types.PrivValidator, valIndex int) *validatorStub { return &validatorStub{ Index: valIndex, PrivValidator: privValidator, @@ -385,7 +385,7 @@ func randState(nValidators int) (*State, []*validatorStub) { cs := newState(state, privVals[0], counter.NewApplication(true)) for i := 0; i < nValidators; i++ { - vss[i] = NewValidatorStub(privVals[i], i) + vss[i] = newValidatorStub(privVals[i], i) } // since cs1 starts at 1 incrementHeight(vss[1:]...) diff --git a/consensus/replay_test.go b/consensus/replay_test.go index 530948a18..6a33cf382 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -329,7 +329,7 @@ func TestSimulateValidatorsChange(t *testing.T) { vss := make([]*validatorStub, nPeers) for i := 0; i < nPeers; i++ { - vss[i] = NewValidatorStub(css[i].privValidator, i) + vss[i] = newValidatorStub(css[i].privValidator, i) } height, round := css[0].Height, css[0].Round // start the machine diff --git a/consensus/wal.go b/consensus/wal.go index 64f04fee0..989a5dc29 100644 --- a/consensus/wal.go +++ b/consensus/wal.go @@ -78,7 +78,7 @@ type WAL interface { // TODO: currently the wal is overwritten during replay catchup, give it a mode // so it's either reading or appending - must read to end to start appending // again. -type baseWAL struct { +type BaseWAL struct { service.BaseService group *auto.Group @@ -89,11 +89,11 @@ type baseWAL struct { flushInterval time.Duration } -var _ WAL = &baseWAL{} +var _ WAL = &BaseWAL{} // NewWAL returns a new write-ahead logger based on `baseWAL`, which implements // WAL. It's flushed and synced to disk every 2s and once when stopped. -func NewWAL(walFile string, groupOptions ...func(*auto.Group)) (*baseWAL, error) { +func NewWAL(walFile string, groupOptions ...func(*auto.Group)) (*BaseWAL, error) { err := tmos.EnsureDir(filepath.Dir(walFile), 0700) if err != nil { return nil, errors.Wrap(err, "failed to ensure WAL directory is in place") @@ -103,7 +103,7 @@ func NewWAL(walFile string, groupOptions ...func(*auto.Group)) (*baseWAL, error) if err != nil { return nil, err } - wal := &baseWAL{ + wal := &BaseWAL{ group: group, enc: NewWALEncoder(group), flushInterval: walDefaultFlushInterval, @@ -113,20 +113,20 @@ func NewWAL(walFile string, groupOptions ...func(*auto.Group)) (*baseWAL, error) } // SetFlushInterval allows us to override the periodic flush interval for the WAL. -func (wal *baseWAL) SetFlushInterval(i time.Duration) { +func (wal *BaseWAL) SetFlushInterval(i time.Duration) { wal.flushInterval = i } -func (wal *baseWAL) Group() *auto.Group { +func (wal *BaseWAL) Group() *auto.Group { return wal.group } -func (wal *baseWAL) SetLogger(l log.Logger) { +func (wal *BaseWAL) SetLogger(l log.Logger) { wal.BaseService.Logger = l wal.group.SetLogger(l) } -func (wal *baseWAL) OnStart() error { +func (wal *BaseWAL) OnStart() error { size, err := wal.group.Head.Size() if err != nil { return err @@ -142,7 +142,7 @@ func (wal *baseWAL) OnStart() error { return nil } -func (wal *baseWAL) processFlushTicks() { +func (wal *BaseWAL) processFlushTicks() { for { select { case <-wal.flushTicker.C: @@ -157,14 +157,14 @@ func (wal *baseWAL) processFlushTicks() { // FlushAndSync flushes and fsync's the underlying group's data to disk. // See auto#FlushAndSync -func (wal *baseWAL) FlushAndSync() error { +func (wal *BaseWAL) FlushAndSync() error { return wal.group.FlushAndSync() } // Stop the underlying autofile group. // Use Wait() to ensure it's finished shutting down // before cleaning up files. -func (wal *baseWAL) OnStop() { +func (wal *BaseWAL) OnStop() { wal.flushTicker.Stop() wal.FlushAndSync() wal.group.Stop() @@ -173,14 +173,14 @@ func (wal *baseWAL) OnStop() { // Wait for the underlying autofile group to finish shutting down // so it's safe to cleanup files. -func (wal *baseWAL) Wait() { +func (wal *BaseWAL) Wait() { wal.group.Wait() } // Write is called in newStep and for each receive on the // peerMsgQueue and the timeoutTicker. // NOTE: does not call fsync() -func (wal *baseWAL) Write(msg WALMessage) error { +func (wal *BaseWAL) Write(msg WALMessage) error { if wal == nil { return nil } @@ -197,7 +197,7 @@ func (wal *baseWAL) Write(msg WALMessage) error { // WriteSync is called when we receive a msg from ourselves // so that we write to disk before sending signed messages. // NOTE: calls fsync() -func (wal *baseWAL) WriteSync(msg WALMessage) error { +func (wal *BaseWAL) WriteSync(msg WALMessage) error { if wal == nil { return nil } @@ -227,7 +227,7 @@ type WALSearchOptions struct { // Group reader will be nil if found equals false. // // CONTRACT: caller must close group reader. -func (wal *baseWAL) SearchForEndHeight( +func (wal *BaseWAL) SearchForEndHeight( height int64, options *WALSearchOptions) (rd io.ReadCloser, found bool, err error) { var ( diff --git a/lite/multiprovider.go b/lite/multiprovider.go index b10c1c3cb..364647a40 100644 --- a/lite/multiprovider.go +++ b/lite/multiprovider.go @@ -16,7 +16,7 @@ type multiProvider struct { } // NewMultiProvider returns a new provider which wraps multiple other providers. -func NewMultiProvider(providers ...PersistentProvider) *multiProvider { +func NewMultiProvider(providers ...PersistentProvider) PersistentProvider { return &multiProvider{ logger: log.NewNopLogger(), providers: providers, diff --git a/p2p/conn_set.go b/p2p/conn_set.go index d64622783..a889ad5e1 100644 --- a/p2p/conn_set.go +++ b/p2p/conn_set.go @@ -26,7 +26,7 @@ type connSet struct { } // NewConnSet returns a ConnSet implementation. -func NewConnSet() *connSet { +func NewConnSet() ConnSet { return &connSet{ conns: map[string]connSetItem{}, } diff --git a/p2p/pex/addrbook.go b/p2p/pex/addrbook.go index 4efb4d1e0..dbba71345 100644 --- a/p2p/pex/addrbook.go +++ b/p2p/pex/addrbook.go @@ -102,7 +102,7 @@ type addrBook struct { // NewAddrBook creates a new address book. // Use Start to begin processing asynchronous address updates. -func NewAddrBook(filePath string, routabilityStrict bool) *addrBook { +func NewAddrBook(filePath string, routabilityStrict bool) AddrBook { am := &addrBook{ rand: tmrand.NewRand(), ourAddrs: make(map[string]struct{}), diff --git a/p2p/pex/addrbook_test.go b/p2p/pex/addrbook_test.go index 0bcda730e..4942b403b 100644 --- a/p2p/pex/addrbook_test.go +++ b/p2p/pex/addrbook_test.go @@ -17,6 +17,8 @@ import ( "github.com/tendermint/tendermint/p2p" ) +// FIXME These tests should not rely on .(*addrBook) assertions + func TestAddrBookPickAddress(t *testing.T) { fname := createTempFileName("addrbook_test") defer deleteTempFile(fname) @@ -58,11 +60,11 @@ func TestAddrBookSaveLoad(t *testing.T) { defer deleteTempFile(fname) // 0 addresses - book := NewAddrBook(fname, true) + book := NewAddrBook(fname, true).(*addrBook) book.SetLogger(log.TestingLogger()) book.saveToFile(fname) - book = NewAddrBook(fname, true) + book = NewAddrBook(fname, true).(*addrBook) book.SetLogger(log.TestingLogger()) book.loadFromFile(fname) @@ -78,7 +80,7 @@ func TestAddrBookSaveLoad(t *testing.T) { assert.Equal(t, 100, book.Size()) book.saveToFile(fname) - book = NewAddrBook(fname, true) + book = NewAddrBook(fname, true).(*addrBook) book.SetLogger(log.TestingLogger()) book.loadFromFile(fname) @@ -91,7 +93,7 @@ func TestAddrBookLookup(t *testing.T) { randAddrs := randNetAddressPairs(t, 100) - book := NewAddrBook(fname, true) + book := NewAddrBook(fname, true).(*addrBook) book.SetLogger(log.TestingLogger()) for _, addrSrc := range randAddrs { addr := addrSrc.addr @@ -575,7 +577,7 @@ func deleteTempFile(fname string) { func createAddrBookWithMOldAndNNewAddrs(t *testing.T, nOld, nNew int) (book *addrBook, fname string) { fname = createTempFileName("addrbook_test") - book = NewAddrBook(fname, true) + book = NewAddrBook(fname, true).(*addrBook) book.SetLogger(log.TestingLogger()) assert.Zero(t, book.Size()) diff --git a/p2p/pex/pex_reactor_test.go b/p2p/pex/pex_reactor_test.go index 5e174765a..4cddf6352 100644 --- a/p2p/pex/pex_reactor_test.go +++ b/p2p/pex/pex_reactor_test.go @@ -74,7 +74,7 @@ func TestPEXReactorRunning(t *testing.T) { require.Nil(t, err) defer os.RemoveAll(dir) // nolint: errcheck - books := make([]*addrBook, N) + books := make([]AddrBook, N) logger := log.TestingLogger() // create switches @@ -404,7 +404,7 @@ func TestPEXReactorSeedModeFlushStop(t *testing.T) { require.Nil(t, err) defer os.RemoveAll(dir) // nolint: errcheck - books := make([]*addrBook, N) + books := make([]AddrBook, N) logger := log.TestingLogger() // create switches @@ -631,7 +631,7 @@ func testCreatePeerWithSeed(dir string, id int, seed *p2p.Switch) *p2p.Switch { return testCreatePeerWithConfig(dir, id, conf) } -func createReactor(conf *ReactorConfig) (r *Reactor, book *addrBook) { +func createReactor(conf *ReactorConfig) (r *Reactor, book AddrBook) { // directory to store address book dir, err := ioutil.TempDir("", "pex_reactor") if err != nil { @@ -645,8 +645,9 @@ func createReactor(conf *ReactorConfig) (r *Reactor, book *addrBook) { return } -func teardownReactor(book *addrBook) { - err := os.RemoveAll(filepath.Dir(book.FilePath())) +func teardownReactor(book AddrBook) { + // FIXME Shouldn't rely on .(*addrBook) assertion + err := os.RemoveAll(filepath.Dir(book.(*addrBook).FilePath())) if err != nil { panic(err) } diff --git a/privval/socket_listeners.go b/privval/socket_listeners.go index f4d875e71..0e12e4268 100644 --- a/privval/socket_listeners.go +++ b/privval/socket_listeners.go @@ -23,26 +23,26 @@ type timeoutError interface { // TCP Listener // TCPListenerOption sets an optional parameter on the tcpListener. -type TCPListenerOption func(*tcpListener) +type TCPListenerOption func(*TCPListener) // TCPListenerTimeoutAccept sets the timeout for the listener. // A zero time value disables the timeout. func TCPListenerTimeoutAccept(timeout time.Duration) TCPListenerOption { - return func(tl *tcpListener) { tl.timeoutAccept = timeout } + return func(tl *TCPListener) { tl.timeoutAccept = timeout } } // TCPListenerTimeoutReadWrite sets the read and write timeout for connections // from external signing processes. func TCPListenerTimeoutReadWrite(timeout time.Duration) TCPListenerOption { - return func(tl *tcpListener) { tl.timeoutReadWrite = timeout } + return func(tl *TCPListener) { tl.timeoutReadWrite = timeout } } // tcpListener implements net.Listener. -var _ net.Listener = (*tcpListener)(nil) +var _ net.Listener = (*TCPListener)(nil) -// tcpListener wraps a *net.TCPListener to standardise protocol timeouts +// TCPListener wraps a *net.TCPListener to standardise protocol timeouts // and potentially other tuning parameters. It also returns encrypted connections. -type tcpListener struct { +type TCPListener struct { *net.TCPListener secretConnKey ed25519.PrivKeyEd25519 @@ -53,8 +53,8 @@ type tcpListener struct { // NewTCPListener returns a listener that accepts authenticated encrypted connections // using the given secretConnKey and the default timeout values. -func NewTCPListener(ln net.Listener, secretConnKey ed25519.PrivKeyEd25519) *tcpListener { - return &tcpListener{ +func NewTCPListener(ln net.Listener, secretConnKey ed25519.PrivKeyEd25519) *TCPListener { + return &TCPListener{ TCPListener: ln.(*net.TCPListener), secretConnKey: secretConnKey, timeoutAccept: time.Second * defaultTimeoutAcceptSeconds, @@ -63,7 +63,7 @@ func NewTCPListener(ln net.Listener, secretConnKey ed25519.PrivKeyEd25519) *tcpL } // Accept implements net.Listener. -func (ln *tcpListener) Accept() (net.Conn, error) { +func (ln *TCPListener) Accept() (net.Conn, error) { deadline := time.Now().Add(ln.timeoutAccept) err := ln.SetDeadline(deadline) if err != nil { @@ -89,25 +89,25 @@ func (ln *tcpListener) Accept() (net.Conn, error) { // Unix Listener // unixListener implements net.Listener. -var _ net.Listener = (*unixListener)(nil) +var _ net.Listener = (*UnixListener)(nil) -type UnixListenerOption func(*unixListener) +type UnixListenerOption func(*UnixListener) // UnixListenerTimeoutAccept sets the timeout for the listener. // A zero time value disables the timeout. func UnixListenerTimeoutAccept(timeout time.Duration) UnixListenerOption { - return func(ul *unixListener) { ul.timeoutAccept = timeout } + return func(ul *UnixListener) { ul.timeoutAccept = timeout } } // UnixListenerTimeoutReadWrite sets the read and write timeout for connections // from external signing processes. func UnixListenerTimeoutReadWrite(timeout time.Duration) UnixListenerOption { - return func(ul *unixListener) { ul.timeoutReadWrite = timeout } + return func(ul *UnixListener) { ul.timeoutReadWrite = timeout } } -// unixListener wraps a *net.UnixListener to standardise protocol timeouts +// UnixListener wraps a *net.UnixListener to standardise protocol timeouts // and potentially other tuning parameters. It returns unencrypted connections. -type unixListener struct { +type UnixListener struct { *net.UnixListener timeoutAccept time.Duration @@ -116,8 +116,8 @@ type unixListener struct { // NewUnixListener returns a listener that accepts unencrypted connections // using the default timeout values. -func NewUnixListener(ln net.Listener) *unixListener { - return &unixListener{ +func NewUnixListener(ln net.Listener) *UnixListener { + return &UnixListener{ UnixListener: ln.(*net.UnixListener), timeoutAccept: time.Second * defaultTimeoutAcceptSeconds, timeoutReadWrite: time.Second * defaultTimeoutReadWriteSeconds, @@ -125,7 +125,7 @@ func NewUnixListener(ln net.Listener) *unixListener { } // Accept implements net.Listener. -func (ln *unixListener) Accept() (net.Conn, error) { +func (ln *UnixListener) Accept() (net.Conn, error) { deadline := time.Now().Add(ln.timeoutAccept) err := ln.SetDeadline(deadline) if err != nil { diff --git a/proxy/app_conn.go b/proxy/app_conn.go index 1698ab52f..066d17295 100644 --- a/proxy/app_conn.go +++ b/proxy/app_conn.go @@ -47,7 +47,7 @@ type appConnConsensus struct { appConn abcicli.Client } -func NewAppConnConsensus(appConn abcicli.Client) *appConnConsensus { +func NewAppConnConsensus(appConn abcicli.Client) AppConnConsensus { return &appConnConsensus{ appConn: appConn, } @@ -88,7 +88,7 @@ type appConnMempool struct { appConn abcicli.Client } -func NewAppConnMempool(appConn abcicli.Client) *appConnMempool { +func NewAppConnMempool(appConn abcicli.Client) AppConnMempool { return &appConnMempool{ appConn: appConn, } @@ -121,7 +121,7 @@ type appConnQuery struct { appConn abcicli.Client } -func NewAppConnQuery(appConn abcicli.Client) *appConnQuery { +func NewAppConnQuery(appConn abcicli.Client) AppConnQuery { return &appConnQuery{ appConn: appConn, } diff --git a/proxy/multi_app_conn.go b/proxy/multi_app_conn.go index 44ff242b1..364114115 100644 --- a/proxy/multi_app_conn.go +++ b/proxy/multi_app_conn.go @@ -30,15 +30,15 @@ func NewAppConns(clientCreator ClientCreator) AppConns { type multiAppConn struct { service.BaseService - mempoolConn *appConnMempool - consensusConn *appConnConsensus - queryConn *appConnQuery + mempoolConn AppConnMempool + consensusConn AppConnConsensus + queryConn AppConnQuery clientCreator ClientCreator } // Make all necessary abci connections to the application -func NewMultiAppConn(clientCreator ClientCreator) *multiAppConn { +func NewMultiAppConn(clientCreator ClientCreator) AppConns { multiAppConn := &multiAppConn{ clientCreator: clientCreator, } diff --git a/rpc/lib/server/ws_handler.go b/rpc/lib/server/ws_handler.go index 07f424b48..e7048db79 100644 --- a/rpc/lib/server/ws_handler.go +++ b/rpc/lib/server/ws_handler.go @@ -92,7 +92,7 @@ func (wm *WebsocketManager) WebsocketHandler(w http.ResponseWriter, r *http.Requ }() // register connection - con := NewWSConnection(wsConn, wm.funcMap, wm.cdc, wm.wsConnOptions...) + con := newWSConnection(wsConn, wm.funcMap, wm.cdc, wm.wsConnOptions...) con.SetLogger(wm.logger.With("remote", wsConn.RemoteAddr())) wm.logger.Info("New websocket connection", "remote", con.remoteAddr) err = con.Start() // BLOCKING @@ -154,7 +154,7 @@ type wsConnection struct { // description of how to configure ping period and pong wait time. NOTE: if the // write buffer is full, pongs may be dropped, which may cause clients to // disconnect. see https://github.com/gorilla/websocket/issues/97 -func NewWSConnection( +func newWSConnection( baseConn *websocket.Conn, funcMap map[string]*RPCFunc, cdc *amino.Codec,