Skip to content

Commit

Permalink
Add UnusedParameter linter (ava-labs#2226)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Nov 14, 2022
1 parent 707ffe4 commit 3a7ebb1
Show file tree
Hide file tree
Showing 58 changed files with 182 additions and 210 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ linters:
linters-settings:
revive:
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
- name: unused-parameter
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-receiver
- name: unused-receiver
disabled: false
Expand Down
2 changes: 1 addition & 1 deletion api/admin/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NewMockClient(response interface{}, err error) rpc.EndpointRequester {
}
}

func (mc *mockClient) SendRequest(ctx context.Context, method string, params interface{}, reply interface{}, options ...rpc.Option) error {
func (mc *mockClient) SendRequest(_ context.Context, _ string, _ interface{}, reply interface{}, _ ...rpc.Option) error {
if mc.err != nil {
return mc.err
}
Expand Down
2 changes: 1 addition & 1 deletion api/admin/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func (service *Admin) GetLoggerLevel(_ *http.Request, args *GetLoggerLevelArgs,
}

// GetConfig returns the config that the node was started with.
func (service *Admin) GetConfig(_ *http.Request, args *struct{}, reply *interface{}) error {
func (service *Admin) GetConfig(_ *http.Request, _ *struct{}, reply *interface{}) error {
service.Log.Debug("Admin: GetConfig called")
*reply = service.NodeConfig
return nil
Expand Down
2 changes: 1 addition & 1 deletion api/health/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type mockClient struct {
onCall func()
}

func (mc *mockClient) SendRequest(ctx context.Context, method string, params interface{}, replyIntf interface{}, options ...rpc.Option) error {
func (mc *mockClient) SendRequest(_ context.Context, _ string, _ interface{}, replyIntf interface{}, _ ...rpc.Option) error {
reply := replyIntf.(*APIHealthReply)
*reply = mc.reply
mc.onCall()
Expand Down
2 changes: 1 addition & 1 deletion api/info/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ type GetTxFeeResponse struct {
}

// GetTxFee returns the transaction fee in nAVAX.
func (service *Info) GetTxFee(_ *http.Request, args *struct{}, reply *GetTxFeeResponse) error {
func (service *Info) GetTxFee(_ *http.Request, _ *struct{}, reply *GetTxFeeResponse) error {
reply.TxFee = json.Uint64(service.TxFee)
reply.CreationTxFee = json.Uint64(service.CreateAssetTxFee)
reply.CreateAssetTxFee = json.Uint64(service.CreateAssetTxFee)
Expand Down
6 changes: 3 additions & 3 deletions api/ipcs/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type PublishBlockchainReply struct {
}

// PublishBlockchain publishes the finalized accepted transactions from the blockchainID over the IPC
func (ipc *IPCServer) PublishBlockchain(r *http.Request, args *PublishBlockchainArgs, reply *PublishBlockchainReply) error {
func (ipc *IPCServer) PublishBlockchain(_ *http.Request, args *PublishBlockchainArgs, reply *PublishBlockchainReply) error {
ipc.log.Debug("IPCs: PublishBlockchain called",
logging.UserString("blockchainID", args.BlockchainID),
)
Expand Down Expand Up @@ -93,7 +93,7 @@ type UnpublishBlockchainArgs struct {
}

// UnpublishBlockchain closes publishing of a blockchainID
func (ipc *IPCServer) UnpublishBlockchain(r *http.Request, args *UnpublishBlockchainArgs, _ *api.EmptyReply) error {
func (ipc *IPCServer) UnpublishBlockchain(_ *http.Request, args *UnpublishBlockchainArgs, _ *api.EmptyReply) error {
ipc.log.Debug("IPCs: UnpublishBlockchain called",
logging.UserString("blockchainID", args.BlockchainID),
)
Expand Down Expand Up @@ -124,7 +124,7 @@ type GetPublishedBlockchainsReply struct {
}

// GetPublishedBlockchains returns blockchains being published
func (ipc *IPCServer) GetPublishedBlockchains(r *http.Request, args *struct{}, reply *GetPublishedBlockchainsReply) error {
func (ipc *IPCServer) GetPublishedBlockchains(_ *http.Request, _ *struct{}, reply *GetPublishedBlockchainsReply) error {
reply.Chains = ipc.ipcs.GetPublishedBlockchains()
return nil
}
4 changes: 2 additions & 2 deletions api/keystore/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type ListUsersReply struct {
Users []string `json:"users"`
}

func (s *service) ListUsers(_ *http.Request, args *struct{}, reply *ListUsersReply) error {
func (s *service) ListUsers(_ *http.Request, _ *struct{}, reply *ListUsersReply) error {
s.ks.log.Debug("Keystore: ListUsers called")

var err error
Expand All @@ -56,7 +56,7 @@ type ImportUserArgs struct {
Encoding formatting.Encoding `json:"encoding"`
}

func (s *service) ImportUser(r *http.Request, args *ImportUserArgs, _ *api.EmptyReply) error {
func (s *service) ImportUser(_ *http.Request, args *ImportUserArgs, _ *api.EmptyReply) error {
s.ks.log.Debug("Keystore: ImportUser called",
logging.UserString("username", args.Username),
)
Expand Down
2 changes: 1 addition & 1 deletion chains/atomic/test_shared_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func TestSharedMemoryCommitOnRemove(t *testing.T, _, chainID1 ids.ID, sm0, _ Sha
}

// TestPutAndRemoveBatch tests to make sure multiple put and remove requests work properly
func TestPutAndRemoveBatch(t *testing.T, chainID0, chainID1 ids.ID, _, sm1 SharedMemory, db database.Database) {
func TestPutAndRemoveBatch(t *testing.T, chainID0, _ ids.ID, _, sm1 SharedMemory, db database.Database) {
require := require.New(t)

batch := db.NewBatch()
Expand Down
2 changes: 1 addition & 1 deletion database/memdb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (db *Database) NewIteratorWithStartAndPrefix(start, prefix []byte) database
}
}

func (db *Database) Compact(start []byte, limit []byte) error {
func (db *Database) Compact(_, _ []byte) error {
db.lock.RLock()
defer db.lock.RUnlock()

Expand Down
2 changes: 1 addition & 1 deletion database/nodb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (*Database) NewIteratorWithStart([]byte) database.Iterator { return &Iterat
func (*Database) NewIteratorWithPrefix([]byte) database.Iterator { return &Iterator{} }

// NewIteratorWithStartAndPrefix returns a new empty iterator
func (*Database) NewIteratorWithStartAndPrefix(start, prefix []byte) database.Iterator {
func (*Database) NewIteratorWithStartAndPrefix(_, _ []byte) database.Iterator {
return &Iterator{}
}

Expand Down
6 changes: 3 additions & 3 deletions ids/test_aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var AliasTests = []func(require *require.Assertions, r AliaserReader, w AliaserW
AliaserRemoveAliasTest,
}

func AliaserLookupErrorTest(require *require.Assertions, r AliaserReader, w AliaserWriter) {
func AliaserLookupErrorTest(require *require.Assertions, r AliaserReader, _ AliaserWriter) {
_, err := r.Lookup("Batman")
require.Error(err, "expected an error due to missing alias")
}
Expand All @@ -30,7 +30,7 @@ func AliaserLookupTest(require *require.Assertions, r AliaserReader, w AliaserWr
require.Equal(id, res)
}

func AliaserAliasesEmptyTest(require *require.Assertions, r AliaserReader, w AliaserWriter) {
func AliaserAliasesEmptyTest(require *require.Assertions, r AliaserReader, _ AliaserWriter) {
id := ID{'J', 'a', 'm', 'e', 's', ' ', 'G', 'o', 'r', 'd', 'o', 'n'}

aliases, err := r.Aliases(id)
Expand Down Expand Up @@ -71,7 +71,7 @@ func AliaserPrimaryAliasTest(require *require.Assertions, r AliaserReader, w Ali
require.Equal(expected, res)
}

func AliaserAliasClashTest(require *require.Assertions, r AliaserReader, w AliaserWriter) {
func AliaserAliasClashTest(require *require.Assertions, _ AliaserReader, w AliaserWriter) {
id1 := ID{'B', 'r', 'u', 'c', 'e', ' ', 'W', 'a', 'y', 'n', 'e'}
id2 := ID{'D', 'i', 'c', 'k', ' ', 'G', 'r', 'a', 'y', 's', 'o', 'n'}
err := w.Alias(id1, "Batman")
Expand Down
2 changes: 1 addition & 1 deletion indexer/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type mockClient struct {
onSendRequestF func(reply interface{}) error
}

func (mc *mockClient) SendRequest(ctx context.Context, method string, _ interface{}, reply interface{}, options ...rpc.Option) error {
func (mc *mockClient) SendRequest(_ context.Context, method string, _ interface{}, reply interface{}, _ ...rpc.Option) error {
mc.require.Equal(mc.expectedMethod, method)
return mc.onSendRequestF(reply)
}
Expand Down
8 changes: 4 additions & 4 deletions indexer/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type GetContainerRangeResponse struct {
// If [startIndex] > the last accepted index, returns an error (unless the above apply.)
// If [n] > [MaxFetchedByRange], returns an error.
// If we run out of transactions, returns the ones fetched before running out.
func (s *service) GetContainerRange(r *http.Request, args *GetContainerRangeArgs, reply *GetContainerRangeResponse) error {
func (s *service) GetContainerRange(_ *http.Request, args *GetContainerRangeArgs, reply *GetContainerRangeResponse) error {
containers, err := s.Index.GetContainerRange(uint64(args.StartIndex), uint64(args.NumToFetch))
if err != nil {
return err
Expand Down Expand Up @@ -119,7 +119,7 @@ type GetIndexResponse struct {
Index json.Uint64 `json:"index"`
}

func (s *service) GetIndex(r *http.Request, args *GetIndexArgs, reply *GetIndexResponse) error {
func (s *service) GetIndex(_ *http.Request, args *GetIndexArgs, reply *GetIndexResponse) error {
index, err := s.Index.GetIndex(args.ID)
reply.Index = json.Uint64(index)
return err
Expand All @@ -133,7 +133,7 @@ type IsAcceptedResponse struct {
IsAccepted bool `json:"isAccepted"`
}

func (s *service) IsAccepted(r *http.Request, args *IsAcceptedArgs, reply *IsAcceptedResponse) error {
func (s *service) IsAccepted(_ *http.Request, args *IsAcceptedArgs, reply *IsAcceptedResponse) error {
_, err := s.Index.GetIndex(args.ID)
if err == nil {
reply.IsAccepted = true
Expand All @@ -151,7 +151,7 @@ type GetContainerByIDArgs struct {
Encoding formatting.Encoding `json:"encoding"`
}

func (s *service) GetContainerByID(r *http.Request, args *GetContainerByIDArgs, reply *FormattedContainer) error {
func (s *service) GetContainerByID(_ *http.Request, args *GetContainerByIDArgs, reply *FormattedContainer) error {
container, err := s.Index.GetContainerByID(args.ID)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion nat/no_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (noRouter) SupportsNAT() bool {
return false
}

func (noRouter) MapPort(_ string, intPort, extPort uint16, _ string, _ time.Duration) error {
func (noRouter) MapPort(string, uint16, uint16, string, time.Duration) error {
return errNoRouterCantMapPorts
}

Expand Down
2 changes: 1 addition & 1 deletion nat/pmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (r *pmpRouter) MapPort(
networkProtocol string,
newInternalPort uint16,
newExternalPort uint16,
mappingName string,
_ string,
mappingDuration time.Duration,
) error {
protocol := networkProtocol
Expand Down
2 changes: 0 additions & 2 deletions network/throttling/inbound_msg_throttler.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func NewInboundMsgThrottler(
fmt.Sprintf("%s_cpu", namespace),
registerer,
throttlerConfig.CPUThrottlerConfig,
vdrs,
resourceTracker.CPUTracker(),
cpuTargeter,
)
Expand All @@ -104,7 +103,6 @@ func NewInboundMsgThrottler(
fmt.Sprintf("%s_disk", namespace),
registerer,
throttlerConfig.DiskThrottlerConfig,
vdrs,
resourceTracker.DiskTracker(),
diskTargeter,
)
Expand Down
2 changes: 0 additions & 2 deletions network/throttling/inbound_resource_throttler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/networking/tracker"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/utils/timer/mockable"
"github.com/ava-labs/avalanchego/utils/wrappers"
)
Expand Down Expand Up @@ -92,7 +91,6 @@ func NewSystemThrottler(
namespace string,
reg prometheus.Registerer,
config SystemThrottlerConfig,
vdrs validators.Set,
tracker tracker.Tracker,
targeter tracker.Targeter,
) (SystemThrottler, error) {
Expand Down
14 changes: 3 additions & 11 deletions network/throttling/inbound_resource_throttler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/networking/tracker"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/utils/math/meter"
"github.com/ava-labs/avalanchego/utils/resource"
"github.com/ava-labs/avalanchego/utils/timer/mockable"
Expand All @@ -30,7 +29,6 @@ func TestNewSystemThrottler(t *testing.T) {
reg := prometheus.NewRegistry()
clock := mockable.Clock{}
clock.Set(time.Now())
vdrs := validators.NewSet()
resourceTracker, err := tracker.NewResourceTracker(reg, resource.NoUsage, meter.ContinuousFactory{}, time.Second)
require.NoError(err)
cpuTracker := resourceTracker.CPUTracker()
Expand All @@ -40,7 +38,7 @@ func TestNewSystemThrottler(t *testing.T) {
MaxRecheckDelay: time.Second,
}
targeter := tracker.NewMockTargeter(ctrl)
throttlerIntf, err := NewSystemThrottler("", reg, config, vdrs, cpuTracker, targeter)
throttlerIntf, err := NewSystemThrottler("", reg, config, cpuTracker, targeter)
require.NoError(err)
throttler, ok := throttlerIntf.(*systemThrottler)
require.True(ok)
Expand All @@ -62,12 +60,9 @@ func TestSystemThrottler(t *testing.T) {
config := SystemThrottlerConfig{
MaxRecheckDelay: maxRecheckDelay,
}
vdrs := validators.NewSet()
vdrID, nonVdrID := ids.GenerateTestNodeID(), ids.GenerateTestNodeID()
err := vdrs.AddWeight(vdrID, 1)
require.NoError(err)
targeter := tracker.NewMockTargeter(ctrl)
throttler, err := NewSystemThrottler("", prometheus.NewRegistry(), config, vdrs, mockTracker, targeter)
throttler, err := NewSystemThrottler("", prometheus.NewRegistry(), config, mockTracker, targeter)
require.NoError(err)

// Case: Actual usage <= target usage; should return immediately
Expand Down Expand Up @@ -148,12 +143,9 @@ func TestSystemThrottlerContextCancel(t *testing.T) {
config := SystemThrottlerConfig{
MaxRecheckDelay: maxRecheckDelay,
}
vdrs := validators.NewSet()
vdrID := ids.GenerateTestNodeID()
err := vdrs.AddWeight(vdrID, 1)
require.NoError(err)
targeter := tracker.NewMockTargeter(ctrl)
throttler, err := NewSystemThrottler("", prometheus.NewRegistry(), config, vdrs, mockTracker, targeter)
throttler, err := NewSystemThrottler("", prometheus.NewRegistry(), config, mockTracker, targeter)
require.NoError(err)

// Case: Actual usage > target usage; we should wait.
Expand Down
2 changes: 1 addition & 1 deletion pubsub/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type Server struct {
subscribedConnections *connections
}

func New(networkID uint32, log logging.Logger) *Server {
func New(log logging.Logger) *Server {
return &Server{
log: log,
conns: make(map[*connection]struct{}),
Expand Down
2 changes: 1 addition & 1 deletion snow/acceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func NewAcceptorTracker() *AcceptorTracker {
}
}

func (a *AcceptorTracker) Accept(ctx *ConsensusContext, containerID ids.ID, container []byte) error {
func (a *AcceptorTracker) Accept(_ *ConsensusContext, containerID ids.ID, _ []byte) error {
a.lock.Lock()
a.accepted[containerID]++
a.lock.Unlock()
Expand Down
14 changes: 7 additions & 7 deletions snow/consensus/snowball/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ func (b *Byzantine) Initialize(params Parameters, choice ids.ID) {
b.preference = choice
}

func (b *Byzantine) Parameters() Parameters { return b.params }
func (*Byzantine) Add(choice ids.ID) {}
func (b *Byzantine) Preference() ids.ID { return b.preference }
func (*Byzantine) RecordPoll(votes ids.Bag) bool { return false }
func (*Byzantine) RecordUnsuccessfulPoll() {}
func (*Byzantine) Finalized() bool { return true }
func (b *Byzantine) String() string { return b.preference.String() }
func (b *Byzantine) Parameters() Parameters { return b.params }
func (*Byzantine) Add(ids.ID) {}
func (b *Byzantine) Preference() ids.ID { return b.preference }
func (*Byzantine) RecordPoll(ids.Bag) bool { return false }
func (*Byzantine) RecordUnsuccessfulPoll() {}
func (*Byzantine) Finalized() bool { return true }
func (b *Byzantine) String() string { return b.preference.String() }

var (
Red = ids.Empty.Prefix(0)
Expand Down
2 changes: 1 addition & 1 deletion snow/consensus/snowstorm/acceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (a *acceptor) Fulfill(ctx context.Context, id ids.ID) {
a.Update(ctx)
}

func (a *acceptor) Abandon(_ context.Context, id ids.ID) { a.rejected = true }
func (a *acceptor) Abandon(context.Context, ids.ID) { a.rejected = true }

func (a *acceptor) Update(context.Context) {
// If I was rejected or I am still waiting on dependencies to finish or an
Expand Down
6 changes: 3 additions & 3 deletions snow/engine/common/no_ops_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func NewNoOpAppHandler(log logging.Logger) AppHandler {
return &noOpAppHandler{log: log}
}

func (nop *noOpAppHandler) CrossChainAppRequest(_ context.Context, chainID ids.ID, requestID uint32, deadline time.Time, request []byte) error {
func (nop *noOpAppHandler) CrossChainAppRequest(_ context.Context, chainID ids.ID, requestID uint32, _ time.Time, _ []byte) error {
nop.log.Debug("dropping request",
zap.String("reason", "unhandled by this gear"),
zap.Stringer("messageOp", message.CrossChainAppRequestOp),
Expand All @@ -288,7 +288,7 @@ func (nop *noOpAppHandler) CrossChainAppRequestFailed(_ context.Context, chainID
return nil
}

func (nop *noOpAppHandler) CrossChainAppResponse(_ context.Context, chainID ids.ID, requestID uint32, response []byte) error {
func (nop *noOpAppHandler) CrossChainAppResponse(_ context.Context, chainID ids.ID, requestID uint32, _ []byte) error {
nop.log.Debug("dropping request",
zap.String("reason", "unhandled by this gear"),
zap.Stringer("messageOp", message.CrossChainAppResponseOp),
Expand All @@ -298,7 +298,7 @@ func (nop *noOpAppHandler) CrossChainAppResponse(_ context.Context, chainID ids.
return nil
}

func (nop *noOpAppHandler) AppRequest(_ context.Context, nodeID ids.NodeID, requestID uint32, deadline time.Time, _ []byte) error {
func (nop *noOpAppHandler) AppRequest(_ context.Context, nodeID ids.NodeID, requestID uint32, _ time.Time, _ []byte) error {
nop.log.Debug("dropping request",
zap.String("reason", "unhandled by this gear"),
zap.Stringer("messageOp", message.AppRequestOp),
Expand Down
Loading

0 comments on commit 3a7ebb1

Please sign in to comment.