Browse Source

more linting

pull/703/head
Ethan Buchman 7 years ago
parent
commit
9529f12c28
13 changed files with 43 additions and 23 deletions
  1. +4
    -1
      cmd/tendermint/commands/gen_validator.go
  2. +2
    -2
      consensus/replay_file.go
  3. +4
    -1
      node/node.go
  4. +2
    -2
      p2p/fuzz.go
  5. +1
    -1
      p2p/pex_reactor.go
  6. +2
    -2
      p2p/secret_connection.go
  7. +3
    -1
      p2p/trust/trustmetric.go
  8. +2
    -2
      p2p/types.go
  9. +2
    -2
      p2p/util.go
  10. +6
    -2
      rpc/lib/server/handlers.go
  11. +2
    -2
      rpc/lib/server/http_server.go
  12. +12
    -4
      scripts/wal2json/main.go
  13. +1
    -1
      types/part_set.go

+ 4
- 1
cmd/tendermint/commands/gen_validator.go View File

@ -19,7 +19,10 @@ var GenValidatorCmd = &cobra.Command{
func genValidator(cmd *cobra.Command, args []string) {
privValidator := types.GenPrivValidatorFS("")
privValidatorJSONBytes, _ := json.MarshalIndent(privValidator, "", "\t")
privValidatorJSONBytes, err := json.MarshalIndent(privValidator, "", "\t")
if err != nil {
panic(err)
}
fmt.Printf(`%v
`, string(privValidatorJSONBytes))
}

+ 2
- 2
consensus/replay_file.go View File

@ -59,7 +59,7 @@ func (cs *ConsensusState) ReplayFile(file string, console bool) error {
defer cs.eventBus.Unsubscribe(ctx, subscriber, types.EventQueryNewRoundStep)
// just open the file for reading, no need to use wal
fp, err := os.OpenFile(file, os.O_RDONLY, 0666)
fp, err := os.OpenFile(file, os.O_RDONLY, 0600)
if err != nil {
return err
}
@ -130,7 +130,7 @@ func (pb *playback) replayReset(count int, newStepCh chan interface{}) error {
if err := pb.fp.Close(); err != nil {
return err
}
fp, err := os.OpenFile(pb.fileName, os.O_RDONLY, 0666)
fp, err := os.OpenFile(pb.fileName, os.O_RDONLY, 0600)
if err != nil {
return err
}


+ 4
- 1
node/node.go View File

@ -430,7 +430,10 @@ func (n *Node) startRPC() ([]net.Listener, error) {
mux := http.NewServeMux()
rpcLogger := n.Logger.With("module", "rpc-server")
onDisconnect := rpcserver.OnDisconnect(func(remoteAddr string) {
n.eventBus.UnsubscribeAll(context.Background(), remoteAddr)
err := n.eventBus.UnsubscribeAll(context.Background(), remoteAddr)
if err != nil {
rpcLogger.Error("Error unsubsribing from all on disconnect", "err", err)
}
})
wm := rpcserver.NewWebsocketManager(rpccore.Routes, onDisconnect)
wm.SetLogger(rpcLogger.With("protocol", "websocket"))


+ 2
- 2
p2p/fuzz.go View File

@ -124,7 +124,7 @@ func (fc *FuzzedConnection) SetWriteDeadline(t time.Time) error {
func (fc *FuzzedConnection) randomDuration() time.Duration {
maxDelayMillis := int(fc.config.MaxDelay.Nanoseconds() / 1000)
return time.Millisecond * time.Duration(rand.Int()%maxDelayMillis)
return time.Millisecond * time.Duration(rand.Int()%maxDelayMillis) // nolint: gas
}
// implements the fuzz (delay, kill conn)
@ -143,7 +143,7 @@ func (fc *FuzzedConnection) fuzz() bool {
} else if r < fc.config.ProbDropRW+fc.config.ProbDropConn {
// XXX: can't this fail because machine precision?
// XXX: do we need an error?
fc.Close() // nolint: errcheck
fc.Close() // nolint: errcheck, gas
return true
} else if r < fc.config.ProbDropRW+fc.config.ProbDropConn+fc.config.ProbSleep {
time.Sleep(fc.randomDuration())


+ 1
- 1
p2p/pex_reactor.go View File

@ -283,7 +283,7 @@ func (r *PEXReactor) ensurePeers() {
// If we need more addresses, pick a random peer and ask for more.
if r.book.NeedMoreAddrs() {
if peers := r.Switch.Peers().List(); len(peers) > 0 {
i := rand.Int() % len(peers)
i := rand.Int() % len(peers) // nolint: gas
peer := peers[i]
r.Logger.Info("No addresses to dial. Sending pexRequest to random peer", "peer", peer)
r.RequestPEX(peer)


+ 2
- 2
p2p/secret_connection.go View File

@ -302,7 +302,7 @@ func shareAuthSignature(sc *SecretConnection, pubKey crypto.PubKeyEd25519, signa
// sha256
func hash32(input []byte) (res *[32]byte) {
hasher := sha256.New()
hasher.Write(input) // nolint: errcheck
hasher.Write(input) // nolint: errcheck, gas
resSlice := hasher.Sum(nil)
res = new([32]byte)
copy(res[:], resSlice)
@ -312,7 +312,7 @@ func hash32(input []byte) (res *[32]byte) {
// We only fill in the first 20 bytes with ripemd160
func hash24(input []byte) (res *[24]byte) {
hasher := ripemd160.New()
hasher.Write(input) // nolint: errcheck
hasher.Write(input) // nolint: errcheck, gas
resSlice := hasher.Sum(nil)
res = new([24]byte)
copy(res[:], resSlice)


+ 3
- 1
p2p/trust/trustmetric.go View File

@ -47,7 +47,9 @@ func NewTrustMetricStore(db dbm.DB, tmc TrustMetricConfig) *TrustMetricStore {
// OnStart implements Service
func (tms *TrustMetricStore) OnStart() error {
tms.BaseService.OnStart()
if err := tms.BaseService.OnStart(); err != nil {
return err
}
tms.mtx.Lock()
defer tms.mtx.Unlock()


+ 2
- 2
p2p/types.go View File

@ -55,12 +55,12 @@ func (info *NodeInfo) CompatibleWith(other *NodeInfo) error {
}
func (info *NodeInfo) ListenHost() string {
host, _, _ := net.SplitHostPort(info.ListenAddr)
host, _, _ := net.SplitHostPort(info.ListenAddr) // nolint: errcheck, gas
return host
}
func (info *NodeInfo) ListenPort() int {
_, port, _ := net.SplitHostPort(info.ListenAddr)
_, port, _ := net.SplitHostPort(info.ListenAddr) // nolint: errcheck, gas
port_i, err := strconv.Atoi(port)
if err != nil {
return -1


+ 2
- 2
p2p/util.go View File

@ -7,9 +7,9 @@ import (
// doubleSha256 calculates sha256(sha256(b)) and returns the resulting bytes.
func doubleSha256(b []byte) []byte {
hasher := sha256.New()
hasher.Write(b) // nolint: errcheck
hasher.Write(b) // nolint: errcheck, gas
sum := hasher.Sum(nil)
hasher.Reset()
hasher.Write(sum) // nolint: errcheck
hasher.Write(sum) // nolint: errcheck, gas
return hasher.Sum(nil)
}

+ 6
- 2
rpc/lib/server/handlers.go View File

@ -99,7 +99,11 @@ func funcReturnTypes(f interface{}) []reflect.Type {
// jsonrpc calls grab the given method's function info and runs reflect.Call
func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger log.Logger) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
b, _ := ioutil.ReadAll(r.Body)
b, err := ioutil.ReadAll(r.Body)
if err != nil {
WriteRPCResponseHTTP(w, types.RPCInvalidRequestError("", errors.Wrap(err, "Error reading request body")))
return
}
// if its an empty request (like from a browser),
// just display a list of functions
if len(b) == 0 {
@ -108,7 +112,7 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger log.Logger) http.Han
}
var request types.RPCRequest
err := json.Unmarshal(b, &request)
err = json.Unmarshal(b, &request)
if err != nil {
WriteRPCResponseHTTP(w, types.RPCParseError("", errors.Wrap(err, "Error unmarshalling request")))
return


+ 2
- 2
rpc/lib/server/http_server.go View File

@ -56,7 +56,7 @@ func WriteRPCResponseHTTPError(w http.ResponseWriter, httpCode int, res types.RP
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(httpCode)
w.Write(jsonBytes) // nolint: errcheck
w.Write(jsonBytes) // nolint: errcheck, gas
}
func WriteRPCResponseHTTP(w http.ResponseWriter, res types.RPCResponse) {
@ -66,7 +66,7 @@ func WriteRPCResponseHTTP(w http.ResponseWriter, res types.RPCResponse) {
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200)
w.Write(jsonBytes) // nolint: errcheck
w.Write(jsonBytes) // nolint: errcheck, gas
}
//-----------------------------------------------------------------------------


+ 12
- 4
scripts/wal2json/main.go View File

@ -41,10 +41,18 @@ func main() {
panic(fmt.Errorf("failed to marshal msg: %v", err))
}
os.Stdout.Write(json)
os.Stdout.Write([]byte("\n"))
if end, ok := msg.Msg.(cs.EndHeightMessage); ok {
os.Stdout.Write([]byte(fmt.Sprintf("ENDHEIGHT %d\n", end.Height)))
_, err = os.Stdout.Write(json)
if err == nil {
_, err = os.Stdout.Write([]byte("\n"))
}
if err == nil {
if end, ok := msg.Msg.(cs.EndHeightMessage); ok {
_, err = os.Stdout.Write([]byte(fmt.Sprintf("ENDHEIGHT %d\n", end.Height))) // nolint: errcheck, gas
}
}
if err != nil {
fmt.Println("Failed to write message", err)
os.Exit(1)
}
}
}

+ 1
- 1
types/part_set.go View File

@ -34,7 +34,7 @@ func (part *Part) Hash() []byte {
return part.hash
} else {
hasher := ripemd160.New()
hasher.Write(part.Bytes) // nolint: errcheck
hasher.Write(part.Bytes) // nolint: errcheck, gas
part.hash = hasher.Sum(nil)
return part.hash
}


Loading…
Cancel
Save