Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump golangci-lint to 1.63.4 #6011

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/6011.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bump golangci-lint to 1.63.4
2 changes: 1 addition & 1 deletion docker/oasis-core-dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ARG GO_NANCY_VERSION=1.0.33
ARG GO_NANCY_CHECKSUM=a4bf5290d41b095c04f941ed5380674770c79d59735e33b1bd07a5cd5fbb135d
ARG GO_PROTOC_VERSION=3.6.1
ARG GO_PROTOC_GEN_GO_VERSION=1.21.0
ARG GOLANGCILINT_VERSION=1.61.0
ARG GOLANGCILINT_VERSION=1.63.4
ARG GOCOVMERGE_VERSION=b5bfa59ec0adc420475f97f89b58045c721d761c
ARG GOFUMPT_VERSION=v0.6.0
ARG GOIMPORTS_VERSION=v0.18.0
Expand Down
4 changes: 2 additions & 2 deletions go/common/crypto/signature/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ func WithChainSeparation() ContextOption {

// WithDynamicSuffix is a context option that configures the context to use
// a dynamic suffix.
func WithDynamicSuffix(str string, len int) ContextOption {
func WithDynamicSuffix(str string, maxLen int) ContextOption {
return func(o *contextOptions) {
o.dynamicSuffix = str
o.dynamicSuffixMaxLen = len
o.dynamicSuffixMaxLen = maxLen
}
}

Expand Down
8 changes: 4 additions & 4 deletions go/consensus/cometbft/api/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ func (ga *compositeGasAccountant) GasWanted() transaction.Gas {
}

func (ga *compositeGasAccountant) GasUsed() transaction.Gas {
var max transaction.Gas
var maxGas transaction.Gas
for _, a := range ga.accts {
if g := a.GasUsed(); g > max {
max = g
if g := a.GasUsed(); g > maxGas {
maxGas = g
}
}
return max
return maxGas
}

// NewCompositeGasAccountant creates a gas accountant that is composed
Expand Down
7 changes: 2 additions & 5 deletions go/consensus/cometbft/api/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,6 @@ func convertValidators(d *genesis.Document) ([]cmttypes.GenesisValidator, error)
})

// Keep only the first MaxValidators validators.
max := d.Scheduler.Parameters.MaxValidators
if max > len(tmValidators) {
max = len(tmValidators)
}
return tmValidators[:max], nil
maxVal := min(d.Scheduler.Parameters.MaxValidators, len(tmValidators))
return tmValidators[:maxVal], nil
}
6 changes: 3 additions & 3 deletions go/consensus/cometbft/apps/roothash/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func (s *MutableState) SetRuntimeState(ctx context.Context, state *roothash.Runt
//
// This is used when reducing the MaxPastRootsStored consensus parameter in
// changeParameters() in go/consensus/cometbft/apps/roothash/messages.go.
func (s *MutableState) ShrinkPastRoots(ctx context.Context, max uint64) error {
func (s *MutableState) ShrinkPastRoots(ctx context.Context, maxStoredRoots uint64) error {
// Go through all runtimes, so we can delete extra stored past
// roots for each one, where it's needed.
runtimes, err := s.Runtimes(ctx)
Expand All @@ -447,12 +447,12 @@ func (s *MutableState) ShrinkPastRoots(ctx context.Context, max uint64) error {
for _, r := range runtimes {
id := r.Runtime.ID
numStoredRoots := s.PastRoundRootsCount(ctx, id)
if numStoredRoots <= max {
if numStoredRoots <= maxStoredRoots {
// Nothing to delete.
continue
}

numPastRootsToDelete := numStoredRoots - max
numPastRootsToDelete := numStoredRoots - maxStoredRoots

it := s.is.NewIterator(ctx)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func (app *supplementarySanityApplication) endBlockImpl(ctx *api.Context) error

newInterval := height / app.interval
if newInterval != app.currentInterval {
min := height % app.interval
offset := rand.Int63n(app.interval-min) + min
minimum := height % app.interval
offset := rand.Int63n(app.interval-minimum) + minimum
app.currentInterval = newInterval
app.checkHeight = newInterval*app.interval + offset
logger.Debug("Entering new interval",
Expand Down
8 changes: 3 additions & 5 deletions go/oasis-node/cmd/stake/delegations.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@

// lenLongestString returns the length of the longest string passed to it.
func lenLongestString(strs ...string) int {
max := 0
maxLen := 0

Check warning on line 63 in go/oasis-node/cmd/stake/delegations.go

View check run for this annotation

Codecov / codecov/patch

go/oasis-node/cmd/stake/delegations.go#L63

Added line #L63 was not covered by tests
for _, s := range strs {
if len(s) > max {
max = len(s)
}
maxLen = max(maxLen, len(s))

Check warning on line 65 in go/oasis-node/cmd/stake/delegations.go

View check run for this annotation

Codecov / codecov/patch

go/oasis-node/cmd/stake/delegations.go#L65

Added line #L65 was not covered by tests
}
return max
return maxLen

Check warning on line 67 in go/oasis-node/cmd/stake/delegations.go

View check run for this annotation

Codecov / codecov/patch

go/oasis-node/cmd/stake/delegations.go#L67

Added line #L67 was not covered by tests
}

// prettyPrintDelegationDescriptions pretty-prints the given list of delegation
Expand Down
16 changes: 6 additions & 10 deletions go/oasis-test-runner/cmd/cmp/cmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,14 @@ func getSummableMetric(

// Compute average and max values.
avg := 0.0
max := 0.0
maximum := 0.0
for _, s := range result.(model.Vector) {
avg += float64(s.Value)
if max < float64(s.Value) {
max = float64(s.Value)
}
maximum = max(maximum, float64(s.Value))
}
avg /= float64(len(result.(model.Vector)))

return avg, max, nil
return avg, maximum, nil
}

// getNetwork returns average and maximum amount of network activity for all
Expand Down Expand Up @@ -315,18 +313,16 @@ func getNetwork(

// Compute average and max values.
avg := 0.0
max := 0.0
maximum := 0.0
for _, s := range result.(model.Matrix) {
// Network traffic is difference between last and first reading.
avg += float64(s.Values[len(s.Values)-1].Value - s.Values[0].Value)
if max < float64(s.Values[len(s.Values)-1].Value-s.Values[0].Value) {
max = float64(s.Values[len(s.Values)-1].Value - s.Values[0].Value)
}
maximum = max(maximum, float64(s.Values[len(s.Values)-1].Value-s.Values[0].Value))
}
avg /= float64(len(result.(model.Matrix)))

bytesTotalAvg[rxtx] = avg
bytesTotalMax[rxtx] = max
bytesTotalMax[rxtx] = maximum
}

return (bytesTotalAvg[metrics.MetricNetReceiveBytesTotal] + bytesTotalAvg[metrics.MetricNetTransmitBytesTotal]) / 2.0,
Expand Down
2 changes: 1 addition & 1 deletion go/p2p/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type Service interface {
PeerManager() PeerManager

// RegisterProtocol starts tracking and managing peers that support the given protocol.
RegisterProtocol(p core.ProtocolID, min int, total int)
RegisterProtocol(p core.ProtocolID, minPeers int, totalPeers int)

// RegisterProtocolServer registers a protocol server for the given protocol.
RegisterProtocolServer(srv rpc.Server)
Expand Down
12 changes: 6 additions & 6 deletions go/p2p/discovery/peerstore/peerstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@ type StoreOptions struct {
type StoreOption func(opts *StoreOptions)

// WithMaxPeers configures maximum number of peers.
func WithMaxPeers(max int) StoreOption {
func WithMaxPeers(n int) StoreOption {
return func(opts *StoreOptions) {
opts.maxPeers = max
opts.maxPeers = n
}
}

// WithMaxNamespacePeers configures maximum number of peers in a namespace.
func WithMaxNamespacePeers(max int) StoreOption {
func WithMaxNamespacePeers(n int) StoreOption {
return func(opts *StoreOptions) {
opts.maxNsPeers = max
opts.maxNsPeers = n
}
}

// WithMaxPeerNamespaces configures maximum number of peer's namespaces.
func WithMaxPeerNamespaces(max int) StoreOption {
func WithMaxPeerNamespaces(n int) StoreOption {
return func(opts *StoreOptions) {
opts.maxPeerNs = max
opts.maxPeerNs = n
}
}

Expand Down
4 changes: 2 additions & 2 deletions go/p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ func (p *p2p) BlockPeer(peerID core.PeerID) {
}

// Implements api.Service.
func (p *p2p) RegisterProtocol(pid core.ProtocolID, min int, total int) {
p.peerMgr.RegisterProtocol(pid, min, total)
func (p *p2p) RegisterProtocol(pid core.ProtocolID, minPeers int, totalPeers int) {
p.peerMgr.RegisterProtocol(pid, minPeers, totalPeers)
}

// Implements api.Service.
Expand Down
12 changes: 6 additions & 6 deletions go/p2p/peermgmt/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func newPeerConnector(h host.Host, g connmgr.ConnectionGater) *peerConnector {
//
// Note that at the end more than max number of peers from the given list can be connected as some
// of them might already be connected prior the method call or connected via some other means.
func (c *peerConnector) connectMany(ctx context.Context, peersCh <-chan peer.AddrInfo, max int) {
if max <= 0 {
func (c *peerConnector) connectMany(ctx context.Context, peersCh <-chan peer.AddrInfo, maxPeers int) {
if maxPeers <= 0 {
return
}

Expand All @@ -68,8 +68,8 @@ func (c *peerConnector) connectMany(ctx context.Context, peersCh <-chan peer.Add

// Try connecting to peers in parallel until enough connections are established.
// Note that connections are throttled inside libp2p package.
ticketCh := make(chan bool, max)
for i := 0; i < max; i++ {
ticketCh := make(chan bool, maxPeers)
for i := 0; i < maxPeers; i++ {
ticketCh <- false
}

Expand Down Expand Up @@ -104,8 +104,8 @@ func (c *peerConnector) connectMany(ctx context.Context, peersCh <-chan peer.Add
break
}

max--
if max == 0 {
maxPeers--
if maxPeers == 0 {
return
}
}
Expand Down
32 changes: 16 additions & 16 deletions go/p2p/peermgmt/peermgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,59 +173,59 @@

// RegisterProtocol starts tracking and managing peers that support the given protocol.
// If the protocol is already registered, its values are updated.
func (m *PeerManager) RegisterProtocol(p core.ProtocolID, min int, total int) {
func (m *PeerManager) RegisterProtocol(p core.ProtocolID, minPeers int, totalPeers int) {
m.mu.Lock()
defer m.mu.Unlock()

if w, ok := m.protocols[p]; ok {
w.min = min
w.total = total
w.min = minPeers
w.total = totalPeers

m.logger.Debug("protocol updated",
"protocol", p,
"min", min,
"total", total,
"min_peers", minPeers,
"total_peers", totalPeers,
)

return
}

m.protocols[p] = &watermark{min, total}
m.protocols[p] = &watermark{minPeers, totalPeers}
m.discovery.startAdvertising(string(p))

m.logger.Debug("protocol registered",
"protocol", p,
"min", min,
"total", total,
"min_peers", minPeers,
"total_peers", totalPeers,
)
}

// RegisterTopic starts tracking and managing peers that support the given topic.
// If the topic is already registered, its values are updated.
func (m *PeerManager) RegisterTopic(topic string, min int, total int) {
func (m *PeerManager) RegisterTopic(topic string, minPeers int, totalPeers int) {
m.mu.Lock()
defer m.mu.Unlock()

if data, ok := m.topics[topic]; ok {
data.min = min
data.total = total
data.min = minPeers
data.total = totalPeers

Check warning on line 211 in go/p2p/peermgmt/peermgr.go

View check run for this annotation

Codecov / codecov/patch

go/p2p/peermgmt/peermgr.go#L210-L211

Added lines #L210 - L211 were not covered by tests

m.logger.Debug("topic updated",
"topic", topic,
"min", min,
"total", total,
"min_peers", minPeers,
"total_peers", totalPeers,

Check warning on line 216 in go/p2p/peermgmt/peermgr.go

View check run for this annotation

Codecov / codecov/patch

go/p2p/peermgmt/peermgr.go#L215-L216

Added lines #L215 - L216 were not covered by tests
)

return
}

m.topics[topic] = &watermark{min, total}
m.topics[topic] = &watermark{minPeers, totalPeers}
m.discovery.startAdvertising(topic)

m.logger.Debug("topic registered",
"topic", topic,
"min", min,
"total", total,
"min_peers", minPeers,
"total_peers", totalPeers,
)
}

Expand Down
2 changes: 1 addition & 1 deletion go/p2p/rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type P2P interface {
BlockPeer(peerID core.PeerID)

// RegisterProtocol starts tracking and managing peers that support given protocol.
RegisterProtocol(p core.ProtocolID, min int, total int)
RegisterProtocol(p core.ProtocolID, minPeers int, totalPeers int)

// Host returns the P2P host.
Host() core.Host
Expand Down
2 changes: 1 addition & 1 deletion go/runtime/host/tdx/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
return imageFn, nil
}

func (q *qemuProvisioner) updateCapabilityTEE(ctx context.Context, hp *sandbox.HostInitializerParams) (cap *node.CapabilityTEE, aerr error) {
func (q *qemuProvisioner) updateCapabilityTEE(ctx context.Context, hp *sandbox.HostInitializerParams) (capTEE *node.CapabilityTEE, aerr error) {

Check warning on line 297 in go/runtime/host/tdx/qemu.go

View check run for this annotation

Codecov / codecov/patch

go/runtime/host/tdx/qemu.go#L297

Added line #L297 was not covered by tests
defer func() {
sgxCommon.UpdateAttestationMetrics(hp.Runtime.ID(), component.TEEKindTDX, aerr)
}()
Expand Down
Loading