From 3e1516b62427aba1199766fc98943dffe81d7f4b Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Sat, 16 Nov 2019 19:35:39 +0400 Subject: [PATCH] linters: enable stylecheck (#4153) Refs #3262 --- .golangci.yml | 2 +- CHANGELOG_PENDING.md | 3 +- abci/client/client.go | 2 +- abci/client/socket_client.go | 8 +- abci/cmd/abci-cli/abci-cli.go | 8 +- abci/server/server.go | 2 +- abci/server/socket_server.go | 6 +- abci/tests/benchmarks/simple/simple.go | 2 +- abci/tests/server/client.go | 10 +-- behaviour/reporter_test.go | 6 +- blockchain/v0/reactor.go | 14 ++-- blockchain/v2/routine_test.go | 10 +-- blockchain/v2/schedule.go | 34 ++++---- cmd/tendermint/commands/codec.go | 4 +- cmd/tendermint/commands/root.go | 2 +- cmd/tendermint/commands/run_node.go | 4 +- consensus/mempool_test.go | 6 +- consensus/reactor.go | 60 +++++++------- consensus/reactor_test.go | 28 +++---- consensus/replay.go | 20 ++--- consensus/replay_test.go | 2 +- consensus/state.go | 12 +-- consensus/state_test.go | 4 +- consensus/types/height_vote_set.go | 21 ++--- consensus/types/height_vote_set_test.go | 4 +- consensus/types/peer_round_state.go | 16 ++-- consensus/types/round_state.go | 4 +- crypto/encoding/amino/amino.go | 2 +- crypto/encoding/amino/encode_test.go | 2 +- crypto/merkle/proof.go | 8 +- crypto/merkle/proof_test.go | 4 +- crypto/merkle/rfc6962_test.go | 6 +- crypto/merkle/simple_proof.go | 4 +- crypto/multisig/bitarray/compact_bit_array.go | 2 +- crypto/xchacha20poly1305/vector_test.go | 6 +- crypto/xchacha20poly1305/xchachapoly_test.go | 10 +-- crypto/xsalsa20symmetric/symmetric.go | 4 +- docs/spec/scripts/crypto.go | 4 +- evidence/codec.go | 4 +- evidence/reactor.go | 4 +- evidence/reactor_test.go | 18 ++--- libs/autofile/autofile_test.go | 4 +- libs/autofile/group_test.go | 4 +- libs/cli/flags/log_level.go | 6 +- libs/cli/setup.go | 2 +- libs/clist/clist_test.go | 4 +- libs/common/async.go | 4 +- libs/common/async_test.go | 30 +++---- libs/common/bit_array.go | 2 +- libs/common/bytes.go | 2 +- libs/common/os.go | 2 +- libs/common/random_test.go | 2 +- libs/common/tempfile.go | 2 +- libs/events/events_test.go | 12 +-- libs/log/filter.go | 2 +- libs/log/tm_logger_test.go | 2 +- libs/log/tracing_logger_test.go | 4 +- libs/pubsub/pubsub_test.go | 2 +- lite/dbprovider.go | 4 +- lite/proxy/block.go | 6 +- lite/proxy/validate_test.go | 16 ++-- mempool/clist_mempool_test.go | 8 +- mempool/errors.go | 2 +- mempool/mempool.go | 2 +- mempool/reactor_test.go | 10 +-- node/codec.go | 4 +- node/node.go | 4 +- p2p/codec.go | 4 +- p2p/conn/codec.go | 4 +- p2p/conn/connection.go | 12 +-- p2p/conn/secret_connection.go | 25 +++--- p2p/conn/secret_connection_test.go | 68 ++++++++-------- p2p/key.go | 2 +- p2p/netaddress.go | 10 +-- p2p/node_info.go | 6 +- p2p/node_info_test.go | 10 +-- p2p/peer_set_test.go | 8 +- p2p/pex/pex_reactor.go | 4 +- p2p/switch_test.go | 4 +- p2p/test_util.go | 4 +- p2p/transport.go | 2 +- p2p/transport_test.go | 14 ++-- p2p/trust/store_test.go | 2 +- p2p/upnp/probe.go | 8 +- p2p/upnp/upnp.go | 18 ++--- privval/codec.go | 4 +- privval/signer_listener_endpoint_test.go | 4 +- proxy/app_conn_test.go | 2 +- rpc/core/blocks.go | 4 +- rpc/core/mempool.go | 4 +- rpc/core/net.go | 4 +- rpc/core/tx.go | 6 +- rpc/core/types/codec.go | 2 +- rpc/core/types/responses.go | 2 +- rpc/core/types/responses_test.go | 2 +- rpc/grpc/api.go | 2 +- rpc/grpc/client_server.go | 2 +- rpc/grpc/grpc_test.go | 2 +- rpc/grpc/types.pb.go | 2 +- rpc/grpc/typespb_test.go | 2 +- rpc/lib/client/integration_test.go | 2 +- rpc/lib/server/http_params.go | 10 +-- rpc/lib/server/http_uri_handler.go | 2 +- rpc/lib/types/types.go | 2 +- rpc/lib/types/types_test.go | 4 +- scripts/json2wal/main.go | 6 +- scripts/privValUpgrade.go | 2 +- state/codec.go | 4 +- state/execution.go | 14 ++-- state/state.go | 6 +- state/txindex/indexer.go | 2 +- state/txindex/kv/kv.go | 8 +- state/txindex/null/null.go | 2 +- state/validation.go | 32 ++++---- tools/tm-monitor/mock/eventmeter.go | 8 +- tools/tm-monitor/monitor/monitor.go | 2 +- tools/tm-monitor/monitor/monitor_test.go | 4 +- tools/tm-monitor/monitor/node.go | 6 +- tools/tm-monitor/monitor/node_test.go | 4 +- types/block.go | 58 +++++++------- types/codec.go | 4 +- types/evidence.go | 24 +++--- types/genesis.go | 6 +- types/params.go | 10 +-- types/part_set.go | 6 +- types/part_set_test.go | 6 +- types/proposal.go | 20 ++--- types/proposal_test.go | 2 +- types/protobuf.go | 6 +- types/tx.go | 8 +- types/validation.go | 4 +- types/validator_set.go | 12 +-- types/validator_set_test.go | 10 +-- types/vote.go | 32 ++++---- types/vote_set.go | 2 +- types/vote_set_test.go | 80 +++++++++---------- types/vote_test.go | 6 +- 137 files changed, 590 insertions(+), 589 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 4da1cbadb..72e5410a1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -29,7 +29,7 @@ linters: - scopelint - staticcheck - structcheck - # - stylecheck + - stylecheck - typecheck - unconvert # - unparam diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index a7efc7e51..26b0f3129 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -3,7 +3,7 @@ \*\* Special thanks to external contributors on this release: -@erikgrinaker +@erikgrinaker, @PSalant726 Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermint). @@ -45,6 +45,7 @@ program](https://hackerone.com/tendermint). - Go API - [libs/pubsub] [\#4070](https://github.com/tendermint/tendermint/pull/4070) `Query#(Matches|Conditions)` returns an error. - [rpc/client] \#3471 `Validators` now requires two more args: `page` and `perPage` + - [libs/common] \#3262 Make error the last parameter of `Task` (@PSalant726) - Blockchain Protocol - [abci] \#2521 Remove `TotalTxs` and `NumTxs` from `Header` diff --git a/abci/client/client.go b/abci/client/client.go index 5f5ad7860..b7f941e7b 100644 --- a/abci/client/client.go +++ b/abci/client/client.go @@ -60,7 +60,7 @@ func NewClient(addr, transport string, mustConnect bool) (client Client, err err case "grpc": client = NewGRPCClient(addr, mustConnect) default: - err = fmt.Errorf("Unknown abci transport %s", transport) + err = fmt.Errorf("unknown abci transport %s", transport) } return } diff --git a/abci/client/socket_client.go b/abci/client/socket_client.go index 062d50d4e..3d4a03c9a 100644 --- a/abci/client/socket_client.go +++ b/abci/client/socket_client.go @@ -137,14 +137,14 @@ func (cli *socketClient) sendRequestsRoutine(conn io.Writer) { cli.willSendReq(reqres) err := types.WriteMessage(reqres.Request, w) if err != nil { - cli.StopForError(fmt.Errorf("Error writing msg: %v", err)) + cli.StopForError(fmt.Errorf("error writing msg: %v", err)) return } // cli.Logger.Debug("Sent request", "requestType", reflect.TypeOf(reqres.Request), "request", reqres.Request) if _, ok := reqres.Request.Value.(*types.Request_Flush); ok { err = w.Flush() if err != nil { - cli.StopForError(fmt.Errorf("Error flushing writer: %v", err)) + cli.StopForError(fmt.Errorf("error flushing writer: %v", err)) return } } @@ -191,11 +191,11 @@ func (cli *socketClient) didRecvResponse(res *types.Response) error { // Get the first ReqRes next := cli.reqSent.Front() if next == nil { - return fmt.Errorf("Unexpected result type %v when nothing expected", reflect.TypeOf(res.Value)) + return fmt.Errorf("unexpected result type %v when nothing expected", reflect.TypeOf(res.Value)) } reqres := next.Value.(*ReqRes) if !resMatchesReq(reqres.Request, res) { - return fmt.Errorf("Unexpected result type %v when response to %v expected", + return fmt.Errorf("unexpected result type %v when response to %v expected", reflect.TypeOf(res.Value), reflect.TypeOf(reqres.Request.Value)) } diff --git a/abci/cmd/abci-cli/abci-cli.go b/abci/cmd/abci-cli/abci-cli.go index 32560f427..8e4bf5162 100644 --- a/abci/cmd/abci-cli/abci-cli.go +++ b/abci/cmd/abci-cli/abci-cli.go @@ -350,7 +350,7 @@ LOOP: line, more, err := bufReader.ReadLine() switch { case more: - return errors.New("Input line is too long") + return errors.New("input line is too long") case err == io.EOF: break LOOP case len(line) == 0: @@ -374,7 +374,7 @@ func cmdConsole(cmd *cobra.Command, args []string) error { bufReader := bufio.NewReader(os.Stdin) line, more, err := bufReader.ReadLine() if more { - return errors.New("Input is too long") + return errors.New("input is too long") } else if err != nil { return err } @@ -730,14 +730,14 @@ func stringOrHexToBytes(s string) ([]byte, error) { if len(s) > 2 && strings.ToLower(s[:2]) == "0x" { b, err := hex.DecodeString(s[2:]) if err != nil { - err = fmt.Errorf("Error decoding hex argument: %s", err.Error()) + err = fmt.Errorf("error decoding hex argument: %s", err.Error()) return nil, err } return b, nil } if !strings.HasPrefix(s, "\"") || !strings.HasSuffix(s, "\"") { - err := fmt.Errorf("Invalid string arg: \"%s\". Must be quoted or a \"0x\"-prefixed hex string", s) + err := fmt.Errorf("invalid string arg: \"%s\". Must be quoted or a \"0x\"-prefixed hex string", s) return nil, err } diff --git a/abci/server/server.go b/abci/server/server.go index ada514fa8..a134ded6d 100644 --- a/abci/server/server.go +++ b/abci/server/server.go @@ -25,7 +25,7 @@ func NewServer(protoAddr, transport string, app types.Application) (cmn.Service, case "grpc": s = NewGRPCServer(protoAddr, types.NewGRPCApplication(app)) default: - err = fmt.Errorf("Unknown server type %s", transport) + err = fmt.Errorf("unknown server type %s", transport) } return s, err } diff --git a/abci/server/socket_server.go b/abci/server/socket_server.go index 8dbd934b4..3c89de2bf 100644 --- a/abci/server/socket_server.go +++ b/abci/server/socket_server.go @@ -88,7 +88,7 @@ func (s *SocketServer) rmConn(connID int) error { conn, ok := s.conns[connID] if !ok { - return fmt.Errorf("Connection %d does not exist", connID) + return fmt.Errorf("connection %d does not exist", connID) } delete(s.conns, connID) @@ -222,13 +222,13 @@ func (s *SocketServer) handleResponses(closeConn chan error, conn io.Writer, res var res = <-responses err := types.WriteMessage(res, bufWriter) if err != nil { - closeConn <- fmt.Errorf("Error writing message: %v", err.Error()) + closeConn <- fmt.Errorf("error writing message: %v", err.Error()) return } if _, ok := res.Value.(*types.Response_Flush); ok { err = bufWriter.Flush() if err != nil { - closeConn <- fmt.Errorf("Error flushing write buffer: %v", err.Error()) + closeConn <- fmt.Errorf("error flushing write buffer: %v", err.Error()) return } } diff --git a/abci/tests/benchmarks/simple/simple.go b/abci/tests/benchmarks/simple/simple.go index b5cfb044d..f3ac8a170 100644 --- a/abci/tests/benchmarks/simple/simple.go +++ b/abci/tests/benchmarks/simple/simple.go @@ -62,7 +62,7 @@ func makeRequest(conn io.ReadWriter, req *types.Request) (*types.Response, error return nil, err } if _, ok := resFlush.Value.(*types.Response_Flush); !ok { - return nil, fmt.Errorf("Expected flush response but got something else: %v", reflect.TypeOf(resFlush)) + return nil, fmt.Errorf("expected flush response but got something else: %v", reflect.TypeOf(resFlush)) } return res, nil diff --git a/abci/tests/server/client.go b/abci/tests/server/client.go index 58a413a4e..f0608ba08 100644 --- a/abci/tests/server/client.go +++ b/abci/tests/server/client.go @@ -51,7 +51,7 @@ func Commit(client abcicli.Client, hashExp []byte) error { if !bytes.Equal(data, hashExp) { fmt.Println("Failed test: Commit") fmt.Printf("Commit hash was unexpected. Got %X expected %X\n", data, hashExp) - return errors.New("CommitTx failed") + return errors.New("commitTx failed") } fmt.Println("Passed test: Commit") return nil @@ -64,13 +64,13 @@ func DeliverTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp [] fmt.Println("Failed test: DeliverTx") fmt.Printf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v\n", code, codeExp, log) - return errors.New("DeliverTx error") + return errors.New("deliverTx error") } if !bytes.Equal(data, dataExp) { fmt.Println("Failed test: DeliverTx") fmt.Printf("DeliverTx response data was unexpected. Got %X expected %X\n", data, dataExp) - return errors.New("DeliverTx error") + return errors.New("deliverTx error") } fmt.Println("Passed test: DeliverTx") return nil @@ -83,13 +83,13 @@ func CheckTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []by fmt.Println("Failed test: CheckTx") fmt.Printf("CheckTx response code was unexpected. Got %v expected %v. Log: %v\n", code, codeExp, log) - return errors.New("CheckTx") + return errors.New("checkTx") } if !bytes.Equal(data, dataExp) { fmt.Println("Failed test: CheckTx") fmt.Printf("CheckTx response data was unexpected. Got %X expected %X\n", data, dataExp) - return errors.New("CheckTx") + return errors.New("checkTx") } fmt.Println("Passed test: CheckTx") return nil diff --git a/behaviour/reporter_test.go b/behaviour/reporter_test.go index 9822cfc6d..5c4db1468 100644 --- a/behaviour/reporter_test.go +++ b/behaviour/reporter_test.go @@ -108,13 +108,13 @@ func TestEqualPeerBehaviours(t *testing.T) { for _, test := range equals { if !equalBehaviours(test.left, test.right) { - t.Errorf("Expected %#v and %#v to be equal", test.left, test.right) + t.Errorf("expected %#v and %#v to be equal", test.left, test.right) } } for _, test := range unequals { if equalBehaviours(test.left, test.right) { - t.Errorf("Expected %#v and %#v to be unequal", test.left, test.right) + t.Errorf("expected %#v and %#v to be unequal", test.left, test.right) } } } @@ -194,7 +194,7 @@ func TestMockPeerBehaviourReporterConcurrency(t *testing.T) { for _, items := range behaviourScript { reported := pr.GetBehaviours(items.peerID) if !equalBehaviours(reported, items.behaviours) { - t.Errorf("Expected peer %s to have behaved \nExpected: %#v \nGot %#v \n", + t.Errorf("expected peer %s to have behaved \nExpected: %#v \nGot %#v \n", items.peerID, items.behaviours, reported) } } diff --git a/blockchain/v0/reactor.go b/blockchain/v0/reactor.go index 574ef3f29..6e7bea660 100644 --- a/blockchain/v0/reactor.go +++ b/blockchain/v0/reactor.go @@ -319,14 +319,14 @@ FOR_LOOP: if peer != nil { // NOTE: we've already removed the peer's request, but we // still need to clean up the rest. - bcR.Switch.StopPeerForError(peer, fmt.Errorf("BlockchainReactor validation error: %v", err)) + bcR.Switch.StopPeerForError(peer, fmt.Errorf("blockchainReactor validation error: %v", err)) } peerID2 := bcR.pool.RedoRequest(second.Height) peer2 := bcR.Switch.Peers().Get(peerID2) if peer2 != nil && peer2 != peer { // NOTE: we've already removed the peer's request, but we // still need to clean up the rest. - bcR.Switch.StopPeerForError(peer2, fmt.Errorf("BlockchainReactor validation error: %v", err)) + bcR.Switch.StopPeerForError(peer2, fmt.Errorf("blockchainReactor validation error: %v", err)) } continue FOR_LOOP } else { @@ -387,7 +387,7 @@ func RegisterBlockchainMessages(cdc *amino.Codec) { func decodeMsg(bz []byte) (msg BlockchainMessage, err error) { if len(bz) > maxMsgSize { - return msg, fmt.Errorf("Msg exceeds max size (%d > %d)", len(bz), maxMsgSize) + return msg, fmt.Errorf("msg exceeds max size (%d > %d)", len(bz), maxMsgSize) } err = cdc.UnmarshalBinaryBare(bz, &msg) return @@ -402,7 +402,7 @@ type bcBlockRequestMessage struct { // ValidateBasic performs basic validation. func (m *bcBlockRequestMessage) ValidateBasic() error { if m.Height < 0 { - return errors.New("Negative Height") + return errors.New("negative Height") } return nil } @@ -418,7 +418,7 @@ type bcNoBlockResponseMessage struct { // ValidateBasic performs basic validation. func (m *bcNoBlockResponseMessage) ValidateBasic() error { if m.Height < 0 { - return errors.New("Negative Height") + return errors.New("negative Height") } return nil } @@ -451,7 +451,7 @@ type bcStatusRequestMessage struct { // ValidateBasic performs basic validation. func (m *bcStatusRequestMessage) ValidateBasic() error { if m.Height < 0 { - return errors.New("Negative Height") + return errors.New("negative Height") } return nil } @@ -469,7 +469,7 @@ type bcStatusResponseMessage struct { // ValidateBasic performs basic validation. func (m *bcStatusResponseMessage) ValidateBasic() error { if m.Height < 0 { - return errors.New("Negative Height") + return errors.New("negative Height") } return nil } diff --git a/blockchain/v2/routine_test.go b/blockchain/v2/routine_test.go index 66a8cc704..eb3863068 100644 --- a/blockchain/v2/routine_test.go +++ b/blockchain/v2/routine_test.go @@ -12,11 +12,11 @@ type eventA struct { priorityNormal } -var done = fmt.Errorf("done") +var errDone = fmt.Errorf("done") func simpleHandler(event Event) (Event, error) { if _, ok := event.(eventA); ok { - return noOp, done + return noOp, errDone } return noOp, nil } @@ -37,7 +37,7 @@ func TestRoutineFinal(t *testing.T) { assert.True(t, routine.send(eventA{}), "expected sending to a ready routine to succeed") - assert.Equal(t, done, <-routine.final(), + assert.Equal(t, errDone, <-routine.final(), "expected the final event to be done") assert.False(t, routine.isRunning(), @@ -131,7 +131,7 @@ func handleWithPriority(event Event) (Event, error) { case lowPriorityEvent: return noOp, nil case highPriorityEvent: - return noOp, done + return noOp, errDone } return noOp, nil } @@ -157,7 +157,7 @@ func TestPriority(t *testing.T) { assert.True(t, routine.send(highPriorityEvent{}), "expected send to succeed even when saturated") - assert.Equal(t, done, <-routine.final()) + assert.Equal(t, errDone, <-routine.final()) assert.False(t, routine.isRunning(), "expected an started routine") } diff --git a/blockchain/v2/schedule.go b/blockchain/v2/schedule.go index 38c6c5d2d..236d12aa9 100644 --- a/blockchain/v2/schedule.go +++ b/blockchain/v2/schedule.go @@ -113,7 +113,7 @@ func newSchedule(initHeight int64) *schedule { func (sc *schedule) addPeer(peerID p2p.ID) error { if _, ok := sc.peers[peerID]; ok { - return fmt.Errorf("Cannot add duplicate peer %s", peerID) + return fmt.Errorf("cannot add duplicate peer %s", peerID) } sc.peers[peerID] = newScPeer(peerID) return nil @@ -122,11 +122,11 @@ func (sc *schedule) addPeer(peerID p2p.ID) error { func (sc *schedule) touchPeer(peerID p2p.ID, time time.Time) error { peer, ok := sc.peers[peerID] if !ok { - return fmt.Errorf("Couldn't find peer %s", peerID) + return fmt.Errorf("couldn't find peer %s", peerID) } if peer.state == peerStateRemoved { - return fmt.Errorf("Tried to touch peer in peerStateRemoved") + return fmt.Errorf("tried to touch peer in peerStateRemoved") } peer.lastTouched = time @@ -137,11 +137,11 @@ func (sc *schedule) touchPeer(peerID p2p.ID, time time.Time) error { func (sc *schedule) removePeer(peerID p2p.ID) error { peer, ok := sc.peers[peerID] if !ok { - return fmt.Errorf("Couldn't find peer %s", peerID) + return fmt.Errorf("couldn't find peer %s", peerID) } if peer.state == peerStateRemoved { - return fmt.Errorf("Tried to remove peer %s in peerStateRemoved", peerID) + return fmt.Errorf("tried to remove peer %s in peerStateRemoved", peerID) } for height, pendingPeerID := range sc.pendingBlocks { @@ -168,15 +168,15 @@ func (sc *schedule) removePeer(peerID p2p.ID) error { func (sc *schedule) setPeerHeight(peerID p2p.ID, height int64) error { peer, ok := sc.peers[peerID] if !ok { - return fmt.Errorf("Can't find peer %s", peerID) + return fmt.Errorf("can't find peer %s", peerID) } if peer.state == peerStateRemoved { - return fmt.Errorf("Cannot set peer height for a peer in peerStateRemoved") + return fmt.Errorf("cannot set peer height for a peer in peerStateRemoved") } if height < peer.height { - return fmt.Errorf("Cannot move peer height lower. from %d to %d", peer.height, height) + return fmt.Errorf("cannot move peer height lower. from %d to %d", peer.height, height) } peer.height = height @@ -240,20 +240,20 @@ func (sc *schedule) setStateAtHeight(height int64, state blockState) { func (sc *schedule) markReceived(peerID p2p.ID, height int64, size int64, now time.Time) error { peer, ok := sc.peers[peerID] if !ok { - return fmt.Errorf("Can't find peer %s", peerID) + return fmt.Errorf("can't find peer %s", peerID) } if peer.state == peerStateRemoved { - return fmt.Errorf("Cannot receive blocks from removed peer %s", peerID) + return fmt.Errorf("cannot receive blocks from removed peer %s", peerID) } if state := sc.getStateAtHeight(height); state != blockStatePending || sc.pendingBlocks[height] != peerID { - return fmt.Errorf("Received block %d from peer %s without being requested", height, peerID) + return fmt.Errorf("received block %d from peer %s without being requested", height, peerID) } pendingTime, ok := sc.pendingTime[height] if !ok || now.Sub(pendingTime) <= 0 { - return fmt.Errorf("Clock error. Block %d received at %s but requested at %s", + return fmt.Errorf("clock error. Block %d received at %s but requested at %s", height, pendingTime, now) } @@ -271,20 +271,20 @@ func (sc *schedule) markReceived(peerID p2p.ID, height int64, size int64, now ti func (sc *schedule) markPending(peerID p2p.ID, height int64, time time.Time) error { peer, ok := sc.peers[peerID] if !ok { - return fmt.Errorf("Can't find peer %s", peerID) + return fmt.Errorf("can't find peer %s", peerID) } state := sc.getStateAtHeight(height) if state != blockStateNew { - return fmt.Errorf("Block %d should be in blockStateNew but was %s", height, state) + return fmt.Errorf("block %d should be in blockStateNew but was %s", height, state) } if peer.state != peerStateReady { - return fmt.Errorf("Cannot schedule %d from %s in %s", height, peerID, peer.state) + return fmt.Errorf("cannot schedule %d from %s in %s", height, peerID, peer.state) } if height > peer.height { - return fmt.Errorf("Cannot request height %d from peer %s who is at height %d", + return fmt.Errorf("cannot request height %d from peer %s who is at height %d", height, peerID, peer.height) } @@ -300,7 +300,7 @@ func (sc *schedule) markPending(peerID p2p.ID, height int64, time time.Time) err func (sc *schedule) markProcessed(height int64) error { state := sc.getStateAtHeight(height) if state != blockStateReceived { - return fmt.Errorf("Can't mark height %d received from block state %s", height, state) + return fmt.Errorf("can't mark height %d received from block state %s", height, state) } delete(sc.receivedBlocks, height) diff --git a/cmd/tendermint/commands/codec.go b/cmd/tendermint/commands/codec.go index 322f92b3f..717f2d21e 100644 --- a/cmd/tendermint/commands/codec.go +++ b/cmd/tendermint/commands/codec.go @@ -2,11 +2,11 @@ package commands import ( amino "github.com/tendermint/go-amino" - cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino" + cryptoamino "github.com/tendermint/tendermint/crypto/encoding/amino" ) var cdc = amino.NewCodec() func init() { - cryptoAmino.RegisterAmino(cdc) + cryptoamino.RegisterAmino(cdc) } diff --git a/cmd/tendermint/commands/root.go b/cmd/tendermint/commands/root.go index 6d79f75c0..4fa0cf3f7 100644 --- a/cmd/tendermint/commands/root.go +++ b/cmd/tendermint/commands/root.go @@ -37,7 +37,7 @@ func ParseConfig() (*cfg.Config, error) { conf.SetRoot(conf.RootDir) cfg.EnsureRoot(conf.RootDir) if err = conf.ValidateBasic(); err != nil { - return nil, fmt.Errorf("Error in config file: %v", err) + return nil, fmt.Errorf("error in config file: %v", err) } return conf, err } diff --git a/cmd/tendermint/commands/run_node.go b/cmd/tendermint/commands/run_node.go index 2faffc5ab..dd1aa081a 100644 --- a/cmd/tendermint/commands/run_node.go +++ b/cmd/tendermint/commands/run_node.go @@ -70,7 +70,7 @@ func NewRunNodeCmd(nodeProvider nm.NodeProvider) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { n, err := nodeProvider(config, logger) if err != nil { - return fmt.Errorf("Failed to create node: %v", err) + return fmt.Errorf("failed to create node: %v", err) } // Stop upon receiving SIGTERM or CTRL-C. @@ -81,7 +81,7 @@ func NewRunNodeCmd(nodeProvider nm.NodeProvider) *cobra.Command { }) if err := n.Start(); err != nil { - return fmt.Errorf("Failed to start node: %v", err) + return fmt.Errorf("failed to start node: %v", err) } logger.Info("Started node", "nodeInfo", n.Switch().NodeInfo()) diff --git a/consensus/mempool_test.go b/consensus/mempool_test.go index aa74a6972..d13148c14 100644 --- a/consensus/mempool_test.go +++ b/consensus/mempool_test.go @@ -161,7 +161,7 @@ func TestMempoolRmBadTx(t *testing.T) { checkTxRespCh <- struct{}{} }, mempl.TxInfo{}) if err != nil { - t.Errorf("Error after CheckTx: %v", err) + t.Errorf("error after CheckTx: %v", err) return } @@ -182,7 +182,7 @@ func TestMempoolRmBadTx(t *testing.T) { case <-checkTxRespCh: // success case <-ticker: - t.Errorf("Timed out waiting for tx to return") + t.Errorf("timed out waiting for tx to return") return } @@ -192,7 +192,7 @@ func TestMempoolRmBadTx(t *testing.T) { case <-emptyMempoolCh: // success case <-ticker: - t.Errorf("Timed out waiting for tx to be removed") + t.Errorf("timed out waiting for tx to be removed") return } } diff --git a/consensus/reactor.go b/consensus/reactor.go index 6d4b61219..dbda0f74a 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -898,8 +898,8 @@ func ReactorMetrics(metrics *Metrics) ReactorOption { //----------------------------------------------------------------------------- var ( - ErrPeerStateHeightRegression = errors.New("Error peer state height regression") - ErrPeerStateInvalidStartTime = errors.New("Error peer state invalid startTime") + ErrPeerStateHeightRegression = errors.New("error peer state height regression") + ErrPeerStateInvalidStartTime = errors.New("error peer state invalid startTime") ) // PeerState contains the known state of a peer, including its connection and @@ -1399,7 +1399,7 @@ func RegisterConsensusMessages(cdc *amino.Codec) { func decodeMsg(bz []byte) (msg ConsensusMessage, err error) { if len(bz) > maxMsgSize { - return msg, fmt.Errorf("Msg exceeds max size (%d > %d)", len(bz), maxMsgSize) + return msg, fmt.Errorf("msg exceeds max size (%d > %d)", len(bz), maxMsgSize) } err = cdc.UnmarshalBinaryBare(bz, &msg) return @@ -1420,20 +1420,20 @@ type NewRoundStepMessage struct { // ValidateBasic performs basic validation. func (m *NewRoundStepMessage) ValidateBasic() error { if m.Height < 0 { - return errors.New("Negative Height") + return errors.New("negative Height") } if m.Round < 0 { - return errors.New("Negative Round") + return errors.New("negative Round") } if !m.Step.IsValid() { - return errors.New("Invalid Step") + return errors.New("invalid Step") } // NOTE: SecondsSinceStartTime may be negative if (m.Height == 1 && m.LastCommitRound != -1) || (m.Height > 1 && m.LastCommitRound < -1) { // TODO: #2737 LastCommitRound should always be >= 0 for heights > 1 - return errors.New("Invalid LastCommitRound (for 1st block: -1, for others: >= 0)") + return errors.New("invalid LastCommitRound (for 1st block: -1, for others: >= 0)") } return nil } @@ -1460,19 +1460,19 @@ type NewValidBlockMessage struct { // ValidateBasic performs basic validation. func (m *NewValidBlockMessage) ValidateBasic() error { if m.Height < 0 { - return errors.New("Negative Height") + return errors.New("negative Height") } if m.Round < 0 { - return errors.New("Negative Round") + return errors.New("negative Round") } if err := m.BlockPartsHeader.ValidateBasic(); err != nil { - return fmt.Errorf("Wrong BlockPartsHeader: %v", err) + return fmt.Errorf("wrong BlockPartsHeader: %v", err) } if m.BlockParts.Size() == 0 { return errors.New("Empty BlockParts") } if m.BlockParts.Size() != m.BlockPartsHeader.Total { - return fmt.Errorf("BlockParts bit array size %d not equal to BlockPartsHeader.Total %d", + return fmt.Errorf("blockParts bit array size %d not equal to BlockPartsHeader.Total %d", m.BlockParts.Size(), m.BlockPartsHeader.Total) } @@ -1517,13 +1517,13 @@ type ProposalPOLMessage struct { // ValidateBasic performs basic validation. func (m *ProposalPOLMessage) ValidateBasic() error { if m.Height < 0 { - return errors.New("Negative Height") + return errors.New("negative Height") } if m.ProposalPOLRound < 0 { - return errors.New("Negative ProposalPOLRound") + return errors.New("negative ProposalPOLRound") } if m.ProposalPOL.Size() == 0 { - return errors.New("Empty ProposalPOL bit array") + return errors.New("empty ProposalPOL bit array") } if m.ProposalPOL.Size() > types.MaxVotesCount { return errors.Errorf("ProposalPOL bit array is too big: %d, max: %d", m.ProposalPOL.Size(), types.MaxVotesCount) @@ -1548,13 +1548,13 @@ type BlockPartMessage struct { // ValidateBasic performs basic validation. func (m *BlockPartMessage) ValidateBasic() error { if m.Height < 0 { - return errors.New("Negative Height") + return errors.New("negative Height") } if m.Round < 0 { - return errors.New("Negative Round") + return errors.New("negative Round") } if err := m.Part.ValidateBasic(); err != nil { - return fmt.Errorf("Wrong Part: %v", err) + return fmt.Errorf("wrong Part: %v", err) } return nil } @@ -1594,16 +1594,16 @@ type HasVoteMessage struct { // ValidateBasic performs basic validation. func (m *HasVoteMessage) ValidateBasic() error { if m.Height < 0 { - return errors.New("Negative Height") + return errors.New("negative Height") } if m.Round < 0 { - return errors.New("Negative Round") + return errors.New("negative Round") } if !types.IsVoteTypeValid(m.Type) { - return errors.New("Invalid Type") + return errors.New("invalid Type") } if m.Index < 0 { - return errors.New("Negative Index") + return errors.New("negative Index") } return nil } @@ -1626,16 +1626,16 @@ type VoteSetMaj23Message struct { // ValidateBasic performs basic validation. func (m *VoteSetMaj23Message) ValidateBasic() error { if m.Height < 0 { - return errors.New("Negative Height") + return errors.New("negative Height") } if m.Round < 0 { - return errors.New("Negative Round") + return errors.New("negative Round") } if !types.IsVoteTypeValid(m.Type) { - return errors.New("Invalid Type") + return errors.New("invalid Type") } if err := m.BlockID.ValidateBasic(); err != nil { - return fmt.Errorf("Wrong BlockID: %v", err) + return fmt.Errorf("wrong BlockID: %v", err) } return nil } @@ -1659,20 +1659,20 @@ type VoteSetBitsMessage struct { // ValidateBasic performs basic validation. func (m *VoteSetBitsMessage) ValidateBasic() error { if m.Height < 0 { - return errors.New("Negative Height") + return errors.New("negative Height") } if m.Round < 0 { - return errors.New("Negative Round") + return errors.New("negative Round") } if !types.IsVoteTypeValid(m.Type) { - return errors.New("Invalid Type") + return errors.New("invalid Type") } if err := m.BlockID.ValidateBasic(); err != nil { - return fmt.Errorf("Wrong BlockID: %v", err) + return fmt.Errorf("wrong BlockID: %v", err) } // NOTE: Votes.Size() can be zero if the node does not have any if m.Votes.Size() > types.MaxVotesCount { - return fmt.Errorf("Votes bit array is too big: %d, max: %d", m.Votes.Size(), types.MaxVotesCount) + return fmt.Errorf("votes bit array is too big: %d, max: %d", m.Votes.Size(), types.MaxVotesCount) } return nil } diff --git a/consensus/reactor_test.go b/consensus/reactor_test.go index b9ff6ea78..476eeddfb 100644 --- a/consensus/reactor_test.go +++ b/consensus/reactor_test.go @@ -608,14 +608,14 @@ func waitForBlockWithUpdatedValsAndValidateIt( func validateBlock(block *types.Block, activeVals map[string]struct{}) error { if block.LastCommit.Size() != len(activeVals) { return fmt.Errorf( - "Commit size doesn't match number of active validators. Got %d, expected %d", + "commit size doesn't match number of active validators. Got %d, expected %d", block.LastCommit.Size(), len(activeVals)) } for _, vote := range block.LastCommit.Precommits { if _, ok := activeVals[string(vote.ValidatorAddress)]; !ok { - return fmt.Errorf("Found vote for unactive validator %X", vote.ValidatorAddress) + return fmt.Errorf("found vote for unactive validator %X", vote.ValidatorAddress) } } return nil @@ -704,11 +704,11 @@ func TestNewValidBlockMessageValidateBasic(t *testing.T) { expErr string }{ {func(msg *NewValidBlockMessage) {}, ""}, - {func(msg *NewValidBlockMessage) { msg.Height = -1 }, "Negative Height"}, - {func(msg *NewValidBlockMessage) { msg.Round = -1 }, "Negative Round"}, + {func(msg *NewValidBlockMessage) { msg.Height = -1 }, "negative Height"}, + {func(msg *NewValidBlockMessage) { msg.Round = -1 }, "negative Round"}, { func(msg *NewValidBlockMessage) { msg.BlockPartsHeader.Total = 2 }, - "BlockParts bit array size 1 not equal to BlockPartsHeader.Total 2", + "blockParts bit array size 1 not equal to BlockPartsHeader.Total 2", }, { func(msg *NewValidBlockMessage) { msg.BlockPartsHeader.Total = 0; msg.BlockParts = cmn.NewBitArray(0) }, @@ -716,7 +716,7 @@ func TestNewValidBlockMessageValidateBasic(t *testing.T) { }, { func(msg *NewValidBlockMessage) { msg.BlockParts = cmn.NewBitArray(types.MaxBlockPartsCount + 1) }, - "BlockParts bit array size 1602 not equal to BlockPartsHeader.Total 1", + "blockParts bit array size 1602 not equal to BlockPartsHeader.Total 1", }, } @@ -747,9 +747,9 @@ func TestProposalPOLMessageValidateBasic(t *testing.T) { expErr string }{ {func(msg *ProposalPOLMessage) {}, ""}, - {func(msg *ProposalPOLMessage) { msg.Height = -1 }, "Negative Height"}, - {func(msg *ProposalPOLMessage) { msg.ProposalPOLRound = -1 }, "Negative ProposalPOLRound"}, - {func(msg *ProposalPOLMessage) { msg.ProposalPOL = cmn.NewBitArray(0) }, "Empty ProposalPOL bit array"}, + {func(msg *ProposalPOLMessage) { msg.Height = -1 }, "negative Height"}, + {func(msg *ProposalPOLMessage) { msg.ProposalPOLRound = -1 }, "negative ProposalPOLRound"}, + {func(msg *ProposalPOLMessage) { msg.ProposalPOL = cmn.NewBitArray(0) }, "empty ProposalPOL bit array"}, {func(msg *ProposalPOLMessage) { msg.ProposalPOL = cmn.NewBitArray(types.MaxVotesCount + 1) }, "ProposalPOL bit array is too big: 10001, max: 10000"}, } @@ -893,9 +893,9 @@ func TestVoteSetBitsMessageValidateBasic(t *testing.T) { expErr string }{ {func(msg *VoteSetBitsMessage) {}, ""}, - {func(msg *VoteSetBitsMessage) { msg.Height = -1 }, "Negative Height"}, - {func(msg *VoteSetBitsMessage) { msg.Round = -1 }, "Negative Round"}, - {func(msg *VoteSetBitsMessage) { msg.Type = 0x03 }, "Invalid Type"}, + {func(msg *VoteSetBitsMessage) { msg.Height = -1 }, "negative Height"}, + {func(msg *VoteSetBitsMessage) { msg.Round = -1 }, "negative Round"}, + {func(msg *VoteSetBitsMessage) { msg.Type = 0x03 }, "invalid Type"}, {func(msg *VoteSetBitsMessage) { msg.BlockID = types.BlockID{ Hash: cmn.HexBytes{}, @@ -904,9 +904,9 @@ func TestVoteSetBitsMessageValidateBasic(t *testing.T) { Hash: cmn.HexBytes{}, }, } - }, "Wrong BlockID: Wrong PartsHeader: Negative Total"}, + }, "wrong BlockID: wrong PartsHeader: negative Total"}, {func(msg *VoteSetBitsMessage) { msg.Votes = cmn.NewBitArray(types.MaxVotesCount + 1) }, - "Votes bit array is too big: 10001, max: 10000"}, + "votes bit array is too big: 10001, max: 10000"}, } for i, tc := range testCases { diff --git a/consensus/replay.go b/consensus/replay.go index a4c0aef19..e6ef44c28 100644 --- a/consensus/replay.go +++ b/consensus/replay.go @@ -59,12 +59,12 @@ func (cs *ConsensusState) readReplayMessage(msg *TimedWALMessage, newStepSub typ case stepMsg := <-newStepSub.Out(): m2 := stepMsg.Data().(types.EventDataRoundState) if m.Height != m2.Height || m.Round != m2.Round || m.Step != m2.Step { - return fmt.Errorf("RoundState mismatch. Got %v; Expected %v", m2, m) + return fmt.Errorf("roundState mismatch. Got %v; Expected %v", m2, m) } case <-newStepSub.Cancelled(): - return fmt.Errorf("Failed to read off newStepSub.Out(). newStepSub was cancelled") + return fmt.Errorf("failed to read off newStepSub.Out(). newStepSub was cancelled") case <-ticker: - return fmt.Errorf("Failed to read off newStepSub.Out()") + return fmt.Errorf("failed to read off newStepSub.Out()") } } case msgInfo: @@ -90,7 +90,7 @@ func (cs *ConsensusState) readReplayMessage(msg *TimedWALMessage, newStepSub typ cs.Logger.Info("Replay: Timeout", "height", m.Height, "round", m.Round, "step", m.Step, "dur", m.Duration) cs.handleTimeout(m, cs.RoundState) default: - return fmt.Errorf("Replay: Unknown TimedWALMessage type: %v", reflect.TypeOf(msg.Msg)) + return fmt.Errorf("replay: Unknown TimedWALMessage type: %v", reflect.TypeOf(msg.Msg)) } return nil } @@ -119,7 +119,7 @@ func (cs *ConsensusState) catchupReplay(csHeight int64) error { } } if found { - return fmt.Errorf("WAL should not contain #ENDHEIGHT %d", csHeight) + return fmt.Errorf("wal should not contain #ENDHEIGHT %d", csHeight) } // Search for last height marker. @@ -132,7 +132,7 @@ func (cs *ConsensusState) catchupReplay(csHeight int64) error { return err } if !found { - return fmt.Errorf("Cannot replay height %d. WAL does not contain #ENDHEIGHT for %d", csHeight, csHeight-1) + return fmt.Errorf("cannot replay height %d. WAL does not contain #ENDHEIGHT for %d", csHeight, csHeight-1) } defer gr.Close() // nolint: errcheck @@ -175,11 +175,11 @@ func makeHeightSearchFunc(height int64) auto.SearchFunc { line = strings.TrimRight(line, "\n") parts := strings.Split(line, " ") if len(parts) != 2 { - return -1, errors.New("Line did not have 2 parts") + return -1, errors.New("line did not have 2 parts") } i, err := strconv.Atoi(parts[1]) if err != nil { - return -1, errors.New("Failed to parse INFO: " + err.Error()) + return -1, errors.New("failed to parse INFO: " + err.Error()) } if height < i { return 1, nil @@ -243,12 +243,12 @@ func (h *Handshaker) Handshake(proxyApp proxy.AppConns) error { // Handshake is done via ABCI Info on the query conn. res, err := proxyApp.Query().InfoSync(proxy.RequestInfo) if err != nil { - return fmt.Errorf("Error calling Info: %v", err) + return fmt.Errorf("error calling Info: %v", err) } blockHeight := res.LastBlockHeight if blockHeight < 0 { - return fmt.Errorf("Got a negative last block height (%d) from the app", blockHeight) + return fmt.Errorf("got a negative last block height (%d) from the app", blockHeight) } appHash := res.LastBlockAppHash diff --git a/consensus/replay_test.go b/consensus/replay_test.go index 6a804c307..da96be39c 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -932,7 +932,7 @@ func makeBlockchainFromWAL(wal WAL) ([]*types.Block, []*types.Commit, error) { return nil, nil, err } if !found { - return nil, nil, fmt.Errorf("WAL does not contain height %d", height) + return nil, nil, fmt.Errorf("wal does not contain height %d", height) } defer gr.Close() // nolint: errcheck diff --git a/consensus/state.go b/consensus/state.go index 25dad26ce..68ea31d26 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -27,10 +27,10 @@ import ( // Errors var ( - ErrInvalidProposalSignature = errors.New("Error invalid proposal signature") - ErrInvalidProposalPOLRound = errors.New("Error invalid proposal POL round") - ErrAddingVote = errors.New("Error adding vote") - ErrVoteHeightMismatch = errors.New("Error vote height mismatch") + ErrInvalidProposalSignature = errors.New("error invalid proposal signature") + ErrInvalidProposalPOLRound = errors.New("error invalid proposal POL round") + ErrAddingVote = errors.New("error adding vote") + ErrVoteHeightMismatch = errors.New("error vote height mismatch") ) //----------------------------------------------------------------------------- @@ -969,8 +969,8 @@ func (cs *ConsensusState) defaultDecideProposal(height int64, round int) { cs.wal.FlushAndSync() // Make proposal - propBlockId := types.BlockID{Hash: block.Hash(), PartsHeader: blockParts.Header()} - proposal := types.NewProposal(height, round, cs.ValidRound, propBlockId) + propBlockID := types.BlockID{Hash: block.Hash(), PartsHeader: blockParts.Header()} + proposal := types.NewProposal(height, round, cs.ValidRound, propBlockID) if err := cs.privValidator.SignProposal(cs.state.ChainID, proposal); err == nil { // send proposal and block parts on internal msg queue diff --git a/consensus/state_test.go b/consensus/state_test.go index 4de8d3734..a5f916e47 100644 --- a/consensus/state_test.go +++ b/consensus/state_test.go @@ -1594,7 +1594,7 @@ func TestStateOutputsBlockPartsStats(t *testing.T) { select { case <-cs.statsMsgQueue: - t.Errorf("Should not output stats message after receiving the known block part!") + t.Errorf("should not output stats message after receiving the known block part!") case <-time.After(50 * time.Millisecond): } @@ -1625,7 +1625,7 @@ func TestStateOutputVoteStats(t *testing.T) { select { case <-cs.statsMsgQueue: - t.Errorf("Should not output stats message after receiving the known vote or vote from bigger height") + t.Errorf("should not output stats message after receiving the known vote or vote from bigger height") case <-time.After(50 * time.Millisecond): } diff --git a/consensus/types/height_vote_set.go b/consensus/types/height_vote_set.go index cc8a23f2f..14cd04bf8 100644 --- a/consensus/types/height_vote_set.go +++ b/consensus/types/height_vote_set.go @@ -16,8 +16,9 @@ type RoundVoteSet struct { } var ( - GotVoteFromUnwantedRoundError = errors.New( - "Peer has sent a vote that does not match our round for more than one round") + ErrGotVoteFromUnwantedRound = errors.New( + "peer has sent a vote that does not match our round for more than one round", + ) ) /* @@ -123,7 +124,7 @@ func (hvs *HeightVoteSet) AddVote(vote *types.Vote, peerID p2p.ID) (added bool, hvs.peerCatchupRounds[peerID] = append(rndz, vote.Round) } else { // punish peer - err = GotVoteFromUnwantedRoundError + err = ErrGotVoteFromUnwantedRound return } } @@ -158,18 +159,18 @@ func (hvs *HeightVoteSet) POLInfo() (polRound int, polBlockID types.BlockID) { return -1, types.BlockID{} } -func (hvs *HeightVoteSet) getVoteSet(round int, type_ types.SignedMsgType) *types.VoteSet { +func (hvs *HeightVoteSet) getVoteSet(round int, voteType types.SignedMsgType) *types.VoteSet { rvs, ok := hvs.roundVoteSets[round] if !ok { return nil } - switch type_ { + switch voteType { case types.PrevoteType: return rvs.Prevotes case types.PrecommitType: return rvs.Precommits default: - panic(fmt.Sprintf("Unexpected vote type %X", type_)) + panic(fmt.Sprintf("Unexpected vote type %X", voteType)) } } @@ -179,15 +180,15 @@ func (hvs *HeightVoteSet) getVoteSet(round int, type_ types.SignedMsgType) *type // TODO: implement ability to remove peers too func (hvs *HeightVoteSet) SetPeerMaj23( round int, - type_ types.SignedMsgType, + voteType types.SignedMsgType, peerID p2p.ID, blockID types.BlockID) error { hvs.mtx.Lock() defer hvs.mtx.Unlock() - if !types.IsVoteTypeValid(type_) { - return fmt.Errorf("SetPeerMaj23: Invalid vote type %v", type_) + if !types.IsVoteTypeValid(voteType) { + return fmt.Errorf("setPeerMaj23: Invalid vote type %X", voteType) } - voteSet := hvs.getVoteSet(round, type_) + voteSet := hvs.getVoteSet(round, voteType) if voteSet == nil { return nil // something we don't know about yet } diff --git a/consensus/types/height_vote_set_test.go b/consensus/types/height_vote_set_test.go index f45492aa4..93c73f1a1 100644 --- a/consensus/types/height_vote_set_test.go +++ b/consensus/types/height_vote_set_test.go @@ -38,8 +38,8 @@ func TestPeerCatchupRounds(t *testing.T) { vote1001_0 := makeVoteHR(t, 1, 1001, privVals, 0) added, err = hvs.AddVote(vote1001_0, "peer1") - if err != GotVoteFromUnwantedRoundError { - t.Errorf("Expected GotVoteFromUnwantedRoundError, but got %v", err) + if err != ErrGotVoteFromUnwantedRound { + t.Errorf("expected GotVoteFromUnwantedRoundError, but got %v", err) } if added { t.Error("Expected to *not* add vote from peer, too many catchup rounds.") diff --git a/consensus/types/peer_round_state.go b/consensus/types/peer_round_state.go index 2eae65f5a..41b5bd81b 100644 --- a/consensus/types/peer_round_state.go +++ b/consensus/types/peer_round_state.go @@ -70,19 +70,19 @@ func (prs PeerRoundState) StringIndented(indent string) string { // These methods are for Protobuf Compatibility // Size returns the size of the amino encoding, in bytes. -func (ps *PeerRoundState) Size() int { - bs, _ := ps.Marshal() +func (prs *PeerRoundState) Size() int { + bs, _ := prs.Marshal() return len(bs) } // Marshal returns the amino encoding. -func (ps *PeerRoundState) Marshal() ([]byte, error) { - return cdc.MarshalBinaryBare(ps) +func (prs *PeerRoundState) Marshal() ([]byte, error) { + return cdc.MarshalBinaryBare(prs) } // MarshalTo calls Marshal and copies to the given buffer. -func (ps *PeerRoundState) MarshalTo(data []byte) (int, error) { - bs, err := ps.Marshal() +func (prs *PeerRoundState) MarshalTo(data []byte) (int, error) { + bs, err := prs.Marshal() if err != nil { return -1, err } @@ -90,6 +90,6 @@ func (ps *PeerRoundState) MarshalTo(data []byte) (int, error) { } // Unmarshal deserializes from amino encoded form. -func (ps *PeerRoundState) Unmarshal(bs []byte) error { - return cdc.UnmarshalBinaryBare(bs, ps) +func (prs *PeerRoundState) Unmarshal(bs []byte) error { + return cdc.UnmarshalBinaryBare(bs, prs) } diff --git a/consensus/types/round_state.go b/consensus/types/round_state.go index 47c3f1fd7..abb085669 100644 --- a/consensus/types/round_state.go +++ b/consensus/types/round_state.go @@ -139,7 +139,7 @@ func (rs *RoundState) NewRoundEvent() types.EventDataNewRound { func (rs *RoundState) CompleteProposalEvent() types.EventDataCompleteProposal { // We must construct BlockID from ProposalBlock and ProposalBlockParts // cs.Proposal is not guaranteed to be set when this function is called - blockId := types.BlockID{ + blockID := types.BlockID{ Hash: rs.ProposalBlock.Hash(), PartsHeader: rs.ProposalBlockParts.Header(), } @@ -148,7 +148,7 @@ func (rs *RoundState) CompleteProposalEvent() types.EventDataCompleteProposal { Height: rs.Height, Round: rs.Round, Step: rs.Step.String(), - BlockID: blockId, + BlockID: blockID, } } diff --git a/crypto/encoding/amino/amino.go b/crypto/encoding/amino/amino.go index 1aed88115..fc2236aae 100644 --- a/crypto/encoding/amino/amino.go +++ b/crypto/encoding/amino/amino.go @@ -1,4 +1,4 @@ -package cryptoAmino +package cryptoamino import ( "reflect" diff --git a/crypto/encoding/amino/encode_test.go b/crypto/encoding/amino/encode_test.go index e73478b54..c3d8f2676 100644 --- a/crypto/encoding/amino/encode_test.go +++ b/crypto/encoding/amino/encode_test.go @@ -1,4 +1,4 @@ -package cryptoAmino +package cryptoamino import ( "os" diff --git a/crypto/merkle/proof.go b/crypto/merkle/proof.go index ad101d94d..50bcdd0ac 100644 --- a/crypto/merkle/proof.go +++ b/crypto/merkle/proof.go @@ -44,11 +44,11 @@ func (poz ProofOperators) Verify(root []byte, keypath string, args [][]byte) (er key := op.GetKey() if len(key) != 0 { if len(keys) == 0 { - return errors.Errorf("Key path has insufficient # of parts: expected no more keys but got %+v", string(key)) + return errors.Errorf("key path has insufficient # of parts: expected no more keys but got %+v", string(key)) } lastKey := keys[len(keys)-1] if !bytes.Equal(lastKey, key) { - return errors.Errorf("Key mismatch on operation #%d: expected %+v but got %+v", i, string(lastKey), string(key)) + return errors.Errorf("key mismatch on operation #%d: expected %+v but got %+v", i, string(lastKey), string(key)) } keys = keys[:len(keys)-1] } @@ -58,10 +58,10 @@ func (poz ProofOperators) Verify(root []byte, keypath string, args [][]byte) (er } } if !bytes.Equal(root, args[0]) { - return errors.Errorf("Calculated root hash is invalid: expected %+v but got %+v", root, args[0]) + return errors.Errorf("calculated root hash is invalid: expected %+v but got %+v", root, args[0]) } if len(keys) != 0 { - return errors.New("Keypath not consumed all") + return errors.New("keypath not consumed all") } return nil } diff --git a/crypto/merkle/proof_test.go b/crypto/merkle/proof_test.go index 4dc916ac9..c24e791cb 100644 --- a/crypto/merkle/proof_test.go +++ b/crypto/merkle/proof_test.go @@ -50,10 +50,10 @@ func (dop DominoOp) ProofOp() ProofOp { func (dop DominoOp) Run(input [][]byte) (output [][]byte, err error) { if len(input) != 1 { - return nil, errors.New("Expected input of length 1") + return nil, errors.New("expected input of length 1") } if string(input[0]) != dop.Input { - return nil, errors.Errorf("Expected input %v, got %v", + return nil, errors.Errorf("expected input %v, got %v", dop.Input, string(input[0])) } return [][]byte{[]byte(dop.Output)}, nil diff --git a/crypto/merkle/rfc6962_test.go b/crypto/merkle/rfc6962_test.go index e2fe7f617..6c508164a 100644 --- a/crypto/merkle/rfc6962_test.go +++ b/crypto/merkle/rfc6962_test.go @@ -77,7 +77,7 @@ func TestRFC6962HasherCollisions(t *testing.T) { _, leafHashTrail = trailsFromByteSlices([][]byte{leaf2}) hash2 := leafHashTrail.Hash if bytes.Equal(hash1, hash2) { - t.Errorf("Leaf hashes should differ, but both are %x", hash1) + t.Errorf("leaf hashes should differ, but both are %x", hash1) } // Compute an intermediate subtree hash. _, subHash1Trail := trailsFromByteSlices([][]byte{hash1, hash2}) @@ -87,12 +87,12 @@ func TestRFC6962HasherCollisions(t *testing.T) { _, forgedHashTrail := trailsFromByteSlices([][]byte{preimage}) forgedHash := forgedHashTrail.Hash if bytes.Equal(subHash1, forgedHash) { - t.Errorf("Hasher is not second-preimage resistant") + t.Errorf("hasher is not second-preimage resistant") } // Swap the order of nodes and check that the hash is different. _, subHash2Trail := trailsFromByteSlices([][]byte{hash2, hash1}) subHash2 := subHash2Trail.Hash if bytes.Equal(subHash1, subHash2) { - t.Errorf("Subtree hash does not depend on the order of leaves") + t.Errorf("subtree hash does not depend on the order of leaves") } } diff --git a/crypto/merkle/simple_proof.go b/crypto/merkle/simple_proof.go index 79a4729eb..660bf236f 100644 --- a/crypto/merkle/simple_proof.go +++ b/crypto/merkle/simple_proof.go @@ -76,10 +76,10 @@ func SimpleProofsFromMap(m map[string][]byte) (rootHash []byte, proofs map[strin func (sp *SimpleProof) Verify(rootHash []byte, leaf []byte) error { leafHash := leafHash(leaf) if sp.Total < 0 { - return errors.New("Proof total must be positive") + return errors.New("proof total must be positive") } if sp.Index < 0 { - return errors.New("Proof index cannot be negative") + return errors.New("proof index cannot be negative") } if !bytes.Equal(sp.LeafHash, leafHash) { return errors.Errorf("invalid leaf hash: wanted %X got %X", leafHash, sp.LeafHash) diff --git a/crypto/multisig/bitarray/compact_bit_array.go b/crypto/multisig/bitarray/compact_bit_array.go index 0152db724..890a4c9c7 100644 --- a/crypto/multisig/bitarray/compact_bit_array.go +++ b/crypto/multisig/bitarray/compact_bit_array.go @@ -176,7 +176,7 @@ func (bA *CompactBitArray) UnmarshalJSON(bz []byte) error { // Validate 'b'. match := bitArrayJSONRegexp.FindStringSubmatch(b) if match == nil { - return fmt.Errorf("BitArray in JSON should be a string of format %q but got %s", bitArrayJSONRegexp.String(), b) + return fmt.Errorf("bitArray in JSON should be a string of format %q but got %s", bitArrayJSONRegexp.String(), b) } bits := match[1] diff --git a/crypto/xchacha20poly1305/vector_test.go b/crypto/xchacha20poly1305/vector_test.go index f1aa9d66d..c6ca9d8d2 100644 --- a/crypto/xchacha20poly1305/vector_test.go +++ b/crypto/xchacha20poly1305/vector_test.go @@ -27,7 +27,7 @@ func TestHChaCha20(t *testing.T) { HChaCha20(&key, &nonce, &key) if !bytes.Equal(key[:], v.keystream) { - t.Errorf("Test %d: keystream mismatch:\n \t got: %s\n \t want: %s", i, toHex(key[:]), toHex(v.keystream)) + t.Errorf("test %d: keystream mismatch:\n \t got: %s\n \t want: %s", i, toHex(key[:]), toHex(v.keystream)) } } } @@ -78,14 +78,14 @@ func TestVectors(t *testing.T) { dst := aead.Seal(nil, nonce[:], v.plaintext, v.ad) if !bytes.Equal(dst, v.ciphertext) { - t.Errorf("Test %d: ciphertext mismatch:\n \t got: %s\n \t want: %s", i, toHex(dst), toHex(v.ciphertext)) + t.Errorf("test %d: ciphertext mismatch:\n \t got: %s\n \t want: %s", i, toHex(dst), toHex(v.ciphertext)) } open, err := aead.Open(nil, nonce[:], dst, v.ad) if err != nil { t.Error(err) } if !bytes.Equal(open, v.plaintext) { - t.Errorf("Test %d: plaintext mismatch:\n \t got: %s\n \t want: %s", i, string(open), string(v.plaintext)) + t.Errorf("test %d: plaintext mismatch:\n \t got: %s\n \t want: %s", i, string(open), string(v.plaintext)) } } } diff --git a/crypto/xchacha20poly1305/xchachapoly_test.go b/crypto/xchacha20poly1305/xchachapoly_test.go index 5b92a7607..18779ae16 100644 --- a/crypto/xchacha20poly1305/xchachapoly_test.go +++ b/crypto/xchacha20poly1305/xchachapoly_test.go @@ -37,12 +37,12 @@ func TestRandom(t *testing.T) { plaintext2, err := aead.Open(nil, nonce[:], ct, ad) if err != nil { - t.Errorf("Random #%d: Open failed", i) + t.Errorf("random #%d: Open failed", i) continue } if !bytes.Equal(plaintext, plaintext2) { - t.Errorf("Random #%d: plaintext's don't match: got %x vs %x", i, plaintext2, plaintext) + t.Errorf("random #%d: plaintext's don't match: got %x vs %x", i, plaintext2, plaintext) continue } @@ -50,7 +50,7 @@ func TestRandom(t *testing.T) { alterAdIdx := mr.Intn(len(ad)) ad[alterAdIdx] ^= 0x80 if _, err := aead.Open(nil, nonce[:], ct, ad); err == nil { - t.Errorf("Random #%d: Open was successful after altering additional data", i) + t.Errorf("random #%d: Open was successful after altering additional data", i) } ad[alterAdIdx] ^= 0x80 } @@ -58,14 +58,14 @@ func TestRandom(t *testing.T) { alterNonceIdx := mr.Intn(aead.NonceSize()) nonce[alterNonceIdx] ^= 0x80 if _, err := aead.Open(nil, nonce[:], ct, ad); err == nil { - t.Errorf("Random #%d: Open was successful after altering nonce", i) + t.Errorf("random #%d: Open was successful after altering nonce", i) } nonce[alterNonceIdx] ^= 0x80 alterCtIdx := mr.Intn(len(ct)) ct[alterCtIdx] ^= 0x80 if _, err := aead.Open(nil, nonce[:], ct, ad); err == nil { - t.Errorf("Random #%d: Open was successful after altering ciphertext", i) + t.Errorf("random #%d: Open was successful after altering ciphertext", i) } ct[alterCtIdx] ^= 0x80 } diff --git a/crypto/xsalsa20symmetric/symmetric.go b/crypto/xsalsa20symmetric/symmetric.go index 73dc9dec5..74cb4b103 100644 --- a/crypto/xsalsa20symmetric/symmetric.go +++ b/crypto/xsalsa20symmetric/symmetric.go @@ -38,7 +38,7 @@ func DecryptSymmetric(ciphertext []byte, secret []byte) (plaintext []byte, err e panic(fmt.Sprintf("Secret must be 32 bytes long, got len %v", len(secret))) } if len(ciphertext) <= secretbox.Overhead+nonceLen { - return nil, errors.New("Ciphertext is too short") + return nil, errors.New("ciphertext is too short") } nonce := ciphertext[:nonceLen] nonceArr := [nonceLen]byte{} @@ -48,7 +48,7 @@ func DecryptSymmetric(ciphertext []byte, secret []byte) (plaintext []byte, err e plaintext = make([]byte, len(ciphertext)-nonceLen-secretbox.Overhead) _, ok := secretbox.Open(plaintext[:0], ciphertext[nonceLen:], &nonceArr, &secretArr) if !ok { - return nil, errors.New("Ciphertext decryption failed") + return nil, errors.New("ciphertext decryption failed") } return plaintext, nil } diff --git a/docs/spec/scripts/crypto.go b/docs/spec/scripts/crypto.go index e040f0e6a..7116bdda2 100644 --- a/docs/spec/scripts/crypto.go +++ b/docs/spec/scripts/crypto.go @@ -5,12 +5,12 @@ import ( "os" amino "github.com/tendermint/go-amino" - cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino" + cryptoamino "github.com/tendermint/tendermint/crypto/encoding/amino" ) func main() { cdc := amino.NewCodec() - cryptoAmino.RegisterAmino(cdc) + cryptoamino.RegisterAmino(cdc) cdc.PrintTypes(os.Stdout) fmt.Println("") } diff --git a/evidence/codec.go b/evidence/codec.go index 6752bc3e2..73cf466c4 100644 --- a/evidence/codec.go +++ b/evidence/codec.go @@ -2,7 +2,7 @@ package evidence import ( amino "github.com/tendermint/go-amino" - cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino" + cryptoamino "github.com/tendermint/tendermint/crypto/encoding/amino" "github.com/tendermint/tendermint/types" ) @@ -10,7 +10,7 @@ var cdc = amino.NewCodec() func init() { RegisterEvidenceMessages(cdc) - cryptoAmino.RegisterAmino(cdc) + cryptoamino.RegisterAmino(cdc) types.RegisterEvidences(cdc) } diff --git a/evidence/reactor.go b/evidence/reactor.go index 1a2e52693..09f7b272e 100644 --- a/evidence/reactor.go +++ b/evidence/reactor.go @@ -218,7 +218,7 @@ func RegisterEvidenceMessages(cdc *amino.Codec) { func decodeMsg(bz []byte) (msg EvidenceMessage, err error) { if len(bz) > maxMsgSize { - return msg, fmt.Errorf("Msg exceeds max size (%d > %d)", len(bz), maxMsgSize) + return msg, fmt.Errorf("msg exceeds max size (%d > %d)", len(bz), maxMsgSize) } err = cdc.UnmarshalBinaryBare(bz, &msg) return @@ -235,7 +235,7 @@ type EvidenceListMessage struct { func (m *EvidenceListMessage) ValidateBasic() error { for i, ev := range m.Evidence { if err := ev.ValidateBasic(); err != nil { - return fmt.Errorf("Invalid evidence (#%d): %v", i, err) + return fmt.Errorf("invalid evidence (#%d): %v", i, err) } } return nil diff --git a/evidence/reactor_test.go b/evidence/reactor_test.go index 9f081c8ef..b3f95dd57 100644 --- a/evidence/reactor_test.go +++ b/evidence/reactor_test.go @@ -66,7 +66,7 @@ func waitForEvidence(t *testing.T, evs types.EvidenceList, reactors []*EvidenceR close(done) }() - timer := time.After(TIMEOUT) + timer := time.After(Timeout) select { case <-timer: t.Fatal("Timed out waiting for evidence") @@ -115,8 +115,8 @@ func sendEvidence(t *testing.T, evpool *EvidencePool, valAddr []byte, n int) typ } var ( - NUM_EVIDENCE = 10 - TIMEOUT = 120 * time.Second // ridiculously high because CircleCI is slow + NumEvidence = 10 + Timeout = 120 * time.Second // ridiculously high because CircleCI is slow ) func TestReactorBroadcastEvidence(t *testing.T) { @@ -127,7 +127,7 @@ func TestReactorBroadcastEvidence(t *testing.T) { stateDBs := make([]dbm.DB, N) valAddr := []byte("myval") // we need validators saved for heights at least as high as we have evidence for - height := int64(NUM_EVIDENCE) + 10 + height := int64(NumEvidence) + 10 for i := 0; i < N; i++ { stateDBs[i] = initializeValidatorState(valAddr, height) } @@ -145,7 +145,7 @@ func TestReactorBroadcastEvidence(t *testing.T) { // send a bunch of valid evidence to the first reactor's evpool // and wait for them all to be received in the others - evList := sendEvidence(t, reactors[0].evpool, valAddr, NUM_EVIDENCE) + evList := sendEvidence(t, reactors[0].evpool, valAddr, NumEvidence) waitForEvidence(t, evList, reactors) } @@ -161,8 +161,8 @@ func TestReactorSelectiveBroadcast(t *testing.T) { config := cfg.TestConfig() valAddr := []byte("myval") - height1 := int64(NUM_EVIDENCE) + 10 - height2 := int64(NUM_EVIDENCE) / 2 + height1 := int64(NumEvidence) + 10 + height2 := int64(NumEvidence) / 2 // DB1 is ahead of DB2 stateDB1 := initializeValidatorState(valAddr, height1) @@ -185,10 +185,10 @@ func TestReactorSelectiveBroadcast(t *testing.T) { peer.Set(types.PeerStateKey, ps) // send a bunch of valid evidence to the first reactor's evpool - evList := sendEvidence(t, reactors[0].evpool, valAddr, NUM_EVIDENCE) + evList := sendEvidence(t, reactors[0].evpool, valAddr, NumEvidence) // only ones less than the peers height should make it through - waitForEvidence(t, evList[:NUM_EVIDENCE/2], reactors[1:2]) + waitForEvidence(t, evList[:NumEvidence/2], reactors[1:2]) // peers should still be connected peers := reactors[1].Switch.Peers().List() diff --git a/libs/autofile/autofile_test.go b/libs/autofile/autofile_test.go index d9c90309e..921a317e9 100644 --- a/libs/autofile/autofile_test.go +++ b/libs/autofile/autofile_test.go @@ -50,10 +50,10 @@ func TestSIGHUP(t *testing.T) { // Both files should exist if body := cmn.MustReadFile(name + "_old"); string(body) != "Line 1\nLine 2\n" { - t.Errorf("Unexpected body %s", body) + t.Errorf("unexpected body %s", body) } if body := cmn.MustReadFile(name); string(body) != "Line 3\nLine 4\n" { - t.Errorf("Unexpected body %s", body) + t.Errorf("unexpected body %s", body) } } diff --git a/libs/autofile/group_test.go b/libs/autofile/group_test.go index c300aba71..434292248 100644 --- a/libs/autofile/group_test.go +++ b/libs/autofile/group_test.go @@ -118,14 +118,14 @@ func TestRotateFile(t *testing.T) { body1, err := ioutil.ReadFile(g.Head.Path + ".000") assert.NoError(t, err, "Failed to read first rolled file") if string(body1) != "Line 1\nLine 2\nLine 3\n" { - t.Errorf("Got unexpected contents: [%v]", string(body1)) + t.Errorf("got unexpected contents: [%v]", string(body1)) } // Read g.Head.Path body2, err := ioutil.ReadFile(g.Head.Path) assert.NoError(t, err, "Failed to read first rolled file") if string(body2) != "Line 4\nLine 5\nLine 6\n" { - t.Errorf("Got unexpected contents: [%v]", string(body2)) + t.Errorf("got unexpected contents: [%v]", string(body2)) } // Cleanup diff --git a/libs/cli/flags/log_level.go b/libs/cli/flags/log_level.go index 241000e29..ce88ab835 100644 --- a/libs/cli/flags/log_level.go +++ b/libs/cli/flags/log_level.go @@ -21,7 +21,7 @@ const ( // ParseLogLevel("consensus:debug,mempool:debug,*:error", log.NewTMLogger(os.Stdout), "info") func ParseLogLevel(lvl string, logger log.Logger, defaultLogLevelValue string) (log.Logger, error) { if lvl == "" { - return nil, errors.New("Empty log level") + return nil, errors.New("empty log level") } l := lvl @@ -42,7 +42,7 @@ func ParseLogLevel(lvl string, logger log.Logger, defaultLogLevelValue string) ( moduleAndLevel := strings.Split(item, ":") if len(moduleAndLevel) != 2 { - return nil, fmt.Errorf("Expected list in a form of \"module:level\" pairs, given pair %s, list %s", item, list) + return nil, fmt.Errorf("expected list in a form of \"module:level\" pairs, given pair %s, list %s", item, list) } module := moduleAndLevel[0] @@ -67,7 +67,7 @@ func ParseLogLevel(lvl string, logger log.Logger, defaultLogLevelValue string) ( option = log.AllowNoneWith("module", module) default: return nil, - fmt.Errorf("Expected either \"info\", \"debug\", \"error\" or \"none\" log level, given %s (pair %s, list %s)", + fmt.Errorf("expected either \"info\", \"debug\", \"error\" or \"none\" log level, given %s (pair %s, list %s)", level, item, list) diff --git a/libs/cli/setup.go b/libs/cli/setup.go index 06cf1cd1f..6a379c4ad 100644 --- a/libs/cli/setup.go +++ b/libs/cli/setup.go @@ -151,7 +151,7 @@ func validateOutput(cmd *cobra.Command, args []string) error { switch output { case "text", "json": default: - return errors.Errorf("Unsupported output format: %s", output) + return errors.Errorf("unsupported output format: %s", output) } return nil } diff --git a/libs/clist/clist_test.go b/libs/clist/clist_test.go index 1784f8218..64cc75d1b 100644 --- a/libs/clist/clist_test.go +++ b/libs/clist/clist_test.go @@ -109,7 +109,7 @@ func _TestGCFifo(t *testing.T) { _ = done if *gcCount != numElements { - t.Errorf("Expected gcCount to be %v, got %v", numElements, + t.Errorf("expected gcCount to be %v, got %v", numElements, *gcCount) } } @@ -157,7 +157,7 @@ func _TestGCRandom(t *testing.T) { time.Sleep(time.Second * 3) if gcCount != numElements { - t.Errorf("Expected gcCount to be %v, got %v", numElements, + t.Errorf("expected gcCount to be %v, got %v", numElements, gcCount) } } diff --git a/libs/common/async.go b/libs/common/async.go index 7da2d2a52..76a9ec9c7 100644 --- a/libs/common/async.go +++ b/libs/common/async.go @@ -10,7 +10,7 @@ import ( // val: the value returned after task execution. // err: the error returned during task completion. // abort: tells Parallel to return, whether or not all tasks have completed. -type Task func(i int) (val interface{}, err error, abort bool) +type Task func(i int) (val interface{}, abort bool, err error) type TaskResult struct { Value interface{} @@ -150,7 +150,7 @@ func Parallel(tasks ...Task) (trs *TaskResultSet, ok bool) { } }() // Run the task. - var val, err, abort = task(i) + var val, abort, err = task(i) // Send val/err to taskResultCh. // NOTE: Below this line, nothing must panic/ taskResultCh <- TaskResult{val, err} diff --git a/libs/common/async_test.go b/libs/common/async_test.go index 9ac5ffe3f..dc90d380c 100644 --- a/libs/common/async_test.go +++ b/libs/common/async_test.go @@ -16,9 +16,9 @@ func TestParallel(t *testing.T) { var counter = new(int32) var tasks = make([]Task, 100*1000) for i := 0; i < len(tasks); i++ { - tasks[i] = func(i int) (res interface{}, err error, abort bool) { + tasks[i] = func(i int) (res interface{}, abort bool, err error) { atomic.AddInt32(counter, 1) - return -1 * i, nil, false + return -1 * i, false, nil } } @@ -60,25 +60,25 @@ func TestParallelAbort(t *testing.T) { // Create tasks. var tasks = []Task{ - func(i int) (res interface{}, err error, abort bool) { + func(i int) (res interface{}, abort bool, err error) { assert.Equal(t, i, 0) flow1 <- struct{}{} - return 0, nil, false + return 0, false, nil }, - func(i int) (res interface{}, err error, abort bool) { + func(i int) (res interface{}, abort bool, err error) { assert.Equal(t, i, 1) flow2 <- <-flow1 - return 1, errors.New("some error"), false + return 1, false, errors.New("some error") }, - func(i int) (res interface{}, err error, abort bool) { + func(i int) (res interface{}, abort bool, err error) { assert.Equal(t, i, 2) flow3 <- <-flow2 - return 2, nil, true + return 2, true, nil }, - func(i int) (res interface{}, err error, abort bool) { + func(i int) (res interface{}, abort bool, err error) { assert.Equal(t, i, 3) <-flow4 - return 3, nil, false + return 3, false, nil }, } @@ -107,13 +107,13 @@ func TestParallelRecover(t *testing.T) { // Create tasks. var tasks = []Task{ - func(i int) (res interface{}, err error, abort bool) { - return 0, nil, false + func(i int) (res interface{}, abort bool, err error) { + return 0, false, nil }, - func(i int) (res interface{}, err error, abort bool) { - return 1, errors.New("some error"), false + func(i int) (res interface{}, abort bool, err error) { + return 1, false, errors.New("some error") }, - func(i int) (res interface{}, err error, abort bool) { + func(i int) (res interface{}, abort bool, err error) { panic(2) }, } diff --git a/libs/common/bit_array.go b/libs/common/bit_array.go index 2e6c255cc..e996b390e 100644 --- a/libs/common/bit_array.go +++ b/libs/common/bit_array.go @@ -400,7 +400,7 @@ func (bA *BitArray) UnmarshalJSON(bz []byte) error { // Validate 'b'. match := bitArrayJSONRegexp.FindStringSubmatch(b) if match == nil { - return fmt.Errorf("BitArray in JSON should be a string of format %q but got %s", bitArrayJSONRegexp.String(), b) + return fmt.Errorf("bitArray in JSON should be a string of format %q but got %s", bitArrayJSONRegexp.String(), b) } bits := match[1] diff --git a/libs/common/bytes.go b/libs/common/bytes.go index 711720aa7..3c1c77589 100644 --- a/libs/common/bytes.go +++ b/libs/common/bytes.go @@ -33,7 +33,7 @@ func (bz HexBytes) MarshalJSON() ([]byte, error) { // This is the point of Bytes. func (bz *HexBytes) UnmarshalJSON(data []byte) error { if len(data) < 2 || data[0] != '"' || data[len(data)-1] != '"' { - return fmt.Errorf("Invalid hex string: %s", data) + return fmt.Errorf("invalid hex string: %s", data) } bz2, err := hex.DecodeString(string(data[1 : len(data)-1])) if err != nil { diff --git a/libs/common/os.go b/libs/common/os.go index 0e35524cf..4b25653ae 100644 --- a/libs/common/os.go +++ b/libs/common/os.go @@ -46,7 +46,7 @@ func EnsureDir(dir string, mode os.FileMode) error { if _, err := os.Stat(dir); os.IsNotExist(err) { err := os.MkdirAll(dir, mode) if err != nil { - return fmt.Errorf("Could not create directory %v. %v", dir, err) + return fmt.Errorf("could not create directory %v. %v", dir, err) } } return nil diff --git a/libs/common/random_test.go b/libs/common/random_test.go index 74dcc04b4..0cfb9d1af 100644 --- a/libs/common/random_test.go +++ b/libs/common/random_test.go @@ -46,7 +46,7 @@ func TestDeterminism(t *testing.T) { if i == 0 { firstOutput = output } else if firstOutput != output { - t.Errorf("Run #%d's output was different from first run.\nfirst: %v\nlast: %v", + t.Errorf("run #%d's output was different from first run.\nfirst: %v\nlast: %v", i, firstOutput, output) } } diff --git a/libs/common/tempfile.go b/libs/common/tempfile.go index a5bb7a5b5..c0bcfe3a3 100644 --- a/libs/common/tempfile.go +++ b/libs/common/tempfile.go @@ -108,7 +108,7 @@ func WriteFileAtomic(filename string, data []byte, perm os.FileMode) (err error) break } if i == atomicWriteFileMaxNumWriteAttempts { - return fmt.Errorf("Could not create atomic write file after %d attempts", i) + return fmt.Errorf("could not create atomic write file after %d attempts", i) } // Clean up in any case. Defer stacking order is last-in-first-out. diff --git a/libs/events/events_test.go b/libs/events/events_test.go index e5a0e8697..d8d302f34 100644 --- a/libs/events/events_test.go +++ b/libs/events/events_test.go @@ -29,7 +29,7 @@ func TestAddListenerForEventFireOnce(t *testing.T) { go evsw.FireEvent("event", "data") received := <-messages if received != "data" { - t.Errorf("Message received does not match: %v", received) + t.Errorf("message received does not match: %v", received) } } @@ -57,7 +57,7 @@ func TestAddListenerForEventFireMany(t *testing.T) { close(numbers) eventSum := <-doneSum if checkSum != eventSum { - t.Errorf("Not all messages sent were received.\n") + t.Errorf("not all messages sent were received.\n") } } @@ -101,7 +101,7 @@ func TestAddListenerForDifferentEvents(t *testing.T) { close(numbers) eventSum := <-doneSum if checkSum != eventSum { - t.Errorf("Not all messages sent were received.\n") + t.Errorf("not all messages sent were received.\n") } } @@ -162,7 +162,7 @@ func TestAddDifferentListenerForDifferentEvents(t *testing.T) { eventSum2 := <-doneSum2 if checkSum1 != eventSum1 || checkSum2 != eventSum2 { - t.Errorf("Not all messages sent were received for different listeners to different events.\n") + t.Errorf("not all messages sent were received for different listeners to different events.\n") } } @@ -255,7 +255,7 @@ func TestAddAndRemoveListener(t *testing.T) { // correct value asserted by preceding tests, suffices to be non-zero checkSumEvent2 == uint64(0) || eventSum2 != uint64(0) { - t.Errorf("Not all messages sent were received or unsubscription did not register.\n") + t.Errorf("not all messages sent were received or unsubscription did not register.\n") } } @@ -390,7 +390,7 @@ func TestRemoveListenersAsync(t *testing.T) { eventSum2 := <-doneSum2 if checkSum != eventSum1 || checkSum != eventSum2 { - t.Errorf("Not all messages sent were received.\n") + t.Errorf("not all messages sent were received.\n") } } diff --git a/libs/log/filter.go b/libs/log/filter.go index cb43621ce..e39a85dcb 100644 --- a/libs/log/filter.go +++ b/libs/log/filter.go @@ -141,7 +141,7 @@ func AllowLevel(lvl string) (Option, error) { case "none": return AllowNone(), nil default: - return nil, fmt.Errorf("Expected either \"info\", \"debug\", \"error\" or \"none\" level, given %s", lvl) + return nil, fmt.Errorf("expected either \"info\", \"debug\", \"error\" or \"none\" level, given %s", lvl) } } diff --git a/libs/log/tm_logger_test.go b/libs/log/tm_logger_test.go index e4fdbaa21..92fbe40eb 100644 --- a/libs/log/tm_logger_test.go +++ b/libs/log/tm_logger_test.go @@ -16,7 +16,7 @@ func TestLoggerLogsItsErrors(t *testing.T) { logger.Info("foo", "baz baz", "bar") msg := strings.TrimSpace(buf.String()) if !strings.Contains(msg, "foo") { - t.Errorf("Expected logger msg to contain ErrInvalidKey, got %s", msg) + t.Errorf("expected logger msg to contain ErrInvalidKey, got %s", msg) } } diff --git a/libs/log/tracing_logger_test.go b/libs/log/tracing_logger_test.go index 978a240f6..919272b21 100644 --- a/libs/log/tracing_logger_test.go +++ b/libs/log/tracing_logger_test.go @@ -17,8 +17,8 @@ func TestTracingLogger(t *testing.T) { logger := log.NewTMJSONLogger(&buf) logger1 := log.NewTracingLogger(logger) - err1 := errors.New("Courage is grace under pressure.") - err2 := errors.New("It does not matter how slowly you go, so long as you do not stop.") + err1 := errors.New("courage is grace under pressure.") + err2 := errors.New("it does not matter how slowly you go, so long as you do not stop.") logger1.With("err1", err1).Info("foo", "err2", err2) want := strings.Replace( diff --git a/libs/pubsub/pubsub_test.go b/libs/pubsub/pubsub_test.go index f799eabdf..f9dd592d1 100644 --- a/libs/pubsub/pubsub_test.go +++ b/libs/pubsub/pubsub_test.go @@ -427,7 +427,7 @@ func assertReceive(t *testing.T, expected interface{}, ch <-chan pubsub.Message, case actual := <-ch: assert.Equal(t, expected, actual.Data(), msgAndArgs...) case <-time.After(1 * time.Second): - t.Errorf("Expected to receive %v from the channel, got nothing after 1s", expected) + t.Errorf("expected to receive %v from the channel, got nothing after 1s", expected) debug.PrintStack() } } diff --git a/lite/dbprovider.go b/lite/dbprovider.go index bbde7ef8c..e45cb3487 100644 --- a/lite/dbprovider.go +++ b/lite/dbprovider.go @@ -6,7 +6,7 @@ import ( "strconv" amino "github.com/tendermint/go-amino" - cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino" + cryptoamino "github.com/tendermint/tendermint/crypto/encoding/amino" log "github.com/tendermint/tendermint/libs/log" lerr "github.com/tendermint/tendermint/lite/errors" "github.com/tendermint/tendermint/types" @@ -30,7 +30,7 @@ func NewDBProvider(label string, db dbm.DB) *DBProvider { //db = dbm.NewDebugDB("db provider "+cmn.RandStr(4), db) cdc := amino.NewCodec() - cryptoAmino.RegisterAmino(cdc) + cryptoamino.RegisterAmino(cdc) dbp := &DBProvider{ logger: log.NewNopLogger(), label: label, diff --git a/lite/proxy/block.go b/lite/proxy/block.go index 035871a11..d154bf333 100644 --- a/lite/proxy/block.go +++ b/lite/proxy/block.go @@ -24,7 +24,7 @@ func ValidateBlock(meta *types.Block, sh types.SignedHeader) error { return err } if !bytes.Equal(meta.Data.Hash(), meta.Header.DataHash) { - return errors.New("Data hash doesn't match header") + return errors.New("data hash doesn't match header") } return nil } @@ -38,11 +38,11 @@ func ValidateHeader(head *types.Header, sh types.SignedHeader) error { } // Make sure they are for the same height (obvious fail). if head.Height != sh.Height { - return errors.New("Header heights mismatched") + return errors.New("header heights mismatched") } // Check if they are equal by using hashes. if !bytes.Equal(head.Hash(), sh.Hash()) { - return errors.New("Headers don't match") + return errors.New("headers don't match") } return nil } diff --git a/lite/proxy/validate_test.go b/lite/proxy/validate_test.go index dce177d7b..e55fc666e 100644 --- a/lite/proxy/validate_test.go +++ b/lite/proxy/validate_test.go @@ -40,7 +40,7 @@ func TestValidateBlock(t *testing.T) { { block: &types.Block{Header: types.Header{Height: 10}}, signedHeader: types.SignedHeader{Header: &types.Header{Height: 11}}, - wantErr: "Header heights mismatched", + wantErr: "header heights mismatched", }, { @@ -53,7 +53,7 @@ func TestValidateBlock(t *testing.T) { { block: &types.Block{Header: hdrHeight11}, signedHeader: types.SignedHeader{Header: &types.Header{Height: 11}}, - wantErr: "Headers don't match", + wantErr: "headers don't match", }, { @@ -72,7 +72,7 @@ func TestValidateBlock(t *testing.T) { Header: &types.Header{Height: 11}, Commit: types.NewCommit(types.BlockID{Hash: []byte("0xDEADBEEF")}, nil), }, - wantErr: "Data hash doesn't match header", + wantErr: "data hash doesn't match header", }, { block: &types.Block{ @@ -119,7 +119,7 @@ func TestValidateBlockMeta(t *testing.T) { { meta: &types.BlockMeta{Header: types.Header{Height: 10}}, signedHeader: types.SignedHeader{Header: &types.Header{Height: 11}}, - wantErr: "Header heights mismatched", + wantErr: "header heights mismatched", }, { @@ -132,7 +132,7 @@ func TestValidateBlockMeta(t *testing.T) { { meta: &types.BlockMeta{Header: hdrHeight11}, signedHeader: types.SignedHeader{Header: &types.Header{Height: 11}}, - wantErr: "Headers don't match", + wantErr: "headers don't match", }, { @@ -152,7 +152,7 @@ func TestValidateBlockMeta(t *testing.T) { signedHeader: types.SignedHeader{ Header: &types.Header{Height: 11, DataHash: deadBeefHash}, }, - wantErr: "Headers don't match", + wantErr: "headers don't match", }, { @@ -171,7 +171,7 @@ func TestValidateBlockMeta(t *testing.T) { }, Commit: types.NewCommit(types.BlockID{Hash: []byte("DEADBEEF")}, nil), }, - wantErr: "Headers don't match", + wantErr: "headers don't match", }, { @@ -190,7 +190,7 @@ func TestValidateBlockMeta(t *testing.T) { }, Commit: types.NewCommit(types.BlockID{Hash: []byte("DEADBEEF")}, nil), }, - wantErr: "Headers don't match", + wantErr: "headers don't match", }, // End Headers don't match test } diff --git a/mempool/clist_mempool_test.go b/mempool/clist_mempool_test.go index 3e52c0319..26ea7ec01 100644 --- a/mempool/clist_mempool_test.go +++ b/mempool/clist_mempool_test.go @@ -316,19 +316,19 @@ func TestSerialReap(t *testing.T) { binary.BigEndian.PutUint64(txBytes, uint64(i)) res, err := appConnCon.DeliverTxSync(abci.RequestDeliverTx{Tx: txBytes}) if err != nil { - t.Errorf("Client error committing tx: %v", err) + t.Errorf("client error committing tx: %v", err) } if res.IsErr() { - t.Errorf("Error committing tx. Code:%v result:%X log:%v", + t.Errorf("error committing tx. Code:%v result:%X log:%v", res.Code, res.Data, res.Log) } } res, err := appConnCon.CommitSync() if err != nil { - t.Errorf("Client error committing: %v", err) + t.Errorf("client error committing: %v", err) } if len(res.Data) != 8 { - t.Errorf("Error committing. Hash:%X", res.Data) + t.Errorf("error committing. Hash:%X", res.Data) } } diff --git a/mempool/errors.go b/mempool/errors.go index c5140bdf0..8e4dcf7cd 100644 --- a/mempool/errors.go +++ b/mempool/errors.go @@ -8,7 +8,7 @@ import ( var ( // ErrTxInCache is returned to the client if we saw tx earlier - ErrTxInCache = errors.New("Tx already exists in cache") + ErrTxInCache = errors.New("tx already exists in cache") ) // ErrTxTooLarge means the tx is too big to be sent in a message to other peers diff --git a/mempool/mempool.go b/mempool/mempool.go index 004c1c8d1..97919ab99 100644 --- a/mempool/mempool.go +++ b/mempool/mempool.go @@ -112,7 +112,7 @@ func PreCheckAminoMaxBytes(maxBytes int64) PreCheckFunc { aminoOverhead := types.ComputeAminoOverhead(tx, 1) txSize := int64(len(tx)) + aminoOverhead if txSize > maxBytes { - return fmt.Errorf("Tx size (including amino overhead) is too big: %d, max: %d", + return fmt.Errorf("tx size (including amino overhead) is too big: %d, max: %d", txSize, maxBytes) } return nil diff --git a/mempool/reactor_test.go b/mempool/reactor_test.go index dff4c0d68..e3076d37a 100644 --- a/mempool/reactor_test.go +++ b/mempool/reactor_test.go @@ -80,7 +80,7 @@ func waitForTxsOnReactors(t *testing.T, txs types.Txs, reactors []*Reactor) { close(done) }() - timer := time.After(TIMEOUT) + timer := time.After(Timeout) select { case <-timer: t.Fatal("Timed out waiting for txs") @@ -108,8 +108,8 @@ func ensureNoTxs(t *testing.T, reactor *Reactor, timeout time.Duration) { } const ( - NUM_TXS = 1000 - TIMEOUT = 120 * time.Second // ridiculously high because CircleCI is slow + NumTxs = 1000 + Timeout = 120 * time.Second // ridiculously high because CircleCI is slow ) func TestReactorBroadcastTxMessage(t *testing.T) { @@ -129,7 +129,7 @@ func TestReactorBroadcastTxMessage(t *testing.T) { // send a bunch of txs to the first reactor's mempool // and wait for them all to be received in the others - txs := checkTxs(t, reactors[0].mempool, NUM_TXS, UnknownPeerID) + txs := checkTxs(t, reactors[0].mempool, NumTxs, UnknownPeerID) waitForTxsOnReactors(t, txs, reactors) } @@ -145,7 +145,7 @@ func TestReactorNoBroadcastToSender(t *testing.T) { // send a bunch of txs to the first reactor's mempool, claiming it came from peer // ensure peer gets no txs - checkTxs(t, reactors[0].mempool, NUM_TXS, 1) + checkTxs(t, reactors[0].mempool, NumTxs, 1) ensureNoTxs(t, reactors[1], 100*time.Millisecond) } diff --git a/node/codec.go b/node/codec.go index 3bd6de2fc..7607b0dd0 100644 --- a/node/codec.go +++ b/node/codec.go @@ -2,11 +2,11 @@ package node import ( amino "github.com/tendermint/go-amino" - cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino" + cryptoamino "github.com/tendermint/tendermint/crypto/encoding/amino" ) var cdc = amino.NewCodec() func init() { - cryptoAmino.RegisterAmino(cdc) + cryptoamino.RegisterAmino(cdc) } diff --git a/node/node.go b/node/node.go index e6d977728..f4f04bd22 100644 --- a/node/node.go +++ b/node/node.go @@ -99,7 +99,7 @@ func DefaultNewNode(config *cfg.Config, logger log.Logger) (*Node, error) { if _, err := os.Stat(oldPrivVal); !os.IsNotExist(err) { oldPV, err := privval.LoadOldFilePV(oldPrivVal) if err != nil { - return nil, fmt.Errorf("error reading OldPrivValidator from %v: %v\n", oldPrivVal, err) + return nil, fmt.Errorf("error reading OldPrivValidator from %v: %v", oldPrivVal, err) } logger.Info("Upgrading PrivValidator file", "old", oldPrivVal, @@ -1154,7 +1154,7 @@ func LoadStateFromDBOrGenesisDocProvider( func loadGenesisDoc(db dbm.DB) (*types.GenesisDoc, error) { b := db.Get(genesisDocKey) if len(b) == 0 { - return nil, errors.New("Genesis doc not found") + return nil, errors.New("genesis doc not found") } var genDoc *types.GenesisDoc err := cdc.UnmarshalJSON(b, &genDoc) diff --git a/p2p/codec.go b/p2p/codec.go index 191e3c523..6368b7d68 100644 --- a/p2p/codec.go +++ b/p2p/codec.go @@ -2,11 +2,11 @@ package p2p import ( amino "github.com/tendermint/go-amino" - cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino" + cryptoamino "github.com/tendermint/tendermint/crypto/encoding/amino" ) var cdc = amino.NewCodec() func init() { - cryptoAmino.RegisterAmino(cdc) + cryptoamino.RegisterAmino(cdc) } diff --git a/p2p/conn/codec.go b/p2p/conn/codec.go index 5231a6ca1..149a09638 100644 --- a/p2p/conn/codec.go +++ b/p2p/conn/codec.go @@ -2,12 +2,12 @@ package conn import ( amino "github.com/tendermint/go-amino" - cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino" + cryptoamino "github.com/tendermint/tendermint/crypto/encoding/amino" ) var cdc *amino.Codec = amino.NewCodec() func init() { - cryptoAmino.RegisterAmino(cdc) + cryptoamino.RegisterAmino(cdc) RegisterPacket(cdc) } diff --git a/p2p/conn/connection.go b/p2p/conn/connection.go index e9b76e24d..77fca6648 100644 --- a/p2p/conn/connection.go +++ b/p2p/conn/connection.go @@ -617,7 +617,7 @@ FOR_LOOP: case PacketMsg: channel, ok := c.channelsIdx[pkt.ChannelID] if !ok || channel == nil { - err := fmt.Errorf("Unknown channel %X", pkt.ChannelID) + err := fmt.Errorf("unknown channel %X", pkt.ChannelID) c.Logger.Error("Connection failed @ recvRoutine", "conn", c, "err", err) c.stopForError(err) break FOR_LOOP @@ -637,7 +637,7 @@ FOR_LOOP: c.onReceive(pkt.ChannelID, msgBytes) } default: - err := fmt.Errorf("Unknown message type %v", reflect.TypeOf(packet)) + err := fmt.Errorf("unknown message type %v", reflect.TypeOf(packet)) c.Logger.Error("Connection failed @ recvRoutine", "conn", c, "err", err) c.stopForError(err) break FOR_LOOP @@ -844,7 +844,7 @@ func (ch *Channel) recvPacketMsg(packet PacketMsg) ([]byte, error) { ch.Logger.Debug("Read PacketMsg", "conn", ch.conn, "packet", packet) var recvCap, recvReceived = ch.desc.RecvMessageCapacity, len(ch.recving) + len(packet.Bytes) if recvCap < recvReceived { - return nil, fmt.Errorf("Received message exceeds available capacity: %v < %v", recvCap, recvReceived) + return nil, fmt.Errorf("received message exceeds available capacity: %v < %v", recvCap, recvReceived) } ch.recving = append(ch.recving, packet.Bytes...) if packet.EOF == byte(0x01) { @@ -882,9 +882,9 @@ func RegisterPacket(cdc *amino.Codec) { cdc.RegisterConcrete(PacketMsg{}, "tendermint/p2p/PacketMsg", nil) } -func (_ PacketPing) AssertIsPacket() {} -func (_ PacketPong) AssertIsPacket() {} -func (_ PacketMsg) AssertIsPacket() {} +func (PacketPing) AssertIsPacket() {} +func (PacketPong) AssertIsPacket() {} +func (PacketMsg) AssertIsPacket() {} type PacketPing struct { } diff --git a/p2p/conn/secret_connection.go b/p2p/conn/secret_connection.go index 9d6825df8..5e5dfd1bb 100644 --- a/p2p/conn/secret_connection.go +++ b/p2p/conn/secret_connection.go @@ -296,21 +296,20 @@ func shareEphPubKey(conn io.ReadWriter, locEphPub *[32]byte) (remEphPub *[32]byt // Send our pubkey and receive theirs in tandem. var trs, _ = cmn.Parallel( - func(_ int) (val interface{}, err error, abort bool) { + func(_ int) (val interface{}, abort bool, err error) { var _, err1 = cdc.MarshalBinaryLengthPrefixedWriter(conn, locEphPub) if err1 != nil { - return nil, err1, true // abort + return nil, true, err1 // abort } - return nil, nil, false + return nil, false, nil }, - func(_ int) (val interface{}, err error, abort bool) { + func(_ int) (val interface{}, abort bool, err error) { var _remEphPub [32]byte var _, err2 = cdc.UnmarshalBinaryLengthPrefixedReader(conn, &_remEphPub, 1024*1024) // TODO if err2 != nil { - return nil, err2, true // abort + return nil, true, err2 // abort } - - return _remEphPub, nil, false + return _remEphPub, false, nil }, ) @@ -405,20 +404,20 @@ func shareAuthSignature(sc io.ReadWriter, pubKey crypto.PubKey, signature []byte // Send our info and receive theirs in tandem. var trs, _ = cmn.Parallel( - func(_ int) (val interface{}, err error, abort bool) { + func(_ int) (val interface{}, abort bool, err error) { var _, err1 = cdc.MarshalBinaryLengthPrefixedWriter(sc, authSigMessage{pubKey, signature}) if err1 != nil { - return nil, err1, true // abort + return nil, true, err1 // abort } - return nil, nil, false + return nil, false, nil }, - func(_ int) (val interface{}, err error, abort bool) { + func(_ int) (val interface{}, abort bool, err error) { var _recvMsg authSigMessage var _, err2 = cdc.UnmarshalBinaryLengthPrefixedReader(sc, &_recvMsg, 1024*1024) // TODO if err2 != nil { - return nil, err2, true // abort + return nil, true, err2 // abort } - return _recvMsg, nil, false + return _recvMsg, false, nil }, ) diff --git a/p2p/conn/secret_connection_test.go b/p2p/conn/secret_connection_test.go index e0d5f4fac..b9b7b482e 100644 --- a/p2p/conn/secret_connection_test.go +++ b/p2p/conn/secret_connection_test.go @@ -53,35 +53,35 @@ func makeSecretConnPair(tb testing.TB) (fooSecConn, barSecConn *SecretConnection // Make connections from both sides in parallel. var trs, ok = cmn.Parallel( - func(_ int) (val interface{}, err error, abort bool) { + func(_ int) (val interface{}, abort bool, err error) { fooSecConn, err = MakeSecretConnection(fooConn, fooPrvKey) if err != nil { - tb.Errorf("Failed to establish SecretConnection for foo: %v", err) - return nil, err, true + tb.Errorf("failed to establish SecretConnection for foo: %v", err) + return nil, true, err } remotePubBytes := fooSecConn.RemotePubKey() if !remotePubBytes.Equals(barPubKey) { - err = fmt.Errorf("Unexpected fooSecConn.RemotePubKey. Expected %v, got %v", + err = fmt.Errorf("unexpected fooSecConn.RemotePubKey. Expected %v, got %v", barPubKey, fooSecConn.RemotePubKey()) tb.Error(err) - return nil, err, false + return nil, false, err } - return nil, nil, false + return nil, false, nil }, - func(_ int) (val interface{}, err error, abort bool) { + func(_ int) (val interface{}, abort bool, err error) { barSecConn, err = MakeSecretConnection(barConn, barPrvKey) if barSecConn == nil { - tb.Errorf("Failed to establish SecretConnection for bar: %v", err) - return nil, err, true + tb.Errorf("failed to establish SecretConnection for bar: %v", err) + return nil, true, err } remotePubBytes := barSecConn.RemotePubKey() if !remotePubBytes.Equals(fooPubKey) { - err = fmt.Errorf("Unexpected barSecConn.RemotePubKey. Expected %v, got %v", + err = fmt.Errorf("unexpected barSecConn.RemotePubKey. Expected %v, got %v", fooPubKey, barSecConn.RemotePubKey()) tb.Error(err) - return nil, nil, false + return nil, false, nil } - return nil, nil, false + return nil, false, nil }, ) @@ -150,7 +150,7 @@ func writeLots(t *testing.T, wg *sync.WaitGroup, conn io.Writer, txt string, n i for i := 0; i < n; i++ { _, err := conn.Write([]byte(txt)) if err != nil { - t.Errorf("Failed to write to fooSecConn: %v", err) + t.Errorf("failed to write to fooSecConn: %v", err) return } } @@ -178,37 +178,37 @@ func TestSecretConnectionReadWrite(t *testing.T) { // A helper that will run with (fooConn, fooWrites, fooReads) and vice versa genNodeRunner := func(id string, nodeConn kvstoreConn, nodeWrites []string, nodeReads *[]string) cmn.Task { - return func(_ int) (interface{}, error, bool) { + return func(_ int) (interface{}, bool, error) { // Initiate cryptographic private key and secret connection trhough nodeConn. nodePrvKey := ed25519.GenPrivKey() nodeSecretConn, err := MakeSecretConnection(nodeConn, nodePrvKey) if err != nil { - t.Errorf("Failed to establish SecretConnection for node: %v", err) - return nil, err, true + t.Errorf("failed to establish SecretConnection for node: %v", err) + return nil, true, err } // In parallel, handle some reads and writes. var trs, ok = cmn.Parallel( - func(_ int) (interface{}, error, bool) { + func(_ int) (interface{}, bool, error) { // Node writes: for _, nodeWrite := range nodeWrites { n, err := nodeSecretConn.Write([]byte(nodeWrite)) if err != nil { - t.Errorf("Failed to write to nodeSecretConn: %v", err) - return nil, err, true + t.Errorf("failed to write to nodeSecretConn: %v", err) + return nil, true, err } if n != len(nodeWrite) { - err = fmt.Errorf("Failed to write all bytes. Expected %v, wrote %v", len(nodeWrite), n) + err = fmt.Errorf("failed to write all bytes. Expected %v, wrote %v", len(nodeWrite), n) t.Error(err) - return nil, err, true + return nil, true, err } } if err := nodeConn.PipeWriter.Close(); err != nil { t.Error(err) - return nil, err, true + return nil, true, err } - return nil, nil, false + return nil, false, nil }, - func(_ int) (interface{}, error, bool) { + func(_ int) (interface{}, bool, error) { // Node reads: readBuffer := make([]byte, dataMaxSize) for { @@ -216,12 +216,12 @@ func TestSecretConnectionReadWrite(t *testing.T) { if err == io.EOF { if err := nodeConn.PipeReader.Close(); err != nil { t.Error(err) - return nil, err, true + return nil, true, err } - return nil, nil, false + return nil, false, nil } else if err != nil { - t.Errorf("Failed to read from nodeSecretConn: %v", err) - return nil, err, true + t.Errorf("failed to read from nodeSecretConn: %v", err) + return nil, true, err } *nodeReads = append(*nodeReads, string(readBuffer[:n])) } @@ -231,11 +231,11 @@ func TestSecretConnectionReadWrite(t *testing.T) { // If error: if trs.FirstError() != nil { - return nil, trs.FirstError(), true + return nil, true, trs.FirstError() } // Otherwise: - return nil, nil, false + return nil, false, nil } } @@ -266,7 +266,7 @@ func TestSecretConnectionReadWrite(t *testing.T) { } // Compare if write != read { - t.Errorf("Expected to read %X, got %X", write, read) + t.Errorf("expected to read %X, got %X", write, read) } // Iterate writes = writes[1:] @@ -412,7 +412,7 @@ func BenchmarkWriteSecretConnection(b *testing.B) { if err == io.EOF { return } else if err != nil { - b.Errorf("Failed to read from barSecConn: %v", err) + b.Errorf("failed to read from barSecConn: %v", err) return } } @@ -423,7 +423,7 @@ func BenchmarkWriteSecretConnection(b *testing.B) { idx := cmn.RandIntn(len(fooWriteBytes)) _, err := fooSecConn.Write(fooWriteBytes[idx]) if err != nil { - b.Errorf("Failed to write to fooSecConn: %v", err) + b.Errorf("failed to write to fooSecConn: %v", err) return } } @@ -457,7 +457,7 @@ func BenchmarkReadSecretConnection(b *testing.B) { idx := cmn.RandIntn(len(fooWriteBytes)) _, err := fooSecConn.Write(fooWriteBytes[idx]) if err != nil { - b.Errorf("Failed to write to fooSecConn: %v, %v,%v", err, i, b.N) + b.Errorf("failed to write to fooSecConn: %v, %v,%v", err, i, b.N) return } } diff --git a/p2p/key.go b/p2p/key.go index 4e662f9f7..504cda75c 100644 --- a/p2p/key.go +++ b/p2p/key.go @@ -65,7 +65,7 @@ func LoadNodeKey(filePath string) (*NodeKey, error) { nodeKey := new(NodeKey) err = cdc.UnmarshalJSON(jsonBytes, nodeKey) if err != nil { - return nil, fmt.Errorf("Error reading NodeKey from %v: %v", filePath, err) + return nil, fmt.Errorf("error reading NodeKey from %v: %v", filePath, err) } return nodeKey, nil } diff --git a/p2p/netaddress.go b/p2p/netaddress.go index 04a2b843f..ed5b703e7 100644 --- a/p2p/netaddress.go +++ b/p2p/netaddress.go @@ -246,9 +246,9 @@ func (na *NetAddress) ReachabilityTo(o *NetAddress) int { Unreachable = 0 Default = iota Teredo - Ipv6_weak + Ipv6Weak Ipv4 - Ipv6_strong + Ipv6Strong ) switch { case !na.Routable(): @@ -262,7 +262,7 @@ func (na *NetAddress) ReachabilityTo(o *NetAddress) int { case o.IP.To4() != nil: return Ipv4 default: // ipv6 - return Ipv6_weak + return Ipv6Weak } case na.IP.To4() != nil: if o.Routable() && o.IP.To4() != nil { @@ -284,9 +284,9 @@ func (na *NetAddress) ReachabilityTo(o *NetAddress) int { return Ipv4 case tunnelled: // only prioritise ipv6 if we aren't tunnelling it. - return Ipv6_weak + return Ipv6Weak } - return Ipv6_strong + return Ipv6Strong } } diff --git a/p2p/node_info.go b/p2p/node_info.go index 8195471ed..485a5e894 100644 --- a/p2p/node_info.go +++ b/p2p/node_info.go @@ -179,13 +179,13 @@ func (info DefaultNodeInfo) CompatibleWith(other_ NodeInfo) error { } if info.ProtocolVersion.Block != other.ProtocolVersion.Block { - return fmt.Errorf("Peer is on a different Block version. Got %v, expected %v", + return fmt.Errorf("peer is on a different Block version. Got %v, expected %v", other.ProtocolVersion.Block, info.ProtocolVersion.Block) } // nodes must be on the same network if info.Network != other.Network { - return fmt.Errorf("Peer is on a different network. Got %v, expected %v", other.Network, info.Network) + return fmt.Errorf("peer is on a different network. Got %v, expected %v", other.Network, info.Network) } // if we have no channels, we're just testing @@ -205,7 +205,7 @@ OUTER_LOOP: } } if !found { - return fmt.Errorf("Peer has no common channels. Our channels: %v ; Peer channels: %v", info.Channels, other.Channels) + return fmt.Errorf("peer has no common channels. Our channels: %v ; Peer channels: %v", info.Channels, other.Channels) } return nil } diff --git a/p2p/node_info_test.go b/p2p/node_info_test.go index 57447d00e..f3c4f4e3e 100644 --- a/p2p/node_info_test.go +++ b/p2p/node_info_test.go @@ -22,7 +22,7 @@ func TestNodeInfoValidate(t *testing.T) { copy(dupChannels, channels[:5]) dupChannels = append(dupChannels, testCh) - nonAscii := "¢§µ" + nonASCII := "¢§µ" emptyTab := fmt.Sprintf("\t") emptySpace := fmt.Sprintf(" ") @@ -42,24 +42,24 @@ func TestNodeInfoValidate(t *testing.T) { {"Invalid NetAddress", func(ni *DefaultNodeInfo) { ni.ListenAddr = "not-an-address" }, true}, {"Good NetAddress", func(ni *DefaultNodeInfo) { ni.ListenAddr = "0.0.0.0:26656" }, false}, - {"Non-ASCII Version", func(ni *DefaultNodeInfo) { ni.Version = nonAscii }, true}, + {"Non-ASCII Version", func(ni *DefaultNodeInfo) { ni.Version = nonASCII }, true}, {"Empty tab Version", func(ni *DefaultNodeInfo) { ni.Version = emptyTab }, true}, {"Empty space Version", func(ni *DefaultNodeInfo) { ni.Version = emptySpace }, true}, {"Empty Version", func(ni *DefaultNodeInfo) { ni.Version = "" }, false}, - {"Non-ASCII Moniker", func(ni *DefaultNodeInfo) { ni.Moniker = nonAscii }, true}, + {"Non-ASCII Moniker", func(ni *DefaultNodeInfo) { ni.Moniker = nonASCII }, true}, {"Empty tab Moniker", func(ni *DefaultNodeInfo) { ni.Moniker = emptyTab }, true}, {"Empty space Moniker", func(ni *DefaultNodeInfo) { ni.Moniker = emptySpace }, true}, {"Empty Moniker", func(ni *DefaultNodeInfo) { ni.Moniker = "" }, true}, {"Good Moniker", func(ni *DefaultNodeInfo) { ni.Moniker = "hey its me" }, false}, - {"Non-ASCII TxIndex", func(ni *DefaultNodeInfo) { ni.Other.TxIndex = nonAscii }, true}, + {"Non-ASCII TxIndex", func(ni *DefaultNodeInfo) { ni.Other.TxIndex = nonASCII }, true}, {"Empty tab TxIndex", func(ni *DefaultNodeInfo) { ni.Other.TxIndex = emptyTab }, true}, {"Empty space TxIndex", func(ni *DefaultNodeInfo) { ni.Other.TxIndex = emptySpace }, true}, {"Empty TxIndex", func(ni *DefaultNodeInfo) { ni.Other.TxIndex = "" }, false}, {"Off TxIndex", func(ni *DefaultNodeInfo) { ni.Other.TxIndex = "off" }, false}, - {"Non-ASCII RPCAddress", func(ni *DefaultNodeInfo) { ni.Other.RPCAddress = nonAscii }, true}, + {"Non-ASCII RPCAddress", func(ni *DefaultNodeInfo) { ni.Other.RPCAddress = nonASCII }, true}, {"Empty tab RPCAddress", func(ni *DefaultNodeInfo) { ni.Other.RPCAddress = emptyTab }, true}, {"Empty space RPCAddress", func(ni *DefaultNodeInfo) { ni.Other.RPCAddress = emptySpace }, true}, {"Empty RPCAddress", func(ni *DefaultNodeInfo) { ni.Other.RPCAddress = "" }, false}, diff --git a/p2p/peer_set_test.go b/p2p/peer_set_test.go index 4bacb07d0..c6f3fa5aa 100644 --- a/p2p/peer_set_test.go +++ b/p2p/peer_set_test.go @@ -101,10 +101,10 @@ func TestPeerSetAddRemoveMany(t *testing.T) { for i := 0; i < N; i++ { peer := newMockPeer(net.IP{127, 0, 0, byte(i)}) if err := peerSet.Add(peer); err != nil { - t.Errorf("Failed to add new peer") + t.Errorf("failed to add new peer") } if peerSet.Size() != i+1 { - t.Errorf("Failed to add new peer and increment size") + t.Errorf("failed to add new peer and increment size") } peers = append(peers, peer) } @@ -113,10 +113,10 @@ func TestPeerSetAddRemoveMany(t *testing.T) { removed := peerSet.Remove(peer) assert.True(t, removed) if peerSet.Has(peer.ID()) { - t.Errorf("Failed to remove peer") + t.Errorf("failed to remove peer") } if peerSet.Size() != len(peers)-i-1 { - t.Errorf("Failed to remove peer and decrement size") + t.Errorf("failed to remove peer and decrement size") } } } diff --git a/p2p/pex/pex_reactor.go b/p2p/pex/pex_reactor.go index 46d09d0cb..3235e4e4b 100644 --- a/p2p/pex/pex_reactor.go +++ b/p2p/pex/pex_reactor.go @@ -145,7 +145,7 @@ func (r *PEXReactor) OnStart() error { if err != nil { return err } else if numOnline == 0 && r.book.Empty() { - return errors.New("Address book is empty and couldn't resolve any seed nodes") + return errors.New("address book is empty and couldn't resolve any seed nodes") } r.seedAddrs = seedAddrs @@ -745,7 +745,7 @@ func RegisterPexMessage(cdc *amino.Codec) { func decodeMsg(bz []byte) (msg PexMessage, err error) { if len(bz) > maxMsgSize { - return msg, fmt.Errorf("Msg exceeds max size (%d > %d)", len(bz), maxMsgSize) + return msg, fmt.Errorf("msg exceeds max size (%d > %d)", len(bz), maxMsgSize) } err = cdc.UnmarshalBinaryBare(bz, &msg) return diff --git a/p2p/switch_test.go b/p2p/switch_test.go index bbbf6461e..ef6fa6f34 100644 --- a/p2p/switch_test.go +++ b/p2p/switch_test.go @@ -121,10 +121,10 @@ func TestSwitches(t *testing.T) { defer s2.Stop() if s1.Peers().Size() != 1 { - t.Errorf("Expected exactly 1 peer in s1, got %v", s1.Peers().Size()) + t.Errorf("expected exactly 1 peer in s1, got %v", s1.Peers().Size()) } if s2.Peers().Size() != 1 { - t.Errorf("Expected exactly 1 peer in s2, got %v", s2.Peers().Size()) + t.Errorf("expected exactly 1 peer in s2, got %v", s2.Peers().Size()) } // Lets send some messages diff --git a/p2p/test_util.go b/p2p/test_util.go index 95ed31949..e0a28fbbb 100644 --- a/p2p/test_util.go +++ b/p2p/test_util.go @@ -71,7 +71,7 @@ func CreateRoutableAddr() (addr string, netAddr *NetAddress) { //------------------------------------------------------------------ // Connects switches via arbitrary net.Conn. Used for testing. -const TEST_HOST = "localhost" +const TestHost = "localhost" // MakeConnectedSwitches returns n switches, connected according to the connect func. // If connect==Connect2Switches, the switches will be fully connected. @@ -84,7 +84,7 @@ func MakeConnectedSwitches(cfg *config.P2PConfig, ) []*Switch { switches := make([]*Switch, n) for i := 0; i < n; i++ { - switches[i] = MakeSwitch(cfg, i, TEST_HOST, "123.123.123", initSwitch) + switches[i] = MakeSwitch(cfg, i, TestHost, "123.123.123", initSwitch) } if err := StartSwitches(switches); err != nil { diff --git a/p2p/transport.go b/p2p/transport.go index 95c646ac0..89d63da7b 100644 --- a/p2p/transport.go +++ b/p2p/transport.go @@ -87,7 +87,7 @@ func ConnDuplicateIPFilter() ConnFilterFunc { if cs.HasIP(ip) { return ErrRejected{ conn: c, - err: fmt.Errorf("IP<%v> already connected", ip), + err: fmt.Errorf("ip<%v> already connected", ip), isDuplicate: true, } } diff --git a/p2p/transport_test.go b/p2p/transport_test.go index 7580f0259..dd0457fb5 100644 --- a/p2p/transport_test.go +++ b/p2p/transport_test.go @@ -237,7 +237,7 @@ func TestTransportMultiplexAcceptNonBlocking(t *testing.T) { // Fast peer connected. case <-time.After(50 * time.Millisecond): // We error if the fast peer didn't succeed. - errc <- fmt.Errorf("Fast peer timed out") + errc <- fmt.Errorf("fast peer timed out") } sc, err := upgradeSecretConn(c, 20*time.Millisecond, ed25519.GenPrivKey()) @@ -592,7 +592,7 @@ func (a *testTransportAddr) String() string { return "test.local:1234" } type testTransportConn struct{} func (c *testTransportConn) Close() error { - return fmt.Errorf("Close() not implemented") + return fmt.Errorf("close() not implemented") } func (c *testTransportConn) LocalAddr() net.Addr { @@ -604,21 +604,21 @@ func (c *testTransportConn) RemoteAddr() net.Addr { } func (c *testTransportConn) Read(_ []byte) (int, error) { - return -1, fmt.Errorf("Read() not implemented") + return -1, fmt.Errorf("read() not implemented") } func (c *testTransportConn) SetDeadline(_ time.Time) error { - return fmt.Errorf("SetDeadline() not implemented") + return fmt.Errorf("setDeadline() not implemented") } func (c *testTransportConn) SetReadDeadline(_ time.Time) error { - return fmt.Errorf("SetReadDeadline() not implemented") + return fmt.Errorf("setReadDeadline() not implemented") } func (c *testTransportConn) SetWriteDeadline(_ time.Time) error { - return fmt.Errorf("SetWriteDeadline() not implemented") + return fmt.Errorf("setWriteDeadline() not implemented") } func (c *testTransportConn) Write(_ []byte) (int, error) { - return -1, fmt.Errorf("Write() not implemented") + return -1, fmt.Errorf("write() not implemented") } diff --git a/p2p/trust/store_test.go b/p2p/trust/store_test.go index d6498d823..08a77bcdb 100644 --- a/p2p/trust/store_test.go +++ b/p2p/trust/store_test.go @@ -141,7 +141,7 @@ func TestTrustMetricStorePeerScore(t *testing.T) { second := tm.TrustScore() if second > first { - t.Errorf("A greater number of bad events should lower the trust score") + t.Errorf("a greater number of bad events should lower the trust score") } store.PeerDisconnected(key) diff --git a/p2p/upnp/probe.go b/p2p/upnp/probe.go index 9adf72c6b..14e24f5cd 100644 --- a/p2p/upnp/probe.go +++ b/p2p/upnp/probe.go @@ -16,26 +16,26 @@ type UPNPCapabilities struct { func makeUPNPListener(intPort int, extPort int, logger log.Logger) (NAT, net.Listener, net.IP, error) { nat, err := Discover() if err != nil { - return nil, nil, nil, fmt.Errorf("NAT upnp could not be discovered: %v", err) + return nil, nil, nil, fmt.Errorf("nat upnp could not be discovered: %v", err) } logger.Info(fmt.Sprintf("ourIP: %v", nat.(*upnpNAT).ourIP)) ext, err := nat.GetExternalAddress() if err != nil { - return nat, nil, nil, fmt.Errorf("External address error: %v", err) + return nat, nil, nil, fmt.Errorf("external address error: %v", err) } logger.Info(fmt.Sprintf("External address: %v", ext)) port, err := nat.AddPortMapping("tcp", extPort, intPort, "Tendermint UPnP Probe", 0) if err != nil { - return nat, nil, ext, fmt.Errorf("Port mapping error: %v", err) + return nat, nil, ext, fmt.Errorf("port mapping error: %v", err) } logger.Info(fmt.Sprintf("Port mapping mapped: %v", port)) // also run the listener, open for all remote addresses. listener, err := net.Listen("tcp", fmt.Sprintf(":%v", intPort)) if err != nil { - return nat, nil, ext, fmt.Errorf("Error establishing listener: %v", err) + return nat, nil, ext, fmt.Errorf("error establishing listener: %v", err) } return nat, listener, ext, nil } diff --git a/p2p/upnp/upnp.go b/p2p/upnp/upnp.go index cb3bd7482..fc395bd75 100644 --- a/p2p/upnp/upnp.go +++ b/p2p/upnp/upnp.go @@ -109,7 +109,7 @@ func Discover() (nat NAT, err error) { return } } - err = errors.New("UPnP port discovery failed") + err = errors.New("upnp port discovery failed") return nat, err } @@ -219,17 +219,17 @@ func getServiceURL(rootURL string) (url, urnDomain string, err error) { } a := &root.Device if !strings.Contains(a.DeviceType, "InternetGatewayDevice:1") { - err = errors.New("No InternetGatewayDevice") + err = errors.New("no InternetGatewayDevice") return } b := getChildDevice(a, "WANDevice:1") if b == nil { - err = errors.New("No WANDevice") + err = errors.New("no WANDevice") return } c := getChildDevice(b, "WANConnectionDevice:1") if c == nil { - err = errors.New("No WANConnectionDevice") + err = errors.New("no WANConnectionDevice") return } d := getChildService(c, "WANIPConnection:1") @@ -239,7 +239,7 @@ func getServiceURL(rootURL string) (url, urnDomain string, err error) { d = getChildService(b, "WANIPConnection:1") if d == nil { - err = errors.New("No WANIPConnection") + err = errors.New("no WANIPConnection") return } } @@ -287,7 +287,7 @@ func soapRequest(url, function, message, domain string) (r *http.Response, err e if r.StatusCode >= 400 { // log.Stderr(function, r.StatusCode) - err = errors.New("Error " + strconv.Itoa(r.StatusCode) + " for " + function) + err = errors.New("error " + strconv.Itoa(r.StatusCode) + " for " + function) r = nil return } @@ -295,7 +295,7 @@ func soapRequest(url, function, message, domain string) (r *http.Response, err e } type statusInfo struct { - externalIpAddress string + externalIPAddress string } func (n *upnpNAT) getExternalIPAddress() (info statusInfo, err error) { @@ -338,9 +338,9 @@ func (n *upnpNAT) GetExternalAddress() (addr net.IP, err error) { if err != nil { return } - addr = net.ParseIP(info.externalIpAddress) + addr = net.ParseIP(info.externalIPAddress) if addr == nil { - err = fmt.Errorf("Failed to parse IP: %v", info.externalIpAddress) + err = fmt.Errorf("failed to parse IP: %v", info.externalIPAddress) } return } diff --git a/privval/codec.go b/privval/codec.go index 637039b77..9edcc7741 100644 --- a/privval/codec.go +++ b/privval/codec.go @@ -2,12 +2,12 @@ package privval import ( amino "github.com/tendermint/go-amino" - cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino" + cryptoamino "github.com/tendermint/tendermint/crypto/encoding/amino" ) var cdc = amino.NewCodec() func init() { - cryptoAmino.RegisterAmino(cdc) + cryptoamino.RegisterAmino(cdc) RegisterRemoteSignerMsg(cdc) } diff --git a/privval/signer_listener_endpoint_test.go b/privval/signer_listener_endpoint_test.go index 7058ff8b8..7422776c0 100644 --- a/privval/signer_listener_endpoint_test.go +++ b/privval/signer_listener_endpoint_test.go @@ -66,9 +66,9 @@ func TestSignerRemoteRetryTCPOnly(t *testing.T) { SignerDialerEndpointTimeoutReadWrite(time.Millisecond)(dialerEndpoint) SignerDialerEndpointConnRetries(retries)(dialerEndpoint) - chainId := cmn.RandStr(12) + chainID := cmn.RandStr(12) mockPV := types.NewMockPV() - signerServer := NewSignerServer(dialerEndpoint, chainId, mockPV) + signerServer := NewSignerServer(dialerEndpoint, chainID, mockPV) err = signerServer.Start() require.NoError(t, err) diff --git a/proxy/app_conn_test.go b/proxy/app_conn_test.go index 2004b0b89..a3ddce22a 100644 --- a/proxy/app_conn_test.go +++ b/proxy/app_conn_test.go @@ -145,7 +145,7 @@ func TestInfo(t *testing.T) { resInfo, err := proxy.InfoSync(RequestInfo) if err != nil { - t.Errorf("Unexpected error: %v", err) + t.Errorf("unexpected error: %v", err) } if resInfo.Data != "{\"size\":0}" { t.Error("Expected ResponseInfo with one element '{\"size\":0}' but got something else") diff --git a/rpc/core/blocks.go b/rpc/core/blocks.go index 4e2331478..1a7ccd53e 100644 --- a/rpc/core/blocks.go +++ b/rpc/core/blocks.go @@ -138,10 +138,10 @@ func getHeight(currentHeight int64, heightPtr *int64) (int64, error) { if heightPtr != nil { height := *heightPtr if height <= 0 { - return 0, fmt.Errorf("Height must be greater than 0") + return 0, fmt.Errorf("height must be greater than 0") } if height > currentHeight { - return 0, fmt.Errorf("Height must be less than or equal to the current blockchain height") + return 0, fmt.Errorf("height must be less than or equal to the current blockchain height") } return height, nil } diff --git a/rpc/core/mempool.go b/rpc/core/mempool.go index 64915e2de..03123d057 100644 --- a/rpc/core/mempool.go +++ b/rpc/core/mempool.go @@ -80,7 +80,7 @@ func BroadcastTxCommit(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadc }, mempl.TxInfo{}) if err != nil { logger.Error("Error on broadcastTxCommit", "err", err) - return nil, fmt.Errorf("Error on broadcastTxCommit: %v", err) + return nil, fmt.Errorf("error on broadcastTxCommit: %v", err) } checkTxResMsg := <-checkTxResCh checkTxRes := checkTxResMsg.GetCheckTx() @@ -117,7 +117,7 @@ func BroadcastTxCommit(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadc Hash: tx.Hash(), }, err case <-time.After(config.TimeoutBroadcastTxCommit): - err = errors.New("Timed out waiting for tx to be included in a block") + err = errors.New("timed out waiting for tx to be included in a block") logger.Error("Error on broadcastTxCommit", "err", err) return &ctypes.ResultBroadcastTxCommit{ CheckTx: *checkTxRes, diff --git a/rpc/core/net.go b/rpc/core/net.go index e53b53ba8..ddab08a4d 100644 --- a/rpc/core/net.go +++ b/rpc/core/net.go @@ -41,7 +41,7 @@ func NetInfo(ctx *rpctypes.Context) (*ctypes.ResultNetInfo, error) { // UnsafeDialSeeds dials the given seeds (comma-separated id@IP:PORT). func UnsafeDialSeeds(ctx *rpctypes.Context, seeds []string) (*ctypes.ResultDialSeeds, error) { if len(seeds) == 0 { - return &ctypes.ResultDialSeeds{}, errors.New("No seeds provided") + return &ctypes.ResultDialSeeds{}, errors.New("no seeds provided") } logger.Info("DialSeeds", "seeds", seeds) if err := p2pPeers.DialPeersAsync(seeds); err != nil { @@ -54,7 +54,7 @@ func UnsafeDialSeeds(ctx *rpctypes.Context, seeds []string) (*ctypes.ResultDialS // optionally making them persistent. func UnsafeDialPeers(ctx *rpctypes.Context, peers []string, persistent bool) (*ctypes.ResultDialPeers, error) { if len(peers) == 0 { - return &ctypes.ResultDialPeers{}, errors.New("No peers provided") + return &ctypes.ResultDialPeers{}, errors.New("no peers provided") } logger.Info("DialPeers", "peers", peers, "persistent", persistent) if persistent { diff --git a/rpc/core/tx.go b/rpc/core/tx.go index 122e23cec..cdc37f017 100644 --- a/rpc/core/tx.go +++ b/rpc/core/tx.go @@ -20,7 +20,7 @@ func Tx(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error // if index is disabled, return error if _, ok := txIndexer.(*null.TxIndex); ok { - return nil, fmt.Errorf("Transaction indexing is disabled") + return nil, fmt.Errorf("transaction indexing is disabled") } r, err := txIndexer.Get(hash) @@ -29,7 +29,7 @@ func Tx(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error } if r == nil { - return nil, fmt.Errorf("Tx (%X) not found", hash) + return nil, fmt.Errorf("tx (%X) not found", hash) } height := r.Height @@ -57,7 +57,7 @@ func Tx(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error func TxSearch(ctx *rpctypes.Context, query string, prove bool, page, perPage int) (*ctypes.ResultTxSearch, error) { // if index is disabled, return error if _, ok := txIndexer.(*null.TxIndex); ok { - return nil, fmt.Errorf("Transaction indexing is disabled") + return nil, fmt.Errorf("transaction indexing is disabled") } q, err := tmquery.New(query) diff --git a/rpc/core/types/codec.go b/rpc/core/types/codec.go index 2180b5a5a..82543ff6e 100644 --- a/rpc/core/types/codec.go +++ b/rpc/core/types/codec.go @@ -1,4 +1,4 @@ -package core_types +package coretypes import ( amino "github.com/tendermint/go-amino" diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index 72b60b92a..b3a89b34f 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -1,4 +1,4 @@ -package core_types +package coretypes import ( "encoding/json" diff --git a/rpc/core/types/responses_test.go b/rpc/core/types/responses_test.go index 796299d33..d6a59e96b 100644 --- a/rpc/core/types/responses_test.go +++ b/rpc/core/types/responses_test.go @@ -1,4 +1,4 @@ -package core_types +package coretypes import ( "testing" diff --git a/rpc/grpc/api.go b/rpc/grpc/api.go index 741d63aff..8216c192e 100644 --- a/rpc/grpc/api.go +++ b/rpc/grpc/api.go @@ -1,4 +1,4 @@ -package core_grpc +package coregrpc import ( "context" diff --git a/rpc/grpc/client_server.go b/rpc/grpc/client_server.go index d02120e10..5967b8ac5 100644 --- a/rpc/grpc/client_server.go +++ b/rpc/grpc/client_server.go @@ -1,4 +1,4 @@ -package core_grpc +package coregrpc import ( "net" diff --git a/rpc/grpc/grpc_test.go b/rpc/grpc/grpc_test.go index d9ef605b2..f7bfdc9f4 100644 --- a/rpc/grpc/grpc_test.go +++ b/rpc/grpc/grpc_test.go @@ -1,4 +1,4 @@ -package core_grpc_test +package coregrpc_test import ( "context" diff --git a/rpc/grpc/types.pb.go b/rpc/grpc/types.pb.go index 86552a4b5..fcd913497 100644 --- a/rpc/grpc/types.pb.go +++ b/rpc/grpc/types.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: rpc/grpc/types.proto -package core_grpc +package coregrpc import ( bytes "bytes" diff --git a/rpc/grpc/typespb_test.go b/rpc/grpc/typespb_test.go index 09b2d666b..d0a6c8654 100644 --- a/rpc/grpc/typespb_test.go +++ b/rpc/grpc/typespb_test.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: rpc/grpc/types.proto -package core_grpc +package coregrpc import ( fmt "fmt" diff --git a/rpc/lib/client/integration_test.go b/rpc/lib/client/integration_test.go index 93a32388f..91d4296d1 100644 --- a/rpc/lib/client/integration_test.go +++ b/rpc/lib/client/integration_test.go @@ -58,7 +58,7 @@ func TestWSClientReconnectWithJitter(t *testing.T) { seenMap := make(map[string]int) for i, match := range matches { if origIndex, seen := seenMap[string(match)]; seen { - t.Errorf("Match #%d (%q) was seen originally at log entry #%d", i, match, origIndex) + t.Errorf("match #%d (%q) was seen originally at log entry #%d", i, match, origIndex) } else { seenMap[string(match)] = i } diff --git a/rpc/lib/server/http_params.go b/rpc/lib/server/http_params.go index 8ade41c79..075afb666 100644 --- a/rpc/lib/server/http_params.go +++ b/rpc/lib/server/http_params.go @@ -15,11 +15,11 @@ var ( dotAtom = atom + `(?:\.` + atom + `)*` domain = `[A-Z0-9.-]+\.[A-Z]{2,4}` - RE_INT = regexp.MustCompile(`^-?[0-9]+$`) - RE_HEX = regexp.MustCompile(`^(?i)[a-f0-9]+$`) - RE_EMAIL = regexp.MustCompile(`^(?i)(` + dotAtom + `)@(` + dotAtom + `)$`) - RE_ADDRESS = regexp.MustCompile(`^(?i)[a-z0-9]{25,34}$`) - RE_HOST = regexp.MustCompile(`^(?i)(` + domain + `)$`) + ReInt = regexp.MustCompile(`^-?[0-9]+$`) + ReHex = regexp.MustCompile(`^(?i)[a-f0-9]+$`) + ReEmail = regexp.MustCompile(`^(?i)(` + dotAtom + `)@(` + dotAtom + `)$`) + ReAddress = regexp.MustCompile(`^(?i)[a-z0-9]{25,34}$`) + ReHost = regexp.MustCompile(`^(?i)(` + domain + `)$`) //RE_ID12 = regexp.MustCompile(`^[a-zA-Z0-9]{12}$`) ) diff --git a/rpc/lib/server/http_uri_handler.go b/rpc/lib/server/http_uri_handler.go index 6c68ba3ac..4ac33dcc1 100644 --- a/rpc/lib/server/http_uri_handler.go +++ b/rpc/lib/server/http_uri_handler.go @@ -130,7 +130,7 @@ func nonJSONStringToArg(cdc *amino.Codec, rt reflect.Type, arg string) (reflect. // NOTE: rt.Kind() isn't a pointer. func _nonJSONStringToArg(cdc *amino.Codec, rt reflect.Type, arg string) (reflect.Value, bool, error) { - isIntString := RE_INT.Match([]byte(arg)) + isIntString := ReInt.Match([]byte(arg)) isQuotedString := strings.HasPrefix(arg, `"`) && strings.HasSuffix(arg, `"`) isHexString := strings.HasPrefix(strings.ToLower(arg), "0x") diff --git a/rpc/lib/types/types.go b/rpc/lib/types/types.go index 0ce9890e5..923dc8c46 100644 --- a/rpc/lib/types/types.go +++ b/rpc/lib/types/types.go @@ -43,7 +43,7 @@ func idFromInterface(idInterface interface{}) (jsonrpcid, error) { return JSONRPCIntID(int(id)), nil default: typ := reflect.TypeOf(id) - return nil, fmt.Errorf("JSON-RPC ID (%v) is of unknown type (%v)", id, typ) + return nil, fmt.Errorf("json-rpc ID (%v) is of unknown type (%v)", id, typ) } } diff --git a/rpc/lib/types/types_test.go b/rpc/lib/types/types_test.go index e2a98a18f..4597b0481 100644 --- a/rpc/lib/types/types_test.go +++ b/rpc/lib/types/types_test.go @@ -41,9 +41,9 @@ func TestResponses(t *testing.T) { s := fmt.Sprintf(`{"jsonrpc":"2.0","id":%v,"result":{"Value":"hello"}}`, tt.expected) assert.Equal(s, string(b)) - d := RPCParseError(errors.New("Hello world")) + d := RPCParseError(errors.New("hello world")) e, _ := json.Marshal(d) - f := `{"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error. Invalid JSON","data":"Hello world"}}` + f := `{"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error. Invalid JSON","data":"hello world"}}` assert.Equal(f, string(e)) g := RPCMethodNotFoundError(jsonid) diff --git a/scripts/json2wal/main.go b/scripts/json2wal/main.go index dd3e29d0f..db67dea9f 100644 --- a/scripts/json2wal/main.go +++ b/scripts/json2wal/main.go @@ -52,19 +52,19 @@ func main() { dec := cs.NewWALEncoder(walFile) for { - msgJson, _, err := br.ReadLine() + msgJSON, _, err := br.ReadLine() if err == io.EOF { break } else if err != nil { panic(fmt.Errorf("failed to read file: %v", err)) } // ignore the ENDHEIGHT in json.File - if strings.HasPrefix(string(msgJson), "ENDHEIGHT") { + if strings.HasPrefix(string(msgJSON), "ENDHEIGHT") { continue } var msg cs.TimedWALMessage - err = cdc.UnmarshalJSON(msgJson, &msg) + err = cdc.UnmarshalJSON(msgJSON, &msg) if err != nil { panic(fmt.Errorf("failed to unmarshal json: %v", err)) } diff --git a/scripts/privValUpgrade.go b/scripts/privValUpgrade.go index 500ef599a..1882a3663 100644 --- a/scripts/privValUpgrade.go +++ b/scripts/privValUpgrade.go @@ -33,7 +33,7 @@ func main() { func loadAndUpgrade(oldPVPath, newPVKeyPath, newPVStatePath string) error { oldPV, err := privval.LoadOldFilePV(oldPVPath) if err != nil { - return fmt.Errorf("Error reading OldPrivValidator from %v: %v\n", oldPVPath, err) + return fmt.Errorf("error reading OldPrivValidator from %v: %v", oldPVPath, err) } logger.Info("Upgrading PrivValidator file", "old", oldPVPath, diff --git a/state/codec.go b/state/codec.go index f7a611294..abbec6e39 100644 --- a/state/codec.go +++ b/state/codec.go @@ -2,11 +2,11 @@ package state import ( amino "github.com/tendermint/go-amino" - cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino" + cryptoamino "github.com/tendermint/tendermint/crypto/encoding/amino" ) var cdc = amino.NewCodec() func init() { - cryptoAmino.RegisterAmino(cdc) + cryptoamino.RegisterAmino(cdc) } diff --git a/state/execution.go b/state/execution.go index 7214338f7..8a3af7362 100644 --- a/state/execution.go +++ b/state/execution.go @@ -146,7 +146,7 @@ func (blockExec *BlockExecutor) ApplyBlock(state State, blockID types.BlockID, b abciValUpdates := abciResponses.EndBlock.ValidatorUpdates err = validateValidatorUpdates(abciValUpdates, state.ConsensusParams.Validator) if err != nil { - return state, fmt.Errorf("Error in validator updates: %v", err) + return state, fmt.Errorf("error in validator updates: %v", err) } validatorUpdates, err := types.PB2TM.ValidatorUpdates(abciValUpdates) if err != nil { @@ -159,13 +159,13 @@ func (blockExec *BlockExecutor) ApplyBlock(state State, blockID types.BlockID, b // Update the state with the block and responses. state, err = updateState(state, blockID, &block.Header, abciResponses, validatorUpdates) if err != nil { - return state, fmt.Errorf("Commit failed for application: %v", err) + return state, fmt.Errorf("commit failed for application: %v", err) } // Lock mempool, commit app state, update mempoool. appHash, err := blockExec.Commit(state, block, abciResponses.DeliverTxs) if err != nil { - return state, fmt.Errorf("Commit failed for application: %v", err) + return state, fmt.Errorf("commit failed for application: %v", err) } // Update evpool with the block and state. @@ -368,7 +368,7 @@ func validateValidatorUpdates(abciUpdates []abci.ValidatorUpdate, params types.ValidatorParams) error { for _, valUpdate := range abciUpdates { if valUpdate.GetPower() < 0 { - return fmt.Errorf("Voting power can't be negative %v", valUpdate) + return fmt.Errorf("voting power can't be negative %v", valUpdate) } else if valUpdate.GetPower() == 0 { // continue, since this is deleting the validator, and thus there is no // pubkey to check @@ -378,7 +378,7 @@ func validateValidatorUpdates(abciUpdates []abci.ValidatorUpdate, // Check if validator's pubkey matches an ABCI type in the consensus params thisKeyType := valUpdate.PubKey.Type if !params.IsValidPubkeyType(thisKeyType) { - return fmt.Errorf("Validator %v is using pubkey %s, which is unsupported for consensus", + return fmt.Errorf("validator %v is using pubkey %s, which is unsupported for consensus", valUpdate, thisKeyType) } } @@ -403,7 +403,7 @@ func updateState( if len(validatorUpdates) > 0 { err := nValSet.UpdateWithChangeSet(validatorUpdates) if err != nil { - return state, fmt.Errorf("Error changing validator set: %v", err) + return state, fmt.Errorf("error changing validator set: %v", err) } // Change results from this height but only applies to the next next height. lastHeightValsChanged = header.Height + 1 + 1 @@ -420,7 +420,7 @@ func updateState( nextParams = state.ConsensusParams.Update(abciResponses.EndBlock.ConsensusParamUpdates) err := nextParams.Validate() if err != nil { - return state, fmt.Errorf("Error updating consensus params: %v", err) + return state, fmt.Errorf("error updating consensus params: %v", err) } // Change results from this height but only applies to the next height. lastHeightParamsChanged = header.Height + 1 diff --git a/state/state.go b/state/state.go index 0aec9ed6b..8cdff90e4 100644 --- a/state/state.go +++ b/state/state.go @@ -198,11 +198,11 @@ func MakeGenesisStateFromFile(genDocFile string) (State, error) { func MakeGenesisDocFromFile(genDocFile string) (*types.GenesisDoc, error) { genDocJSON, err := ioutil.ReadFile(genDocFile) if err != nil { - return nil, fmt.Errorf("Couldn't read GenesisDoc file: %v", err) + return nil, fmt.Errorf("couldn't read GenesisDoc file: %v", err) } genDoc, err := types.GenesisDocFromJSON(genDocJSON) if err != nil { - return nil, fmt.Errorf("Error reading GenesisDoc: %v", err) + return nil, fmt.Errorf("error reading GenesisDoc: %v", err) } return genDoc, nil } @@ -211,7 +211,7 @@ func MakeGenesisDocFromFile(genDocFile string) (*types.GenesisDoc, error) { func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) { err := genDoc.ValidateAndComplete() if err != nil { - return State{}, fmt.Errorf("Error in genesis file: %v", err) + return State{}, fmt.Errorf("error in genesis file: %v", err) } var validatorSet, nextValidatorSet *types.ValidatorSet diff --git a/state/txindex/indexer.go b/state/txindex/indexer.go index ab509f965..c66f4322c 100644 --- a/state/txindex/indexer.go +++ b/state/txindex/indexer.go @@ -55,4 +55,4 @@ func (b *Batch) Size() int { // Errors // ErrorEmptyHash indicates empty hash -var ErrorEmptyHash = errors.New("Transaction hash cannot be empty") +var ErrorEmptyHash = errors.New("transaction hash cannot be empty") diff --git a/state/txindex/kv/kv.go b/state/txindex/kv/kv.go index e6f0e67bf..f7dce3348 100644 --- a/state/txindex/kv/kv.go +++ b/state/txindex/kv/kv.go @@ -70,7 +70,7 @@ func (txi *TxIndex) Get(hash []byte) (*types.TxResult, error) { txResult := new(types.TxResult) err := cdc.UnmarshalBinaryBare(rawBytes, &txResult) if err != nil { - return nil, fmt.Errorf("Error reading TxResult: %v", err) + return nil, fmt.Errorf("error reading TxResult: %v", err) } return txResult, nil @@ -174,7 +174,7 @@ func (txi *TxIndex) Search(q *query.Query) ([]*types.TxResult, error) { } // if there is a hash condition, return the result immediately - hash, err, ok := lookForHash(conditions) + hash, ok, err := lookForHash(conditions) if err != nil { return nil, errors.Wrap(err, "error during searching for a hash in the query") } else if ok { @@ -258,11 +258,11 @@ func (txi *TxIndex) Search(q *query.Query) ([]*types.TxResult, error) { return results, nil } -func lookForHash(conditions []query.Condition) (hash []byte, err error, ok bool) { +func lookForHash(conditions []query.Condition) (hash []byte, ok bool, err error) { for _, c := range conditions { if c.Tag == types.TxHashKey { decoded, err := hex.DecodeString(c.Operand.(string)) - return decoded, err, true + return decoded, true, err } } return diff --git a/state/txindex/null/null.go b/state/txindex/null/null.go index f85de2e6f..ae496a851 100644 --- a/state/txindex/null/null.go +++ b/state/txindex/null/null.go @@ -15,7 +15,7 @@ type TxIndex struct{} // Get on a TxIndex is disabled and panics when invoked. func (txi *TxIndex) Get(hash []byte) (*types.TxResult, error) { - return nil, errors.New(`Indexing is disabled (set 'tx_index = "kv"' in config)`) + return nil, errors.New(`indexing is disabled (set 'tx_index = "kv"' in config)`) } // AddBatch is a noop and always returns nil. diff --git a/state/validation.go b/state/validation.go index d44de002a..409059901 100644 --- a/state/validation.go +++ b/state/validation.go @@ -21,19 +21,19 @@ func validateBlock(evidencePool EvidencePool, stateDB dbm.DB, state State, block // Validate basic info. if block.Version != state.Version.Consensus { - return fmt.Errorf("Wrong Block.Header.Version. Expected %v, got %v", + return fmt.Errorf("wrong Block.Header.Version. Expected %v, got %v", state.Version.Consensus, block.Version, ) } if block.ChainID != state.ChainID { - return fmt.Errorf("Wrong Block.Header.ChainID. Expected %v, got %v", + return fmt.Errorf("wrong Block.Header.ChainID. Expected %v, got %v", state.ChainID, block.ChainID, ) } if block.Height != state.LastBlockHeight+1 { - return fmt.Errorf("Wrong Block.Header.Height. Expected %v, got %v", + return fmt.Errorf("wrong Block.Header.Height. Expected %v, got %v", state.LastBlockHeight+1, block.Height, ) @@ -41,7 +41,7 @@ func validateBlock(evidencePool EvidencePool, stateDB dbm.DB, state State, block // Validate prev block info. if !block.LastBlockID.Equals(state.LastBlockID) { - return fmt.Errorf("Wrong Block.Header.LastBlockID. Expected %v, got %v", + return fmt.Errorf("wrong Block.Header.LastBlockID. Expected %v, got %v", state.LastBlockID, block.LastBlockID, ) @@ -49,31 +49,31 @@ func validateBlock(evidencePool EvidencePool, stateDB dbm.DB, state State, block // Validate app info if !bytes.Equal(block.AppHash, state.AppHash) { - return fmt.Errorf("Wrong Block.Header.AppHash. Expected %X, got %v", + return fmt.Errorf("wrong Block.Header.AppHash. Expected %X, got %v", state.AppHash, block.AppHash, ) } if !bytes.Equal(block.ConsensusHash, state.ConsensusParams.Hash()) { - return fmt.Errorf("Wrong Block.Header.ConsensusHash. Expected %X, got %v", + return fmt.Errorf("wrong Block.Header.ConsensusHash. Expected %X, got %v", state.ConsensusParams.Hash(), block.ConsensusHash, ) } if !bytes.Equal(block.LastResultsHash, state.LastResultsHash) { - return fmt.Errorf("Wrong Block.Header.LastResultsHash. Expected %X, got %v", + return fmt.Errorf("wrong Block.Header.LastResultsHash. Expected %X, got %v", state.LastResultsHash, block.LastResultsHash, ) } if !bytes.Equal(block.ValidatorsHash, state.Validators.Hash()) { - return fmt.Errorf("Wrong Block.Header.ValidatorsHash. Expected %X, got %v", + return fmt.Errorf("wrong Block.Header.ValidatorsHash. Expected %X, got %v", state.Validators.Hash(), block.ValidatorsHash, ) } if !bytes.Equal(block.NextValidatorsHash, state.NextValidators.Hash()) { - return fmt.Errorf("Wrong Block.Header.NextValidatorsHash. Expected %X, got %v", + return fmt.Errorf("wrong Block.Header.NextValidatorsHash. Expected %X, got %v", state.NextValidators.Hash(), block.NextValidatorsHash, ) @@ -82,7 +82,7 @@ func validateBlock(evidencePool EvidencePool, stateDB dbm.DB, state State, block // Validate block LastCommit. if block.Height == 1 { if len(block.LastCommit.Precommits) != 0 { - return errors.New("Block at height 1 can't have LastCommit precommits") + return errors.New("block at height 1 can't have LastCommit precommits") } } else { if len(block.LastCommit.Precommits) != state.LastValidators.Size() { @@ -98,7 +98,7 @@ func validateBlock(evidencePool EvidencePool, stateDB dbm.DB, state State, block // Validate block Time if block.Height > 1 { if !block.Time.After(state.LastBlockTime) { - return fmt.Errorf("Block time %v not greater than last block time %v", + return fmt.Errorf("block time %v not greater than last block time %v", block.Time, state.LastBlockTime, ) @@ -106,7 +106,7 @@ func validateBlock(evidencePool EvidencePool, stateDB dbm.DB, state State, block medianTime := MedianTime(block.LastCommit, state.LastValidators) if !block.Time.Equal(medianTime) { - return fmt.Errorf("Invalid block time. Expected %v, got %v", + return fmt.Errorf("invalid block time. Expected %v, got %v", medianTime, block.Time, ) @@ -114,7 +114,7 @@ func validateBlock(evidencePool EvidencePool, stateDB dbm.DB, state State, block } else if block.Height == 1 { genesisTime := state.LastBlockTime if !block.Time.Equal(genesisTime) { - return fmt.Errorf("Block time %v is not equal to genesis time %v", + return fmt.Errorf("block time %v is not equal to genesis time %v", block.Time, genesisTime, ) @@ -144,7 +144,7 @@ func validateBlock(evidencePool EvidencePool, stateDB dbm.DB, state State, block // a legit address and a known validator. if len(block.ProposerAddress) != crypto.AddressSize || !state.Validators.HasAddress(block.ProposerAddress) { - return fmt.Errorf("Block.Header.ProposerAddress, %X, is not a validator", + return fmt.Errorf("block.Header.ProposerAddress, %X, is not a validator", block.ProposerAddress, ) } @@ -163,7 +163,7 @@ func VerifyEvidence(stateDB dbm.DB, state State, evidence types.Evidence) error evidenceAge := height - evidence.Height() maxAge := state.ConsensusParams.Evidence.MaxAge if evidenceAge > maxAge { - return fmt.Errorf("Evidence from height %d is too old. Min height is %d", + return fmt.Errorf("evidence from height %d is too old. Min height is %d", evidence.Height(), height-maxAge) } @@ -183,7 +183,7 @@ func VerifyEvidence(stateDB dbm.DB, state State, evidence types.Evidence) error height, addr := ev.Height(), ev.Address() _, val := valset.GetByAddress(addr) if val == nil { - return fmt.Errorf("Address %X was not a validator at height %d", addr, height) + return fmt.Errorf("address %X was not a validator at height %d", addr, height) } if err := evidence.Verify(state.ChainID, val.PubKey); err != nil { diff --git a/tools/tm-monitor/mock/eventmeter.go b/tools/tm-monitor/mock/eventmeter.go index 7119c4399..e70137e6f 100644 --- a/tools/tm-monitor/mock/eventmeter.go +++ b/tools/tm-monitor/mock/eventmeter.go @@ -42,12 +42,12 @@ func (e *EventMeter) Call(callback string, args ...interface{}) { } } -type RpcClient struct { +type RPCClient struct { Stubs map[string]interface{} cdc *amino.Codec } -func (c *RpcClient) Call(method string, params map[string]interface{}, result interface{}) (interface{}, error) { +func (c *RPCClient) Call(method string, params map[string]interface{}, result interface{}) (interface{}, error) { s, ok := c.Stubs[method] if !ok { stdlog.Fatalf("Call to %s, but no stub is defined for it", method) @@ -60,10 +60,10 @@ func (c *RpcClient) Call(method string, params map[string]interface{}, result in return s, nil } -func (c *RpcClient) Codec() *amino.Codec { +func (c *RPCClient) Codec() *amino.Codec { return c.cdc } -func (c *RpcClient) SetCodec(cdc *amino.Codec) { +func (c *RPCClient) SetCodec(cdc *amino.Codec) { c.cdc = cdc } diff --git a/tools/tm-monitor/monitor/monitor.go b/tools/tm-monitor/monitor/monitor.go index 0353aa78e..9aed914a8 100644 --- a/tools/tm-monitor/monitor/monitor.go +++ b/tools/tm-monitor/monitor/monitor.go @@ -224,7 +224,7 @@ func (m *Monitor) updateNumValidatorLoop() { m.mtx.Lock() nodesCount := len(m.Nodes) m.mtx.Unlock() - if 0 == nodesCount { + if nodesCount == 0 { time.Sleep(m.numValidatorsUpdateInterval) continue } diff --git a/tools/tm-monitor/monitor/monitor_test.go b/tools/tm-monitor/monitor/monitor_test.go index e700e5298..e1318d146 100644 --- a/tools/tm-monitor/monitor/monitor_test.go +++ b/tools/tm-monitor/monitor/monitor_test.go @@ -67,9 +67,9 @@ func createValidatorNode(t *testing.T) (n *monitor.Node, emMock *mock.EventMeter } stubs["status"] = ctypes.ResultStatus{ValidatorInfo: ctypes.ValidatorInfo{PubKey: pubKey}} cdc := amino.NewCodec() - rpcClientMock := &mock.RpcClient{Stubs: stubs} + rpcClientMock := &mock.RPCClient{Stubs: stubs} rpcClientMock.SetCodec(cdc) - n = monitor.NewNodeWithEventMeterAndRpcClient("tcp://127.0.0.1:26657", emMock, rpcClientMock) + n = monitor.NewNodeWithEventMeterAndRPCClient("tcp://127.0.0.1:26657", emMock, rpcClientMock) return } diff --git a/tools/tm-monitor/monitor/node.go b/tools/tm-monitor/monitor/node.go index d776f5fa3..64209ed49 100644 --- a/tools/tm-monitor/monitor/node.go +++ b/tools/tm-monitor/monitor/node.go @@ -50,10 +50,10 @@ func NewNode(rpcAddr string, options ...func(*Node)) *Node { em := em.NewEventMeter(rpcAddr, UnmarshalEvent) rpcClient := rpc_client.NewURIClient(rpcAddr) // HTTP client by default rpcClient.SetCodec(cdc) - return NewNodeWithEventMeterAndRpcClient(rpcAddr, em, rpcClient, options...) + return NewNodeWithEventMeterAndRPCClient(rpcAddr, em, rpcClient, options...) } -func NewNodeWithEventMeterAndRpcClient( +func NewNodeWithEventMeterAndRPCClient( rpcAddr string, em eventMeter, rpcClient rpc_client.HTTPClient, @@ -184,7 +184,7 @@ func (n *Node) RestartEventMeterBackoff() error { attempt++ if attempt > maxRestarts { - return errors.New("Reached max restarts") + return errors.New("reached max restarts") } } } diff --git a/tools/tm-monitor/monitor/node_test.go b/tools/tm-monitor/monitor/node_test.go index a48d75b15..91e4da87a 100644 --- a/tools/tm-monitor/monitor/node_test.go +++ b/tools/tm-monitor/monitor/node_test.go @@ -85,10 +85,10 @@ func startValidatorNode(t *testing.T) (n *monitor.Node, emMock *mock.EventMeter) } stubs["status"] = ctypes.ResultStatus{ValidatorInfo: ctypes.ValidatorInfo{PubKey: pubKey}} cdc := amino.NewCodec() - rpcClientMock := &mock.RpcClient{Stubs: stubs} + rpcClientMock := &mock.RPCClient{Stubs: stubs} rpcClientMock.SetCodec(cdc) - n = monitor.NewNodeWithEventMeterAndRpcClient("tcp://127.0.0.1:26657", emMock, rpcClientMock) + n = monitor.NewNodeWithEventMeterAndRPCClient("tcp://127.0.0.1:26657", emMock, rpcClientMock) err := n.Start() require.Nil(t, err) diff --git a/types/block.go b/types/block.go index ef4a54504..50f33d4d7 100644 --- a/types/block.go +++ b/types/block.go @@ -52,19 +52,19 @@ func (b *Block) ValidateBasic() error { defer b.mtx.Unlock() if len(b.ChainID) > MaxChainIDLen { - return fmt.Errorf("ChainID is too long. Max is %d, got %d", MaxChainIDLen, len(b.ChainID)) + return fmt.Errorf("chainID is too long. Max is %d, got %d", MaxChainIDLen, len(b.ChainID)) } if b.Height < 0 { - return errors.New("Negative Header.Height") + return errors.New("negative Header.Height") } else if b.Height == 0 { - return errors.New("Zero Header.Height") + return errors.New("zero Header.Height") } // NOTE: Timestamp validation is subtle and handled elsewhere. if err := b.LastBlockID.ValidateBasic(); err != nil { - return fmt.Errorf("Wrong Header.LastBlockID: %v", err) + return fmt.Errorf("wrong Header.LastBlockID: %v", err) } // Validate the last commit and its hash. @@ -73,14 +73,14 @@ func (b *Block) ValidateBasic() error { return errors.New("nil LastCommit") } if err := b.LastCommit.ValidateBasic(); err != nil { - return fmt.Errorf("Wrong LastCommit") + return fmt.Errorf("wrong LastCommit") } } if err := ValidateHash(b.LastCommitHash); err != nil { - return fmt.Errorf("Wrong Header.LastCommitHash: %v", err) + return fmt.Errorf("wrong Header.LastCommitHash: %v", err) } if !bytes.Equal(b.LastCommitHash, b.LastCommit.Hash()) { - return fmt.Errorf("Wrong Header.LastCommitHash. Expected %v, got %v", + return fmt.Errorf("wrong Header.LastCommitHash. Expected %v, got %v", b.LastCommit.Hash(), b.LastCommitHash, ) @@ -90,11 +90,11 @@ func (b *Block) ValidateBasic() error { // NOTE: b.Data.Txs may be nil, but b.Data.Hash() // still works fine if err := ValidateHash(b.DataHash); err != nil { - return fmt.Errorf("Wrong Header.DataHash: %v", err) + return fmt.Errorf("wrong Header.DataHash: %v", err) } if !bytes.Equal(b.DataHash, b.Data.Hash()) { return fmt.Errorf( - "Wrong Header.DataHash. Expected %v, got %v", + "wrong Header.DataHash. Expected %v, got %v", b.Data.Hash(), b.DataHash, ) @@ -103,38 +103,38 @@ func (b *Block) ValidateBasic() error { // Basic validation of hashes related to application data. // Will validate fully against state in state#ValidateBlock. if err := ValidateHash(b.ValidatorsHash); err != nil { - return fmt.Errorf("Wrong Header.ValidatorsHash: %v", err) + return fmt.Errorf("wrong Header.ValidatorsHash: %v", err) } if err := ValidateHash(b.NextValidatorsHash); err != nil { - return fmt.Errorf("Wrong Header.NextValidatorsHash: %v", err) + return fmt.Errorf("wrong Header.NextValidatorsHash: %v", err) } if err := ValidateHash(b.ConsensusHash); err != nil { - return fmt.Errorf("Wrong Header.ConsensusHash: %v", err) + return fmt.Errorf("wrong Header.ConsensusHash: %v", err) } // NOTE: AppHash is arbitrary length if err := ValidateHash(b.LastResultsHash); err != nil { - return fmt.Errorf("Wrong Header.LastResultsHash: %v", err) + return fmt.Errorf("wrong Header.LastResultsHash: %v", err) } // Validate evidence and its hash. if err := ValidateHash(b.EvidenceHash); err != nil { - return fmt.Errorf("Wrong Header.EvidenceHash: %v", err) + return fmt.Errorf("wrong Header.EvidenceHash: %v", err) } // NOTE: b.Evidence.Evidence may be nil, but we're just looping. for i, ev := range b.Evidence.Evidence { if err := ev.ValidateBasic(); err != nil { - return fmt.Errorf("Invalid evidence (#%d): %v", i, err) + return fmt.Errorf("invalid evidence (#%d): %v", i, err) } } if !bytes.Equal(b.EvidenceHash, b.Evidence.Hash()) { - return fmt.Errorf("Wrong Header.EvidenceHash. Expected %v, got %v", + return fmt.Errorf("wrong Header.EvidenceHash. Expected %v, got %v", b.EvidenceHash, b.Evidence.Hash(), ) } if len(b.ProposerAddress) != crypto.AddressSize { - return fmt.Errorf("Expected len(Header.ProposerAddress) to be %d, got %d", + return fmt.Errorf("expected len(Header.ProposerAddress) to be %d, got %d", crypto.AddressSize, len(b.ProposerAddress)) } @@ -612,10 +612,10 @@ func (commit *Commit) IsCommit() bool { // Does not actually check the cryptographic signatures. func (commit *Commit) ValidateBasic() error { if commit.BlockID.IsZero() { - return errors.New("Commit cannot be for nil block") + return errors.New("commit cannot be for nil block") } if len(commit.Precommits) == 0 { - return errors.New("No precommits in commit") + return errors.New("no precommits in commit") } height, round := commit.Height(), commit.Round() @@ -627,17 +627,17 @@ func (commit *Commit) ValidateBasic() error { } // Ensure that all votes are precommits. if precommit.Type != PrecommitType { - return fmt.Errorf("Invalid commit vote. Expected precommit, got %v", + return fmt.Errorf("invalid commit vote. Expected precommit, got %v", precommit.Type) } // Ensure that all heights are the same. if precommit.Height != height { - return fmt.Errorf("Invalid commit precommit height. Expected %v, got %v", + return fmt.Errorf("invalid commit precommit height. Expected %v, got %v", height, precommit.Height) } // Ensure that all rounds are the same. if precommit.Round != round { - return fmt.Errorf("Invalid commit precommit round. Expected %v, got %v", + return fmt.Errorf("invalid commit precommit round. Expected %v, got %v", round, precommit.Round) } } @@ -698,27 +698,27 @@ func (sh SignedHeader) ValidateBasic(chainID string) error { // Make sure the header is consistent with the commit. if sh.Header == nil { - return errors.New("SignedHeader missing header.") + return errors.New("signedHeader missing header.") } if sh.Commit == nil { - return errors.New("SignedHeader missing commit (precommit votes).") + return errors.New("signedHeader missing commit (precommit votes).") } // Check ChainID. if sh.ChainID != chainID { - return fmt.Errorf("Header belongs to another chain '%s' not '%s'", + return fmt.Errorf("header belongs to another chain '%s' not '%s'", sh.ChainID, chainID) } // Check Height. if sh.Commit.Height() != sh.Height { - return fmt.Errorf("SignedHeader header and commit height mismatch: %v vs %v", + return fmt.Errorf("signedHeader header and commit height mismatch: %v vs %v", sh.Height, sh.Commit.Height()) } // Check Hash. hhash := sh.Hash() chash := sh.Commit.BlockID.Hash if !bytes.Equal(hhash, chash) { - return fmt.Errorf("SignedHeader commit signs block %X, header is block %X", + return fmt.Errorf("signedHeader commit signs block %X, header is block %X", chash, hhash) } // ValidateBasic on the Commit. @@ -854,10 +854,10 @@ func (blockID BlockID) Key() string { func (blockID BlockID) ValidateBasic() error { // Hash can be empty in case of POLBlockID in Proposal. if err := ValidateHash(blockID.Hash); err != nil { - return fmt.Errorf("Wrong Hash") + return fmt.Errorf("wrong Hash") } if err := blockID.PartsHeader.ValidateBasic(); err != nil { - return fmt.Errorf("Wrong PartsHeader: %v", err) + return fmt.Errorf("wrong PartsHeader: %v", err) } return nil } diff --git a/types/codec.go b/types/codec.go index 81a7bf76a..d77f2b29d 100644 --- a/types/codec.go +++ b/types/codec.go @@ -2,7 +2,7 @@ package types import ( amino "github.com/tendermint/go-amino" - cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino" + cryptoamino "github.com/tendermint/tendermint/crypto/encoding/amino" ) var cdc = amino.NewCodec() @@ -12,7 +12,7 @@ func init() { } func RegisterBlockAmino(cdc *amino.Codec) { - cryptoAmino.RegisterAmino(cdc) + cryptoamino.RegisterAmino(cdc) RegisterEvidences(cdc) } diff --git a/types/evidence.go b/types/evidence.go index a6c9d1bfe..63d6859e4 100644 --- a/types/evidence.go +++ b/types/evidence.go @@ -136,13 +136,13 @@ func (dve *DuplicateVoteEvidence) Verify(chainID string, pubKey crypto.PubKey) e if dve.VoteA.Height != dve.VoteB.Height || dve.VoteA.Round != dve.VoteB.Round || dve.VoteA.Type != dve.VoteB.Type { - return fmt.Errorf("DuplicateVoteEvidence Error: H/R/S does not match. Got %v and %v", dve.VoteA, dve.VoteB) + return fmt.Errorf("duplicateVoteEvidence Error: H/R/S does not match. Got %v and %v", dve.VoteA, dve.VoteB) } // Address must be the same if !bytes.Equal(dve.VoteA.ValidatorAddress, dve.VoteB.ValidatorAddress) { return fmt.Errorf( - "DuplicateVoteEvidence Error: Validator addresses do not match. Got %X and %X", + "duplicateVoteEvidence Error: Validator addresses do not match. Got %X and %X", dve.VoteA.ValidatorAddress, dve.VoteB.ValidatorAddress, ) @@ -151,7 +151,7 @@ func (dve *DuplicateVoteEvidence) Verify(chainID string, pubKey crypto.PubKey) e // Index must be the same if dve.VoteA.ValidatorIndex != dve.VoteB.ValidatorIndex { return fmt.Errorf( - "DuplicateVoteEvidence Error: Validator indices do not match. Got %d and %d", + "duplicateVoteEvidence Error: Validator indices do not match. Got %d and %d", dve.VoteA.ValidatorIndex, dve.VoteB.ValidatorIndex, ) @@ -160,7 +160,7 @@ func (dve *DuplicateVoteEvidence) Verify(chainID string, pubKey crypto.PubKey) e // BlockIDs must be different if dve.VoteA.BlockID.Equals(dve.VoteB.BlockID) { return fmt.Errorf( - "DuplicateVoteEvidence Error: BlockIDs are the same (%v) - not a real duplicate vote", + "duplicateVoteEvidence Error: BlockIDs are the same (%v) - not a real duplicate vote", dve.VoteA.BlockID, ) } @@ -168,16 +168,16 @@ func (dve *DuplicateVoteEvidence) Verify(chainID string, pubKey crypto.PubKey) e // pubkey must match address (this should already be true, sanity check) addr := dve.VoteA.ValidatorAddress if !bytes.Equal(pubKey.Address(), addr) { - return fmt.Errorf("DuplicateVoteEvidence FAILED SANITY CHECK - address (%X) doesn't match pubkey (%v - %X)", + return fmt.Errorf("duplicateVoteEvidence FAILED SANITY CHECK - address (%X) doesn't match pubkey (%v - %X)", addr, pubKey, pubKey.Address()) } // Signatures must be valid if !pubKey.VerifyBytes(dve.VoteA.SignBytes(chainID), dve.VoteA.Signature) { - return fmt.Errorf("DuplicateVoteEvidence Error verifying VoteA: %v", ErrVoteInvalidSignature) + return fmt.Errorf("duplicateVoteEvidence Error verifying VoteA: %v", ErrVoteInvalidSignature) } if !pubKey.VerifyBytes(dve.VoteB.SignBytes(chainID), dve.VoteB.Signature) { - return fmt.Errorf("DuplicateVoteEvidence Error verifying VoteB: %v", ErrVoteInvalidSignature) + return fmt.Errorf("duplicateVoteEvidence Error verifying VoteB: %v", ErrVoteInvalidSignature) } return nil @@ -198,16 +198,16 @@ func (dve *DuplicateVoteEvidence) Equal(ev Evidence) bool { // ValidateBasic performs basic validation. func (dve *DuplicateVoteEvidence) ValidateBasic() error { if len(dve.PubKey.Bytes()) == 0 { - return errors.New("Empty PubKey") + return errors.New("empty PubKey") } if dve.VoteA == nil || dve.VoteB == nil { - return fmt.Errorf("One or both of the votes are empty %v, %v", dve.VoteA, dve.VoteB) + return fmt.Errorf("one or both of the votes are empty %v, %v", dve.VoteA, dve.VoteB) } if err := dve.VoteA.ValidateBasic(); err != nil { - return fmt.Errorf("Invalid VoteA: %v", err) + return fmt.Errorf("invalid VoteA: %v", err) } if err := dve.VoteB.ValidateBasic(); err != nil { - return fmt.Errorf("Invalid VoteB: %v", err) + return fmt.Errorf("invalid VoteB: %v", err) } return nil } @@ -271,7 +271,7 @@ type MockBadEvidence struct { } func (e MockBadEvidence) Verify(chainID string, pubKey crypto.PubKey) error { - return fmt.Errorf("MockBadEvidence") + return fmt.Errorf("mockBadEvidence") } func (e MockBadEvidence) Equal(ev Evidence) bool { e2 := ev.(MockBadEvidence) diff --git a/types/genesis.go b/types/genesis.go index 94680bca8..4a1fb3e1b 100644 --- a/types/genesis.go +++ b/types/genesis.go @@ -66,7 +66,7 @@ func (genDoc *GenesisDoc) ValidatorHash() []byte { // and fills in defaults for optional fields left empty func (genDoc *GenesisDoc) ValidateAndComplete() error { if genDoc.ChainID == "" { - return errors.New("Genesis doc must include non-empty chain_id") + return errors.New("genesis doc must include non-empty chain_id") } if len(genDoc.ChainID) > MaxChainIDLen { return errors.Errorf("chain_id in genesis doc is too long (max: %d)", MaxChainIDLen) @@ -80,10 +80,10 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error { for i, v := range genDoc.Validators { if v.Power == 0 { - return errors.Errorf("The genesis file cannot contain validators with no voting power: %v", v) + return errors.Errorf("the genesis file cannot contain validators with no voting power: %v", v) } if len(v.Address) > 0 && !bytes.Equal(v.PubKey.Address(), v.Address) { - return errors.Errorf("Incorrect address for validator %v in the genesis file, should be %v", v, v.PubKey.Address()) + return errors.Errorf("incorrect address for validator %v in the genesis file, should be %v", v, v.PubKey.Address()) } if len(v.Address) == 0 { genDoc.Validators[i].Address = v.PubKey.Address() diff --git a/types/params.go b/types/params.go index 9d2b1b9b4..773ec7731 100644 --- a/types/params.go +++ b/types/params.go @@ -100,26 +100,26 @@ func (params *ValidatorParams) IsValidPubkeyType(pubkeyType string) bool { // allowed limits, and returns an error if they are not. func (params *ConsensusParams) Validate() error { if params.Block.MaxBytes <= 0 { - return errors.Errorf("Block.MaxBytes must be greater than 0. Got %d", + return errors.Errorf("block.MaxBytes must be greater than 0. Got %d", params.Block.MaxBytes) } if params.Block.MaxBytes > MaxBlockSizeBytes { - return errors.Errorf("Block.MaxBytes is too big. %d > %d", + return errors.Errorf("block.MaxBytes is too big. %d > %d", params.Block.MaxBytes, MaxBlockSizeBytes) } if params.Block.MaxGas < -1 { - return errors.Errorf("Block.MaxGas must be greater or equal to -1. Got %d", + return errors.Errorf("block.MaxGas must be greater or equal to -1. Got %d", params.Block.MaxGas) } if params.Block.TimeIotaMs <= 0 { - return errors.Errorf("Block.TimeIotaMs must be greater than 0. Got %v", + return errors.Errorf("block.TimeIotaMs must be greater than 0. Got %v", params.Block.TimeIotaMs) } if params.Evidence.MaxAge <= 0 { - return errors.Errorf("EvidenceParams.MaxAge must be greater than 0. Got %d", + return errors.Errorf("evidenceParams.MaxAge must be greater than 0. Got %d", params.Evidence.MaxAge) } diff --git a/types/part_set.go b/types/part_set.go index ecac027f9..69ee3b006 100644 --- a/types/part_set.go +++ b/types/part_set.go @@ -13,8 +13,8 @@ import ( ) var ( - ErrPartSetUnexpectedIndex = errors.New("Error part set unexpected index") - ErrPartSetInvalidProof = errors.New("Error part set invalid proof") + ErrPartSetUnexpectedIndex = errors.New("error part set unexpected index") + ErrPartSetInvalidProof = errors.New("error part set invalid proof") ) type Part struct { @@ -74,7 +74,7 @@ func (psh PartSetHeader) Equals(other PartSetHeader) bool { // ValidateBasic performs basic validation. func (psh PartSetHeader) ValidateBasic() error { if psh.Total < 0 { - return errors.New("Negative Total") + return errors.New("negative Total") } // Hash can be empty in case of POLBlockID.PartsHeader in Proposal. if err := ValidateHash(psh.Hash); err != nil { diff --git a/types/part_set_test.go b/types/part_set_test.go index 706c8cae4..f67f4e7c9 100644 --- a/types/part_set_test.go +++ b/types/part_set_test.go @@ -36,7 +36,7 @@ func TestBasicPartSet(t *testing.T) { //t.Logf("\n%v", part) added, err := partSet2.AddPart(part) if !added || err != nil { - t.Errorf("Failed to add part %v, error: %v", i, err) + t.Errorf("failed to add part %v, error: %v", i, err) } } // adding part with invalid index @@ -73,7 +73,7 @@ func TestWrongProof(t *testing.T) { part.Proof.Aunts[0][0] += byte(0x01) added, err := partSet2.AddPart(part) if added || err == nil { - t.Errorf("Expected to fail adding a part with bad trail.") + t.Errorf("expected to fail adding a part with bad trail.") } // Test adding a part with wrong bytes. @@ -81,7 +81,7 @@ func TestWrongProof(t *testing.T) { part.Bytes[0] += byte(0x01) added, err = partSet2.AddPart(part) if added || err == nil { - t.Errorf("Expected to fail adding a part with bad bytes.") + t.Errorf("expected to fail adding a part with bad bytes.") } } diff --git a/types/proposal.go b/types/proposal.go index 97c06596e..54ad3b2f7 100644 --- a/types/proposal.go +++ b/types/proposal.go @@ -10,8 +10,8 @@ import ( ) var ( - ErrInvalidBlockPartSignature = errors.New("Error invalid block part signature") - ErrInvalidBlockPartHash = errors.New("Error invalid block part hash") + ErrInvalidBlockPartSignature = errors.New("error invalid block part signature") + ErrInvalidBlockPartHash = errors.New("error invalid block part hash") ) // Proposal defines a block proposal for the consensus. @@ -46,32 +46,32 @@ func NewProposal(height int64, round int, polRound int, blockID BlockID) *Propos // ValidateBasic performs basic validation. func (p *Proposal) ValidateBasic() error { if p.Type != ProposalType { - return errors.New("Invalid Type") + return errors.New("invalid Type") } if p.Height < 0 { - return errors.New("Negative Height") + return errors.New("negative Height") } if p.Round < 0 { - return errors.New("Negative Round") + return errors.New("negative Round") } if p.POLRound < -1 { - return errors.New("Negative POLRound (exception: -1)") + return errors.New("negative POLRound (exception: -1)") } if err := p.BlockID.ValidateBasic(); err != nil { - return fmt.Errorf("Wrong BlockID: %v", err) + return fmt.Errorf("wrong BlockID: %v", err) } // ValidateBasic above would pass even if the BlockID was empty: if !p.BlockID.IsComplete() { - return fmt.Errorf("Expected a complete, non-empty BlockID, got: %v", p.BlockID) + return fmt.Errorf("expected a complete, non-empty BlockID, got: %v", p.BlockID) } // NOTE: Timestamp validation is subtle and handled elsewhere. if len(p.Signature) == 0 { - return errors.New("Signature is missing") + return errors.New("signature is missing") } if len(p.Signature) > MaxSignatureSize { - return fmt.Errorf("Signature is too big (max: %d)", MaxSignatureSize) + return fmt.Errorf("signature is too big (max: %d)", MaxSignatureSize) } return nil } diff --git a/types/proposal_test.go b/types/proposal_test.go index 3a1368072..1b30a7286 100644 --- a/types/proposal_test.go +++ b/types/proposal_test.go @@ -39,7 +39,7 @@ func TestProposalString(t *testing.T) { str := testProposal.String() expected := `Proposal{12345/23456 (010203:111:626C6F636B70, -1) 000000000000 @ 2018-02-11T07:09:22.765Z}` if str != expected { - t.Errorf("Got unexpected string for Proposal. Expected:\n%v\nGot:\n%v", expected, str) + t.Errorf("got unexpected string for Proposal. Expected:\n%v\nGot:\n%v", expected, str) } } diff --git a/types/protobuf.go b/types/protobuf.go index fc43b0554..3ca521a4f 100644 --- a/types/protobuf.go +++ b/types/protobuf.go @@ -188,7 +188,7 @@ func (pb2tm) PubKey(pubKey abci.PubKey) (crypto.PubKey, error) { switch pubKey.Type { case ABCIPubKeyTypeEd25519: if len(pubKey.Data) != ed25519.PubKeyEd25519Size { - return nil, fmt.Errorf("Invalid size for PubKeyEd25519. Got %d, expected %d", + return nil, fmt.Errorf("invalid size for PubKeyEd25519. Got %d, expected %d", len(pubKey.Data), ed25519.PubKeyEd25519Size) } var pk ed25519.PubKeyEd25519 @@ -196,14 +196,14 @@ func (pb2tm) PubKey(pubKey abci.PubKey) (crypto.PubKey, error) { return pk, nil case ABCIPubKeyTypeSecp256k1: if len(pubKey.Data) != secp256k1.PubKeySecp256k1Size { - return nil, fmt.Errorf("Invalid size for PubKeySecp256k1. Got %d, expected %d", + return nil, fmt.Errorf("invalid size for PubKeySecp256k1. Got %d, expected %d", len(pubKey.Data), secp256k1.PubKeySecp256k1Size) } var pk secp256k1.PubKeySecp256k1 copy(pk[:], pubKey.Data) return pk, nil default: - return nil, fmt.Errorf("Unknown pubkey type %v", pubKey.Type) + return nil, fmt.Errorf("unknown pubkey type %v", pubKey.Type) } } diff --git a/types/tx.go b/types/tx.go index 54ba6bde8..73ff8d052 100644 --- a/types/tx.go +++ b/types/tx.go @@ -97,17 +97,17 @@ func (tp TxProof) Leaf() []byte { // and if the proof is internally consistent. Otherwise, it returns a sensible error. func (tp TxProof) Validate(dataHash []byte) error { if !bytes.Equal(dataHash, tp.RootHash) { - return errors.New("Proof matches different data hash") + return errors.New("proof matches different data hash") } if tp.Proof.Index < 0 { - return errors.New("Proof index cannot be negative") + return errors.New("proof index cannot be negative") } if tp.Proof.Total <= 0 { - return errors.New("Proof total must be positive") + return errors.New("proof total must be positive") } valid := tp.Proof.Verify(tp.RootHash, tp.Leaf()) if valid != nil { - return errors.New("Proof is not internally consistent") + return errors.New("proof is not internally consistent") } return nil } diff --git a/types/validation.go b/types/validation.go index 1271cfd94..b3b448004 100644 --- a/types/validation.go +++ b/types/validation.go @@ -22,7 +22,7 @@ func ValidateTime(t time.Time) error { oneYear = 8766 * time.Hour ) if t.Before(now.Add(-oneYear)) || t.After(now.Add(oneYear)) { - return fmt.Errorf("Time drifted too much. Expected: -1 < %v < 1 year", now) + return fmt.Errorf("time drifted too much. Expected: -1 < %v < 1 year", now) } return nil } @@ -31,7 +31,7 @@ func ValidateTime(t time.Time) error { // size != tmhash.Size. func ValidateHash(h []byte) error { if len(h) > 0 && len(h) != tmhash.Size { - return fmt.Errorf("Expected size to be %d bytes, got %d bytes", + return fmt.Errorf("expected size to be %d bytes, got %d bytes", tmhash.Size, len(h), ) diff --git a/types/validator_set.go b/types/validator_set.go index eda3a0b22..af7991494 100644 --- a/types/validator_set.go +++ b/types/validator_set.go @@ -605,7 +605,7 @@ func (vals *ValidatorSet) VerifyCommit(chainID string, blockID BlockID, height i return NewErrInvalidCommitHeight(height, commit.Height()) } if !blockID.Equals(commit.BlockID) { - return fmt.Errorf("Invalid commit -- wrong block id: want %v got %v", + return fmt.Errorf("invalid commit -- wrong block id: want %v got %v", blockID, commit.BlockID) } @@ -619,7 +619,7 @@ func (vals *ValidatorSet) VerifyCommit(chainID string, blockID BlockID, height i // Validate signature. precommitSignBytes := commit.VoteSignBytes(chainID, idx) if !val.PubKey.VerifyBytes(precommitSignBytes, precommit.Signature) { - return fmt.Errorf("Invalid commit -- invalid signature: %v", precommit) + return fmt.Errorf("invalid commit -- invalid signature: %v", precommit) } // Good precommit! if blockID.Equals(precommit.BlockID) { @@ -686,13 +686,13 @@ func (vals *ValidatorSet) VerifyFutureCommit(newSet *ValidatorSet, chainID strin continue } if precommit.Height != height { - return errors.Errorf("Blocks don't match - %d vs %d", round, precommit.Round) + return errors.Errorf("blocks don't match - %d vs %d", round, precommit.Round) } if precommit.Round != round { - return errors.Errorf("Invalid commit -- wrong round: %v vs %v", round, precommit.Round) + return errors.Errorf("invalid commit -- wrong round: %v vs %v", round, precommit.Round) } if precommit.Type != PrecommitType { - return errors.Errorf("Invalid commit -- not precommit @ index %v", idx) + return errors.Errorf("invalid commit -- not precommit @ index %v", idx) } // See if this validator is in oldVals. oldIdx, val := oldVals.GetByAddress(precommit.ValidatorAddress) @@ -704,7 +704,7 @@ func (vals *ValidatorSet) VerifyFutureCommit(newSet *ValidatorSet, chainID strin // Validate signature. precommitSignBytes := commit.VoteSignBytes(chainID, idx) if !val.PubKey.VerifyBytes(precommitSignBytes, precommit.Signature) { - return errors.Errorf("Invalid commit -- invalid signature: %v", precommit) + return errors.Errorf("invalid commit -- invalid signature: %v", precommit) } // Good precommit! if blockID.Equals(precommit.BlockID) { diff --git a/types/validator_set_test.go b/types/validator_set_test.go index 2a3de82ea..ae8ff47ec 100644 --- a/types/validator_set_test.go +++ b/types/validator_set_test.go @@ -141,7 +141,7 @@ func TestProposerSelection1(t *testing.T) { ` foo bar foo foo baz foo bar foo foo baz foo bar foo foo baz foo bar foo foo baz foo` + ` foo bar foo baz foo foo bar foo baz foo foo bar foo baz foo foo` if expected != strings.Join(proposers, " ") { - t.Errorf("Expected sequence of proposers was\n%v\nbut got \n%v", expected, strings.Join(proposers, " ")) + t.Errorf("expected sequence of proposers was\n%v\nbut got \n%v", expected, strings.Join(proposers, " ")) } } @@ -322,16 +322,16 @@ func randValidatorSet(numValidators int) *ValidatorSet { return NewValidatorSet(validators) } -func (valSet *ValidatorSet) toBytes() []byte { - bz, err := cdc.MarshalBinaryLengthPrefixed(valSet) +func (vals *ValidatorSet) toBytes() []byte { + bz, err := cdc.MarshalBinaryLengthPrefixed(vals) if err != nil { panic(err) } return bz } -func (valSet *ValidatorSet) fromBytes(b []byte) { - err := cdc.UnmarshalBinaryLengthPrefixed(b, &valSet) +func (vals *ValidatorSet) fromBytes(b []byte) { + err := cdc.UnmarshalBinaryLengthPrefixed(b, &vals) if err != nil { // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED panic(err) diff --git a/types/vote.go b/types/vote.go index 8f5eee7fb..e87eb4e60 100644 --- a/types/vote.go +++ b/types/vote.go @@ -17,13 +17,13 @@ const ( ) var ( - ErrVoteUnexpectedStep = errors.New("Unexpected step") - ErrVoteInvalidValidatorIndex = errors.New("Invalid validator index") - ErrVoteInvalidValidatorAddress = errors.New("Invalid validator address") - ErrVoteInvalidSignature = errors.New("Invalid signature") - ErrVoteInvalidBlockHash = errors.New("Invalid block hash") - ErrVoteNonDeterministicSignature = errors.New("Non-deterministic signature") - ErrVoteNil = errors.New("Nil vote") + ErrVoteUnexpectedStep = errors.New("unexpected step") + ErrVoteInvalidValidatorIndex = errors.New("invalid validator index") + ErrVoteInvalidValidatorAddress = errors.New("invalid validator address") + ErrVoteInvalidSignature = errors.New("invalid signature") + ErrVoteInvalidBlockHash = errors.New("invalid block hash") + ErrVoteNonDeterministicSignature = errors.New("non-deterministic signature") + ErrVoteNil = errors.New("nil vote") ) type ErrVoteConflictingVotes struct { @@ -124,39 +124,39 @@ func (vote *Vote) Verify(chainID string, pubKey crypto.PubKey) error { // ValidateBasic performs basic validation. func (vote *Vote) ValidateBasic() error { if !IsVoteTypeValid(vote.Type) { - return errors.New("Invalid Type") + return errors.New("invalid Type") } if vote.Height < 0 { - return errors.New("Negative Height") + return errors.New("negative Height") } if vote.Round < 0 { - return errors.New("Negative Round") + return errors.New("negative Round") } // NOTE: Timestamp validation is subtle and handled elsewhere. if err := vote.BlockID.ValidateBasic(); err != nil { - return fmt.Errorf("Wrong BlockID: %v", err) + return fmt.Errorf("wrong BlockID: %v", err) } // BlockID.ValidateBasic would not err if we for instance have an empty hash but a // non-empty PartsSetHeader: if !vote.BlockID.IsZero() && !vote.BlockID.IsComplete() { - return fmt.Errorf("BlockID must be either empty or complete, got: %v", vote.BlockID) + return fmt.Errorf("blockID must be either empty or complete, got: %v", vote.BlockID) } if len(vote.ValidatorAddress) != crypto.AddressSize { - return fmt.Errorf("Expected ValidatorAddress size to be %d bytes, got %d bytes", + return fmt.Errorf("expected ValidatorAddress size to be %d bytes, got %d bytes", crypto.AddressSize, len(vote.ValidatorAddress), ) } if vote.ValidatorIndex < 0 { - return errors.New("Negative ValidatorIndex") + return errors.New("negative ValidatorIndex") } if len(vote.Signature) == 0 { - return errors.New("Signature is missing") + return errors.New("signature is missing") } if len(vote.Signature) > MaxSignatureSize { - return fmt.Errorf("Signature is too big (max: %d)", MaxSignatureSize) + return fmt.Errorf("signature is too big (max: %d)", MaxSignatureSize) } return nil } diff --git a/types/vote_set.go b/types/vote_set.go index 9e42b8cde..f296e82e1 100644 --- a/types/vote_set.go +++ b/types/vote_set.go @@ -314,7 +314,7 @@ func (voteSet *VoteSet) SetPeerMaj23(peerID P2PID, blockID BlockID) error { if existing.Equals(blockID) { return nil // Nothing to do } - return fmt.Errorf("SetPeerMaj23: Received conflicting blockID from peer %v. Got %v, expected %v", + return fmt.Errorf("setPeerMaj23: Received conflicting blockID from peer %v. Got %v, expected %v", peerID, blockID, existing) } voteSet.peerMaj23s[peerID] = blockID diff --git a/types/vote_set_test.go b/types/vote_set_test.go index a638b6033..d43482020 100644 --- a/types/vote_set_test.go +++ b/types/vote_set_test.go @@ -75,14 +75,14 @@ func TestAddVote(t *testing.T) { val0Addr := val0.GetPubKey().Address() if voteSet.GetByAddress(val0Addr) != nil { - t.Errorf("Expected GetByAddress(val0.Address) to be nil") + t.Errorf("expected GetByAddress(val0.Address) to be nil") } if voteSet.BitArray().GetIndex(0) { - t.Errorf("Expected BitArray.GetIndex(0) to be false") + t.Errorf("expected BitArray.GetIndex(0) to be false") } blockID, ok := voteSet.TwoThirdsMajority() if ok || !blockID.IsZero() { - t.Errorf("There should be no 2/3 majority") + t.Errorf("there should be no 2/3 majority") } vote := &Vote{ @@ -100,14 +100,14 @@ func TestAddVote(t *testing.T) { } if voteSet.GetByAddress(val0Addr) == nil { - t.Errorf("Expected GetByAddress(val0.Address) to be present") + t.Errorf("expected GetByAddress(val0.Address) to be present") } if !voteSet.BitArray().GetIndex(0) { - t.Errorf("Expected BitArray.GetIndex(0) to be true") + t.Errorf("expected BitArray.GetIndex(0) to be true") } blockID, ok = voteSet.TwoThirdsMajority() if ok || !blockID.IsZero() { - t.Errorf("There should be no 2/3 majority") + t.Errorf("there should be no 2/3 majority") } } @@ -135,7 +135,7 @@ func Test2_3Majority(t *testing.T) { } blockID, ok := voteSet.TwoThirdsMajority() if ok || !blockID.IsZero() { - t.Errorf("There should be no 2/3 majority") + t.Errorf("there should be no 2/3 majority") } // 7th validator voted for some blockhash @@ -148,7 +148,7 @@ func Test2_3Majority(t *testing.T) { } blockID, ok = voteSet.TwoThirdsMajority() if ok || !blockID.IsZero() { - t.Errorf("There should be no 2/3 majority") + t.Errorf("there should be no 2/3 majority") } } @@ -162,7 +162,7 @@ func Test2_3Majority(t *testing.T) { } blockID, ok = voteSet.TwoThirdsMajority() if !ok || !blockID.IsZero() { - t.Errorf("There should be 2/3 majority for nil") + t.Errorf("there should be 2/3 majority for nil") } } } @@ -196,7 +196,7 @@ func Test2_3MajorityRedux(t *testing.T) { } blockID, ok := voteSet.TwoThirdsMajority() if ok || !blockID.IsZero() { - t.Errorf("There should be no 2/3 majority") + t.Errorf("there should be no 2/3 majority") } // 67th validator voted for nil @@ -209,7 +209,7 @@ func Test2_3MajorityRedux(t *testing.T) { } blockID, ok = voteSet.TwoThirdsMajority() if ok || !blockID.IsZero() { - t.Errorf("There should be no 2/3 majority: last vote added was nil") + t.Errorf("there should be no 2/3 majority: last vote added was nil") } } @@ -224,7 +224,7 @@ func Test2_3MajorityRedux(t *testing.T) { } blockID, ok = voteSet.TwoThirdsMajority() if ok || !blockID.IsZero() { - t.Errorf("There should be no 2/3 majority: last vote added had different PartSetHeader Hash") + t.Errorf("there should be no 2/3 majority: last vote added had different PartSetHeader Hash") } } @@ -239,7 +239,7 @@ func Test2_3MajorityRedux(t *testing.T) { } blockID, ok = voteSet.TwoThirdsMajority() if ok || !blockID.IsZero() { - t.Errorf("There should be no 2/3 majority: last vote added had different PartSetHeader Total") + t.Errorf("there should be no 2/3 majority: last vote added had different PartSetHeader Total") } } @@ -253,7 +253,7 @@ func Test2_3MajorityRedux(t *testing.T) { } blockID, ok = voteSet.TwoThirdsMajority() if ok || !blockID.IsZero() { - t.Errorf("There should be no 2/3 majority: last vote added had different BlockHash") + t.Errorf("there should be no 2/3 majority: last vote added had different BlockHash") } } @@ -267,7 +267,7 @@ func Test2_3MajorityRedux(t *testing.T) { } blockID, ok = voteSet.TwoThirdsMajority() if !ok || !blockID.Equals(BlockID{blockHash, blockPartsHeader}) { - t.Errorf("There should be 2/3 majority") + t.Errorf("there should be 2/3 majority") } } } @@ -292,7 +292,7 @@ func TestBadVotes(t *testing.T) { vote := withValidator(voteProto, addr, 0) added, err := signAddVote(privValidators[0], vote, voteSet) if !added || err != nil { - t.Errorf("Expected VoteSet.Add to succeed") + t.Errorf("expected VoteSet.Add to succeed") } } @@ -302,7 +302,7 @@ func TestBadVotes(t *testing.T) { vote := withValidator(voteProto, addr, 0) added, err := signAddVote(privValidators[0], withBlockHash(vote, cmn.RandBytes(32)), voteSet) if added || err == nil { - t.Errorf("Expected VoteSet.Add to fail, conflicting vote.") + t.Errorf("expected VoteSet.Add to fail, conflicting vote.") } } @@ -312,7 +312,7 @@ func TestBadVotes(t *testing.T) { vote := withValidator(voteProto, addr, 1) added, err := signAddVote(privValidators[1], withHeight(vote, height+1), voteSet) if added || err == nil { - t.Errorf("Expected VoteSet.Add to fail, wrong height") + t.Errorf("expected VoteSet.Add to fail, wrong height") } } @@ -322,7 +322,7 @@ func TestBadVotes(t *testing.T) { vote := withValidator(voteProto, addr, 2) added, err := signAddVote(privValidators[2], withRound(vote, round+1), voteSet) if added || err == nil { - t.Errorf("Expected VoteSet.Add to fail, wrong round") + t.Errorf("expected VoteSet.Add to fail, wrong round") } } @@ -332,7 +332,7 @@ func TestBadVotes(t *testing.T) { vote := withValidator(voteProto, addr, 3) added, err := signAddVote(privValidators[3], withType(vote, byte(PrecommitType)), voteSet) if added || err == nil { - t.Errorf("Expected VoteSet.Add to fail, wrong type") + t.Errorf("expected VoteSet.Add to fail, wrong type") } } } @@ -359,7 +359,7 @@ func TestConflicts(t *testing.T) { vote := withValidator(voteProto, val0Addr, 0) added, err := signAddVote(privValidators[0], vote, voteSet) if !added || err != nil { - t.Errorf("Expected VoteSet.Add to succeed") + t.Errorf("expected VoteSet.Add to succeed") } } @@ -368,10 +368,10 @@ func TestConflicts(t *testing.T) { vote := withValidator(voteProto, val0Addr, 0) added, err := signAddVote(privValidators[0], withBlockHash(vote, blockHash1), voteSet) if added { - t.Errorf("Expected VoteSet.Add to fail, conflicting vote.") + t.Errorf("expected VoteSet.Add to fail, conflicting vote.") } if err == nil { - t.Errorf("Expected VoteSet.Add to return error, conflicting vote.") + t.Errorf("expected VoteSet.Add to return error, conflicting vote.") } } @@ -383,10 +383,10 @@ func TestConflicts(t *testing.T) { vote := withValidator(voteProto, val0Addr, 0) added, err := signAddVote(privValidators[0], withBlockHash(vote, blockHash1), voteSet) if !added { - t.Errorf("Expected VoteSet.Add to succeed, called SetPeerMaj23().") + t.Errorf("expected VoteSet.Add to succeed, called SetPeerMaj23().") } if err == nil { - t.Errorf("Expected VoteSet.Add to return error, conflicting vote.") + t.Errorf("expected VoteSet.Add to return error, conflicting vote.") } } @@ -398,10 +398,10 @@ func TestConflicts(t *testing.T) { vote := withValidator(voteProto, val0Addr, 0) added, err := signAddVote(privValidators[0], withBlockHash(vote, blockHash2), voteSet) if added { - t.Errorf("Expected VoteSet.Add to fail, duplicate SetPeerMaj23() from peerA") + t.Errorf("expected VoteSet.Add to fail, duplicate SetPeerMaj23() from peerA") } if err == nil { - t.Errorf("Expected VoteSet.Add to return error, conflicting vote.") + t.Errorf("expected VoteSet.Add to return error, conflicting vote.") } } @@ -411,16 +411,16 @@ func TestConflicts(t *testing.T) { vote := withValidator(voteProto, addr, 1) added, err := signAddVote(privValidators[1], withBlockHash(vote, blockHash1), voteSet) if !added || err != nil { - t.Errorf("Expected VoteSet.Add to succeed") + t.Errorf("expected VoteSet.Add to succeed") } } // check if voteSet.HasTwoThirdsMajority() { - t.Errorf("We shouldn't have 2/3 majority yet") + t.Errorf("we shouldn't have 2/3 majority yet") } if voteSet.HasTwoThirdsAny() { - t.Errorf("We shouldn't have 2/3 if any votes yet") + t.Errorf("we shouldn't have 2/3 if any votes yet") } // val2 votes for blockHash2. @@ -429,16 +429,16 @@ func TestConflicts(t *testing.T) { vote := withValidator(voteProto, addr, 2) added, err := signAddVote(privValidators[2], withBlockHash(vote, blockHash2), voteSet) if !added || err != nil { - t.Errorf("Expected VoteSet.Add to succeed") + t.Errorf("expected VoteSet.Add to succeed") } } // check if voteSet.HasTwoThirdsMajority() { - t.Errorf("We shouldn't have 2/3 majority yet") + t.Errorf("we shouldn't have 2/3 majority yet") } if !voteSet.HasTwoThirdsAny() { - t.Errorf("We should have 2/3 if any votes") + t.Errorf("we should have 2/3 if any votes") } // now attempt tracking blockHash1 @@ -450,23 +450,23 @@ func TestConflicts(t *testing.T) { vote := withValidator(voteProto, addr, 2) added, err := signAddVote(privValidators[2], withBlockHash(vote, blockHash1), voteSet) if !added { - t.Errorf("Expected VoteSet.Add to succeed") + t.Errorf("expected VoteSet.Add to succeed") } if err == nil { - t.Errorf("Expected VoteSet.Add to return error, conflicting vote") + t.Errorf("expected VoteSet.Add to return error, conflicting vote") } } // check if !voteSet.HasTwoThirdsMajority() { - t.Errorf("We should have 2/3 majority for blockHash1") + t.Errorf("we should have 2/3 majority for blockHash1") } blockIDMaj23, _ := voteSet.TwoThirdsMajority() if !bytes.Equal(blockIDMaj23.Hash, blockHash1) { - t.Errorf("Got the wrong 2/3 majority blockhash") + t.Errorf("got the wrong 2/3 majority blockhash") } if !voteSet.HasTwoThirdsAny() { - t.Errorf("We should have 2/3 if any votes") + t.Errorf("we should have 2/3 if any votes") } } @@ -526,12 +526,12 @@ func TestMakeCommit(t *testing.T) { // Commit should have 10 elements if len(commit.Precommits) != 10 { - t.Errorf("Commit Precommits should have the same number of precommits as validators") + t.Errorf("commit Precommits should have the same number of precommits as validators") } // Ensure that Commit precommits are ordered. if err := commit.ValidateBasic(); err != nil { - t.Errorf("Error in Commit.ValidateBasic(): %v", err) + t.Errorf("error in Commit.ValidateBasic(): %v", err) } } diff --git a/types/vote_test.go b/types/vote_test.go index 52252a4dd..6c2379feb 100644 --- a/types/vote_test.go +++ b/types/vote_test.go @@ -199,7 +199,7 @@ func TestIsVoteTypeValid(t *testing.T) { tt := tt t.Run(tt.name, func(st *testing.T) { if rs := IsVoteTypeValid(tt.in); rs != tt.out { - t.Errorf("Got unexpected Vote type. Expected:\n%v\nGot:\n%v", rs, tt.out) + t.Errorf("got unexpected Vote type. Expected:\n%v\nGot:\n%v", rs, tt.out) } }) } @@ -258,13 +258,13 @@ func TestVoteString(t *testing.T) { str := examplePrecommit().String() expected := `Vote{56789:6AF1F4111082 12345/02/2(Precommit) 8B01023386C3 000000000000 @ 2017-12-25T03:00:01.234Z}` if str != expected { - t.Errorf("Got unexpected string for Vote. Expected:\n%v\nGot:\n%v", expected, str) + t.Errorf("got unexpected string for Vote. Expected:\n%v\nGot:\n%v", expected, str) } str2 := examplePrevote().String() expected = `Vote{56789:6AF1F4111082 12345/02/1(Prevote) 8B01023386C3 000000000000 @ 2017-12-25T03:00:01.234Z}` if str2 != expected { - t.Errorf("Got unexpected string for Vote. Expected:\n%v\nGot:\n%v", expected, str2) + t.Errorf("got unexpected string for Vote. Expected:\n%v\nGot:\n%v", expected, str2) } }