From 87c60728dba03c7a1d3d6976e7b43fdbda099fb0 Mon Sep 17 00:00:00 2001 From: Martin Tomazic Date: Sat, 25 Jan 2025 22:51:31 +0100 Subject: [PATCH] Bump golangci-lint to 1.63.4 --- .changelog/6011.internal.md | 1 + docker/oasis-core-dev/Dockerfile | 2 +- go/common/crypto/signature/signer.go | 4 +-- go/consensus/cometbft/api/gas.go | 8 ++--- go/consensus/cometbft/api/genesis.go | 7 ++-- .../cometbft/apps/roothash/state/state.go | 6 ++-- .../supplementarysanity.go | 4 +-- go/oasis-node/cmd/stake/delegations.go | 8 ++--- go/oasis-test-runner/cmd/cmp/cmp.go | 16 ++++------ go/p2p/api/api.go | 2 +- go/p2p/discovery/peerstore/peerstore.go | 12 +++---- go/p2p/p2p.go | 4 +-- go/p2p/peermgmt/connector.go | 12 +++---- go/p2p/peermgmt/peermgr.go | 32 +++++++++---------- go/p2p/rpc/rpc.go | 2 +- go/runtime/host/tdx/qemu.go | 2 +- 16 files changed, 57 insertions(+), 65 deletions(-) create mode 100644 .changelog/6011.internal.md diff --git a/.changelog/6011.internal.md b/.changelog/6011.internal.md new file mode 100644 index 00000000000..099725e1f00 --- /dev/null +++ b/.changelog/6011.internal.md @@ -0,0 +1 @@ +Bump golangci-lint to 1.63.4 diff --git a/docker/oasis-core-dev/Dockerfile b/docker/oasis-core-dev/Dockerfile index a85a2f0a14a..33ba4d52050 100644 --- a/docker/oasis-core-dev/Dockerfile +++ b/docker/oasis-core-dev/Dockerfile @@ -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 diff --git a/go/common/crypto/signature/signer.go b/go/common/crypto/signature/signer.go index 97aca71260e..b3900096406 100644 --- a/go/common/crypto/signature/signer.go +++ b/go/common/crypto/signature/signer.go @@ -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 } } diff --git a/go/consensus/cometbft/api/gas.go b/go/consensus/cometbft/api/gas.go index 9da1ebe2358..9b46900a183 100644 --- a/go/consensus/cometbft/api/gas.go +++ b/go/consensus/cometbft/api/gas.go @@ -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 diff --git a/go/consensus/cometbft/api/genesis.go b/go/consensus/cometbft/api/genesis.go index 9c0e92871f4..0753d4d0d25 100644 --- a/go/consensus/cometbft/api/genesis.go +++ b/go/consensus/cometbft/api/genesis.go @@ -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 } diff --git a/go/consensus/cometbft/apps/roothash/state/state.go b/go/consensus/cometbft/apps/roothash/state/state.go index 401432c99a7..4fb9ea89339 100644 --- a/go/consensus/cometbft/apps/roothash/state/state.go +++ b/go/consensus/cometbft/apps/roothash/state/state.go @@ -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) @@ -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) diff --git a/go/consensus/cometbft/apps/supplementarysanity/supplementarysanity.go b/go/consensus/cometbft/apps/supplementarysanity/supplementarysanity.go index 3ac090a7104..579cdb4bc36 100644 --- a/go/consensus/cometbft/apps/supplementarysanity/supplementarysanity.go +++ b/go/consensus/cometbft/apps/supplementarysanity/supplementarysanity.go @@ -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", diff --git a/go/oasis-node/cmd/stake/delegations.go b/go/oasis-node/cmd/stake/delegations.go index 36e38fb73fb..a3ee07166d5 100644 --- a/go/oasis-node/cmd/stake/delegations.go +++ b/go/oasis-node/cmd/stake/delegations.go @@ -60,13 +60,11 @@ func delegationAmount(shares quantity.Quantity, sharePool api.SharePool) quantit // lenLongestString returns the length of the longest string passed to it. func lenLongestString(strs ...string) int { - max := 0 + maxLen := 0 for _, s := range strs { - if len(s) > max { - max = len(s) - } + maxLen = max(maxLen, len(s)) } - return max + return maxLen } // prettyPrintDelegationDescriptions pretty-prints the given list of delegation diff --git a/go/oasis-test-runner/cmd/cmp/cmp.go b/go/oasis-test-runner/cmd/cmp/cmp.go index 08c60506b27..0934c15f844 100644 --- a/go/oasis-test-runner/cmd/cmp/cmp.go +++ b/go/oasis-test-runner/cmd/cmp/cmp.go @@ -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 @@ -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, diff --git a/go/p2p/api/api.go b/go/p2p/api/api.go index a0686705fb1..9b0e3d22a1f 100644 --- a/go/p2p/api/api.go +++ b/go/p2p/api/api.go @@ -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) diff --git a/go/p2p/discovery/peerstore/peerstore.go b/go/p2p/discovery/peerstore/peerstore.go index 41c1c00fa80..c98768cdcfe 100644 --- a/go/p2p/discovery/peerstore/peerstore.go +++ b/go/p2p/discovery/peerstore/peerstore.go @@ -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 } } diff --git a/go/p2p/p2p.go b/go/p2p/p2p.go index e1b30242ab5..4fa195ff5f9 100644 --- a/go/p2p/p2p.go +++ b/go/p2p/p2p.go @@ -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. diff --git a/go/p2p/peermgmt/connector.go b/go/p2p/peermgmt/connector.go index 8baa2656260..76131460d05 100644 --- a/go/p2p/peermgmt/connector.go +++ b/go/p2p/peermgmt/connector.go @@ -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 } @@ -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 } @@ -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 } } diff --git a/go/p2p/peermgmt/peermgr.go b/go/p2p/peermgmt/peermgr.go index c809cdea1b1..d6b675ee5f1 100644 --- a/go/p2p/peermgmt/peermgr.go +++ b/go/p2p/peermgmt/peermgr.go @@ -173,59 +173,59 @@ func (m *PeerManager) NumTopicPeers(topic string) int { // 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 m.logger.Debug("topic updated", "topic", topic, - "min", min, - "total", total, + "min_peers", minPeers, + "total_peers", totalPeers, ) 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, ) } diff --git a/go/p2p/rpc/rpc.go b/go/p2p/rpc/rpc.go index e59331e105d..a51285a2a26 100644 --- a/go/p2p/rpc/rpc.go +++ b/go/p2p/rpc/rpc.go @@ -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 diff --git a/go/runtime/host/tdx/qemu.go b/go/runtime/host/tdx/qemu.go index 1a190ae43f1..6739c292314 100644 --- a/go/runtime/host/tdx/qemu.go +++ b/go/runtime/host/tdx/qemu.go @@ -294,7 +294,7 @@ func (q *qemuProvisioner) createPersistentOverlayImage( 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) { defer func() { sgxCommon.UpdateAttestationMetrics(hp.Runtime.ID(), component.TEEKindTDX, aerr) }()