Skip to content

Commit

Permalink
go: Fix make lint command
Browse files Browse the repository at this point in the history
  • Loading branch information
martintomazic committed Jan 26, 2025
1 parent 6355ca3 commit a89d279
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 54 deletions.
Empty file added .changelog/6011.trivial.md
Empty file.
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
8 changes: 4 additions & 4 deletions go/consensus/cometbft/api/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ 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)
maxVal := d.Scheduler.Parameters.MaxValidators
if maxVal > len(tmValidators) {
maxVal = len(tmValidators)
}
return tmValidators[:max], nil
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: 4 additions & 4 deletions go/oasis-node/cmd/stake/delegations.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ 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)
if len(s) > maxLen {
maxLen = len(s)
}
}
return max
return maxLen
}

// prettyPrintDelegationDescriptions pretty-prints the given list of delegation
Expand Down
16 changes: 8 additions & 8 deletions go/oasis-test-runner/cmd/cmp/cmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,16 @@ 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)
if maximum < float64(s.Value) {
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 +315,18 @@ 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)
if maximum < float64(s.Values[len(s.Values)-1].Value-s.Values[0].Value) {
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, total 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, total int) {
p.peerMgr.RegisterProtocol(pid, minPeers, total)
}

// 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
20 changes: 10 additions & 10 deletions go/p2p/peermgmt/peermgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,58 +173,58 @@ 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, total int) {
m.mu.Lock()
defer m.mu.Unlock()

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

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

return
}

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

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

// 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, total int) {
m.mu.Lock()
defer m.mu.Unlock()

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

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

return
}

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

m.logger.Debug("topic registered",
"topic", topic,
"min", min,
"min_peers", minPeers,
"total", total,
)
}
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, total 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 @@ 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)
}()
Expand Down

0 comments on commit a89d279

Please sign in to comment.