diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index b3266996b..5ca39435b 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -6,7 +6,6 @@ on: - 'documentation/**' - 'scripts/**' - 'tools/**' - jobs: golangci-lint: name: GolangCI-Lint @@ -15,12 +14,26 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v3 + - name: Checkout custom linter + uses: actions/checkout@v3 + with: + repository: karimodm/typegroupingcheck + path: typegroupingcheck + + - name: Setup go + uses: actions/setup-go@v4 + with: + go-version-file: './typegroupingcheck/go.mod' + + - name: Build custom linter + working-directory: ./typegroupingcheck + run: | + go build -buildmode=plugin -o typegroupingcheck.so + - name: golangci-lint - uses: reviewdog/action-golangci-lint@v2 + uses: golangci/golangci-lint-action@v3 with: - version: v1.53.3 - github_token: ${{ secrets.GITHUB_TOKEN }} - golangci_lint_flags: "--timeout=10m" - reporter: github-pr-check - filter_mode: nofilter - fail_on_error: true + skip-cache: true + version: latest + install-mode: goinstall + args: --timeout=10m --enable typegroupingcheck diff --git a/.golangci.yml b/.golangci.yml index 6000e9feb..535edcf10 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -33,12 +33,17 @@ linters-settings: desc: Should be replaced with "github.com/iotaledger/hive.go/ierrors" package - pkg: "github.com/pkg/errors" desc: Should be replaced with "github.com/iotaledger/hive.go/ierrors" package + custom: + typegroupingcheck: + path: ./typegroupingcheck/typegroupingcheck.so + description: Check for grouped types in functions' parameters linters: # Disable all linters. disable-all: true # Enable specific linter enable: + #- typegroupingcheck - errcheck - gosimple - govet diff --git a/components/metrics/collector/collector.go b/components/metrics/collector/collector.go index 88776c0b9..c195d80ba 100644 --- a/components/metrics/collector/collector.go +++ b/components/metrics/collector/collector.go @@ -44,7 +44,7 @@ func (c *Collector) Collect() { // Update updates the value of the existing metric defined by the subsystem and metricName. // Note that the label values must be passed in the same order as they were defined in the metric, and must match the // number of labels defined in the metric. -func (c *Collector) Update(subsystem, metricName string, metricValue float64, labelValues ...string) { +func (c *Collector) Update(subsystem string, metricName string, metricValue float64, labelValues ...string) { m := c.getMetric(subsystem, metricName) if m != nil { m.update(metricValue, labelValues...) @@ -54,7 +54,7 @@ func (c *Collector) Update(subsystem, metricName string, metricValue float64, la // Increment increments the value of the existing metric defined by the subsystem and metricName. // Note that the label values must be passed in the same order as they were defined in the metric, and must match the // number of labels defined in the metric. -func (c *Collector) Increment(subsystem, metricName string, labels ...string) { +func (c *Collector) Increment(subsystem string, metricName string, labels ...string) { m := c.getMetric(subsystem, metricName) if m != nil { m.increment(labels...) @@ -62,7 +62,7 @@ func (c *Collector) Increment(subsystem, metricName string, labels ...string) { } // DeleteLabels deletes the metric with the given labels values. -func (c *Collector) DeleteLabels(subsystem, metricName string, labelValues map[string]string) { +func (c *Collector) DeleteLabels(subsystem string, metricName string, labelValues map[string]string) { m := c.getMetric(subsystem, metricName) if m != nil { m.deleteLabels(labelValues) @@ -85,7 +85,7 @@ func (c *Collector) Shutdown() { } } -func (c *Collector) getMetric(subsystem, metricName string) *Metric { +func (c *Collector) getMetric(subsystem string, metricName string) *Metric { col := c.getCollection(subsystem) if col != nil { return col.GetMetric(metricName) diff --git a/pkg/core/account/seated_accounts.go b/pkg/core/account/seated_accounts.go index 070eda6e4..6d04e5d1b 100644 --- a/pkg/core/account/seated_accounts.go +++ b/pkg/core/account/seated_accounts.go @@ -35,7 +35,7 @@ func NewSeatedAccounts(accounts *Accounts, optMembers ...iotago.AccountID) *Seat accounts: accounts, seatsByAccount: shrinkingmap.New[iotago.AccountID, SeatIndex](), } - sort.Slice(optMembers, func(i, j int) bool { + sort.Slice(optMembers, func(i int, j int) bool { return bytes.Compare(optMembers[i][:], optMembers[j][:]) < 0 }) diff --git a/pkg/protocol/block_dispatcher.go b/pkg/protocol/block_dispatcher.go index 0a79a0d51..74ab0a65a 100644 --- a/pkg/protocol/block_dispatcher.go +++ b/pkg/protocol/block_dispatcher.go @@ -311,7 +311,7 @@ func (b *BlockDispatcher) processWarpSyncResponse(commitmentID iotago.Commitment } } - blockBookedFunc := func(_, _ bool) { + blockBookedFunc := func(_ bool, _ bool) { if bookedBlocks.Add(1) != totalBlocks { return } @@ -330,7 +330,7 @@ func (b *BlockDispatcher) processWarpSyncResponse(commitmentID iotago.Commitment targetEngine.BlockGadget.SetAccepted(block) - block.Notarized().OnUpdate(func(_, _ bool) { + block.Notarized().OnUpdate(func(_ bool, _ bool) { // Wait for all blocks to be notarized before forcing the commitment of the slot. if notarizedBlocks.Add(1) != totalBlocks { return diff --git a/pkg/protocol/chainmanager/manager.go b/pkg/protocol/chainmanager/manager.go index 0813d0ed4..e70b7b9dc 100644 --- a/pkg/protocol/chainmanager/manager.go +++ b/pkg/protocol/chainmanager/manager.go @@ -309,7 +309,7 @@ func (m *Manager) getOrCreateCommitment(id iotago.CommitmentID) (commitment *Cha }) } -func (m *Manager) evaluateAgainstRootCommitment(commitment *iotago.Commitment) (isBelow, isRootCommitment bool) { +func (m *Manager) evaluateAgainstRootCommitment(commitment *iotago.Commitment) (isBelow bool, isRootCommitment bool) { isBelow = commitment.Slot <= m.rootCommitment.Commitment().Slot() isRootCommitment = commitment.Equals(m.rootCommitment.Commitment().Commitment()) diff --git a/pkg/protocol/engine/blockdag/inmemoryblockdag/blockdag.go b/pkg/protocol/engine/blockdag/inmemoryblockdag/blockdag.go index 6fe5944b0..7164679ca 100644 --- a/pkg/protocol/engine/blockdag/inmemoryblockdag/blockdag.go +++ b/pkg/protocol/engine/blockdag/inmemoryblockdag/blockdag.go @@ -82,7 +82,7 @@ func (b *BlockDAG) setupBlock(block *blocks.Block) { return } - parentBlock.Solid().OnUpdateOnce(func(_, _ bool) { + parentBlock.Solid().OnUpdateOnce(func(_ bool, _ bool) { if unsolidParentsCount.Add(-1) == 0 { if block.SetSolid() { b.events.BlockSolid.Trigger(block) @@ -90,7 +90,7 @@ func (b *BlockDAG) setupBlock(block *blocks.Block) { } }) - parentBlock.Invalid().OnUpdateOnce(func(_, _ bool) { + parentBlock.Invalid().OnUpdateOnce(func(_ bool, _ bool) { if block.SetInvalid() { b.events.BlockInvalid.Trigger(block, ierrors.Errorf("parent block %s is marked as invalid", parent.ID)) } diff --git a/pkg/protocol/engine/blocks/blocks.go b/pkg/protocol/engine/blocks/blocks.go index 00560fc36..3b534a74f 100644 --- a/pkg/protocol/engine/blocks/blocks.go +++ b/pkg/protocol/engine/blocks/blocks.go @@ -51,7 +51,7 @@ func (b *Blocks) Block(id iotago.BlockID) (block *Block, exists bool) { return storage.Get(id) } -func (b *Blocks) StoreOrUpdate(data *model.Block) (storedBlock *Block, evicted, updated bool) { +func (b *Blocks) StoreOrUpdate(data *model.Block) (storedBlock *Block, evicted bool, updated bool) { b.evictionMutex.RLock() defer b.evictionMutex.RUnlock() diff --git a/pkg/protocol/engine/booker/inmemorybooker/booker.go b/pkg/protocol/engine/booker/inmemorybooker/booker.go index 99dbae5cd..2b9196ff1 100644 --- a/pkg/protocol/engine/booker/inmemorybooker/booker.go +++ b/pkg/protocol/engine/booker/inmemorybooker/booker.go @@ -132,7 +132,7 @@ func (b *Booker) setupBlock(block *blocks.Block) { return } - parentBlock.Booked().OnUpdateOnce(func(_, _ bool) { + parentBlock.Booked().OnUpdateOnce(func(_ bool, _ bool) { if unbookedParentsCount.Add(-1) == 0 { if err := b.book(block); err != nil { if block.SetInvalid() { @@ -142,7 +142,7 @@ func (b *Booker) setupBlock(block *blocks.Block) { } }) - parentBlock.Invalid().OnUpdateOnce(func(_, _ bool) { + parentBlock.Invalid().OnUpdateOnce(func(_ bool, _ bool) { if block.SetInvalid() { b.events.BlockInvalid.Trigger(block, ierrors.New("block marked as invalid in Booker")) } diff --git a/pkg/protocol/engine/eviction/state.go b/pkg/protocol/engine/eviction/state.go index 935bd15a2..063f22923 100644 --- a/pkg/protocol/engine/eviction/state.go +++ b/pkg/protocol/engine/eviction/state.go @@ -258,7 +258,7 @@ func (s *State) Import(reader io.ReadSeeker) error { return nil } -func (s *State) Rollback(lowerTarget, targetIndex iotago.SlotIndex) error { +func (s *State) Rollback(lowerTarget iotago.SlotIndex, targetIndex iotago.SlotIndex) error { s.evictionMutex.RLock() defer s.evictionMutex.RUnlock() @@ -313,7 +313,7 @@ func (s *State) setLatestNonEmptySlot(slot iotago.SlotIndex) { } } -func (s *State) activeIndexRange() (startSlot, endSlot iotago.SlotIndex) { +func (s *State) activeIndexRange() (startSlot iotago.SlotIndex, endSlot iotago.SlotIndex) { lastCommittedSlot := s.lastEvictedSlot delayedSlot, valid := s.delayedBlockEvictionThreshold(lastCommittedSlot) diff --git a/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/conflict.go b/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/conflict.go index d943bbb7c..812faac2b 100644 --- a/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/conflict.go +++ b/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/conflict.go @@ -137,7 +137,7 @@ func (c *Conflict[ConflictID, ResourceID, VoteRank]) JoinConflictSets(conflictSe return nil, ierrors.Errorf("tried to join conflict sets of evicted conflict: %w", conflictdag.ErrEntityEvicted) } - registerConflictingConflict := func(c, conflict *Conflict[ConflictID, ResourceID, VoteRank]) { + registerConflictingConflict := func(c *Conflict[ConflictID, ResourceID, VoteRank], conflict *Conflict[ConflictID, ResourceID, VoteRank]) { c.structureMutex.Lock() defer c.structureMutex.Unlock() @@ -180,7 +180,7 @@ func (c *Conflict[ConflictID, ResourceID, VoteRank]) removeParent(parent *Confli } // UpdateParents updates the parents of the Conflict. -func (c *Conflict[ConflictID, ResourceID, VoteRank]) UpdateParents(addedParents, removedParents ds.Set[*Conflict[ConflictID, ResourceID, VoteRank]]) (updated bool) { +func (c *Conflict[ConflictID, ResourceID, VoteRank]) UpdateParents(addedParents ds.Set[*Conflict[ConflictID, ResourceID, VoteRank]], removedParents ds.Set[*Conflict[ConflictID, ResourceID, VoteRank]]) (updated bool) { c.structureMutex.Lock() defer c.structureMutex.Unlock() @@ -389,7 +389,7 @@ func (c *Conflict[ConflictID, ResourceID, VoteRank]) registerChild(child *Confli defer c.likedInsteadMutex.Unlock() c.childUnhookMethods.Set(child.ID, lo.Batch( - c.AcceptanceStateUpdated.Hook(func(_, newState acceptance.State) { + c.AcceptanceStateUpdated.Hook(func(_ acceptance.State, newState acceptance.State) { if newState.IsRejected() { child.setAcceptanceState(newState) } @@ -432,7 +432,7 @@ func (c *Conflict[ConflictID, ResourceID, VoteRank]) unregisterChild(conflict *C } // addInheritedLikedInsteadReference adds the given reference as a liked instead reference from the given source. -func (c *Conflict[ConflictID, ResourceID, VoteRank]) addInheritedLikedInsteadReference(source, reference *Conflict[ConflictID, ResourceID, VoteRank]) { +func (c *Conflict[ConflictID, ResourceID, VoteRank]) addInheritedLikedInsteadReference(source *Conflict[ConflictID, ResourceID, VoteRank], reference *Conflict[ConflictID, ResourceID, VoteRank]) { c.likedInsteadMutex.Lock() defer c.likedInsteadMutex.Unlock() @@ -451,7 +451,7 @@ func (c *Conflict[ConflictID, ResourceID, VoteRank]) addInheritedLikedInsteadRef } // removeInheritedLikedInsteadReference removes the given reference as a liked instead reference from the given source. -func (c *Conflict[ConflictID, ResourceID, VoteRank]) removeInheritedLikedInsteadReference(source, reference *Conflict[ConflictID, ResourceID, VoteRank]) { +func (c *Conflict[ConflictID, ResourceID, VoteRank]) removeInheritedLikedInsteadReference(source *Conflict[ConflictID, ResourceID, VoteRank], reference *Conflict[ConflictID, ResourceID, VoteRank]) { c.likedInsteadMutex.Lock() defer c.likedInsteadMutex.Unlock() diff --git a/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/conflictdag.go b/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/conflictdag.go index 88306cc12..01f102a9b 100644 --- a/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/conflictdag.go +++ b/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/conflictdag.go @@ -86,7 +86,7 @@ func (c *ConflictDAG[ConflictID, ResourceID, VoteRank]) CreateConflict(id Confli // attach to the acceptance state updated event and propagate that event to the outside. // also need to remember the unhook method to properly evict the conflict. - c.conflictUnhooks.Set(id, newConflict.AcceptanceStateUpdated.Hook(func(oldState, newState acceptance.State) { + c.conflictUnhooks.Set(id, newConflict.AcceptanceStateUpdated.Hook(func(_ acceptance.State, newState acceptance.State) { if newState.IsAccepted() { c.events.ConflictAccepted.Trigger(newConflict.ID) return @@ -117,7 +117,6 @@ func (c *ConflictDAG[ConflictID, ResourceID, VoteRank]) UpdateConflictingResourc return conflict.JoinConflictSets(c.conflictSets(resourceIDs)) }() - if err != nil { return ierrors.Errorf("conflict %s failed to join conflict sets: %w", id, err) } @@ -140,7 +139,7 @@ func (c *ConflictDAG[ConflictID, ResourceID, VoteRank]) ReadConsistent(callback } // UpdateConflictParents updates the parents of the given Conflict and returns an error if the operation failed. -func (c *ConflictDAG[ConflictID, ResourceID, VoteRank]) UpdateConflictParents(conflictID ConflictID, addedParentIDs, removedParentIDs ds.Set[ConflictID]) error { +func (c *ConflictDAG[ConflictID, ResourceID, VoteRank]) UpdateConflictParents(conflictID ConflictID, addedParentIDs ds.Set[ConflictID], removedParentIDs ds.Set[ConflictID]) error { newParents := ds.NewSet[ConflictID]() updated, err := func() (bool, error) { @@ -449,7 +448,7 @@ func (c *ConflictDAG[ConflictID, ResourceID, VoteRank]) conflictSets(resourceIDs } // determineVotes determines the Conflicts that are supported and revoked by the given ConflictIDs. -func (c *ConflictDAG[ConflictID, ResourceID, VoteRank]) determineVotes(conflictIDs ds.Set[ConflictID]) (supportedConflicts, revokedConflicts ds.Set[*Conflict[ConflictID, ResourceID, VoteRank]], err error) { +func (c *ConflictDAG[ConflictID, ResourceID, VoteRank]) determineVotes(conflictIDs ds.Set[ConflictID]) (supportedConflicts ds.Set[*Conflict[ConflictID, ResourceID, VoteRank]], revokedConflicts ds.Set[*Conflict[ConflictID, ResourceID, VoteRank]], err error) { supportedConflicts = ds.NewSet[*Conflict[ConflictID, ResourceID, VoteRank]]() revokedConflicts = ds.NewSet[*Conflict[ConflictID, ResourceID, VoteRank]]() @@ -498,7 +497,7 @@ func (c *ConflictDAG[ConflictID, ResourceID, VoteRank]) conflictSetFactory(resou return func() *ConflictSet[ConflictID, ResourceID, VoteRank] { conflictSet := NewConflictSet[ConflictID, ResourceID, VoteRank](resourceID) - conflictSet.OnAllMembersEvicted(func(prevValue, newValue bool) { + conflictSet.OnAllMembersEvicted(func(prevValue bool, newValue bool) { if newValue && !prevValue { c.conflictSetsByID.Delete(conflictSet.ID) } diff --git a/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/sorted_conflict.go b/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/sorted_conflict.go index 461f9b3a4..94ef01152 100644 --- a/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/sorted_conflict.go +++ b/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/sorted_conflict.go @@ -119,7 +119,7 @@ func (s *sortedConflict[ConflictID, ResourceID, VoteRank]) Unhook() { } } -func (s *sortedConflict[ConflictID, ResourceID, VoteRank]) onAcceptanceStateUpdated(_, newState acceptance.State) { +func (s *sortedConflict[ConflictID, ResourceID, VoteRank]) onAcceptanceStateUpdated(_ acceptance.State, newState acceptance.State) { if newState.IsAccepted() { s.sortedSet.owner.setAcceptanceState(acceptance.Rejected) } diff --git a/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/sorted_conflicts.go b/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/sorted_conflicts.go index 6b05827dc..8f2b2e9d1 100644 --- a/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/sorted_conflicts.go +++ b/pkg/protocol/engine/mempool/conflictdag/conflictdagv1/sorted_conflicts.go @@ -370,7 +370,7 @@ func (s *SortedConflicts[ConflictID, ResourceID, VoteRank]) findLowerHeaviestPre } // swapNeighbors swaps the given members in the SortedConflicts. -func (s *SortedConflicts[ConflictID, ResourceID, VoteRank]) swapNeighbors(heavierMember, lighterMember *sortedConflict[ConflictID, ResourceID, VoteRank]) { +func (s *SortedConflicts[ConflictID, ResourceID, VoteRank]) swapNeighbors(heavierMember *sortedConflict[ConflictID, ResourceID, VoteRank], lighterMember *sortedConflict[ConflictID, ResourceID, VoteRank]) { if heavierMember.lighterMember != nil { heavierMember.lighterMember.heavierMember = lighterMember } diff --git a/pkg/protocol/engine/mempool/conflictdag/tests/framework.go b/pkg/protocol/engine/mempool/conflictdag/tests/framework.go index 32676fa84..72c190270 100644 --- a/pkg/protocol/engine/mempool/conflictdag/tests/framework.go +++ b/pkg/protocol/engine/mempool/conflictdag/tests/framework.go @@ -60,7 +60,7 @@ func (f *Framework) CreateOrUpdateConflict(alias string, resourceAliases []strin } // UpdateConflictParents updates the parents of the conflict with the given alias. -func (f *Framework) UpdateConflictParents(conflictAlias string, addedParentIDs, removedParentIDs []string) error { +func (f *Framework) UpdateConflictParents(conflictAlias string, addedParentIDs []string, removedParentIDs []string) error { return f.Instance.UpdateConflictParents(f.ConflictID(conflictAlias), f.ConflictIDs(addedParentIDs...), f.ConflictIDs(removedParentIDs...)) } diff --git a/pkg/protocol/engine/mempool/tests/tests.go b/pkg/protocol/engine/mempool/tests/tests.go index c14fdd591..3fb42ba2d 100644 --- a/pkg/protocol/engine/mempool/tests/tests.go +++ b/pkg/protocol/engine/mempool/tests/tests.go @@ -454,7 +454,7 @@ func TestStoreAttachmentInEvictedSlot(t *testing.T, tf *TestFramework) { } func TestMemoryRelease(t *testing.T, tf *TestFramework) { - issueTransactions := func(startIndex, transactionCount int, prevStateAlias string) (int, string) { + issueTransactions := func(startIndex int, transactionCount int, prevStateAlias string) (int, string) { index := startIndex for ; index < startIndex+transactionCount; index++ { signedTxAlias := fmt.Sprintf("tx%d-signed", index) diff --git a/pkg/protocol/engine/mempool/v1/inclusion_flags.go b/pkg/protocol/engine/mempool/v1/inclusion_flags.go index 3b8213690..f97680af0 100644 --- a/pkg/protocol/engine/mempool/v1/inclusion_flags.go +++ b/pkg/protocol/engine/mempool/v1/inclusion_flags.go @@ -28,7 +28,7 @@ func newInclusionFlags() *inclusionFlags { committedSlot: reactive.NewVariable[iotago.SlotIndex](), rejected: promise.NewEvent(), // Make sure the oldest orphaned index doesn't get overridden by newer TX spending the orphaned conflict further. - orphanedSlot: reactive.NewVariable[iotago.SlotIndex](func(currentValue, newValue iotago.SlotIndex) iotago.SlotIndex { + orphanedSlot: reactive.NewVariable[iotago.SlotIndex](func(currentValue iotago.SlotIndex, newValue iotago.SlotIndex) iotago.SlotIndex { if currentValue != 0 { return currentValue } @@ -49,7 +49,7 @@ func (s *inclusionFlags) IsAccepted() bool { // OnAccepted registers a callback that gets triggered when the entity gets accepted. func (s *inclusionFlags) OnAccepted(callback func()) { - s.accepted.OnUpdate(func(wasAccepted, isAccepted bool) { + s.accepted.OnUpdate(func(wasAccepted bool, isAccepted bool) { if isAccepted && !wasAccepted { callback() } @@ -58,7 +58,7 @@ func (s *inclusionFlags) OnAccepted(callback func()) { // OnPending registers a callback that gets triggered when the entity gets pending. func (s *inclusionFlags) OnPending(callback func()) { - s.accepted.OnUpdate(func(wasAccepted, isAccepted bool) { + s.accepted.OnUpdate(func(wasAccepted bool, isAccepted bool) { if !isAccepted && wasAccepted { callback() } @@ -82,7 +82,7 @@ func (s *inclusionFlags) CommittedSlot() (slot iotago.SlotIndex, isCommitted boo // OnCommitted registers a callback that gets triggered when the entity gets committed. func (s *inclusionFlags) OnCommittedSlotUpdated(callback func(slot iotago.SlotIndex)) { - s.committedSlot.OnUpdate(func(_, newValue iotago.SlotIndex) { + s.committedSlot.OnUpdate(func(_ iotago.SlotIndex, newValue iotago.SlotIndex) { callback(newValue) }) } @@ -94,7 +94,7 @@ func (s *inclusionFlags) OrphanedSlot() (slot iotago.SlotIndex, isOrphaned bool) // OnOrphaned registers a callback that gets triggered when the entity gets orphaned. func (s *inclusionFlags) OnOrphanedSlotUpdated(callback func(slot iotago.SlotIndex)) { - s.orphanedSlot.OnUpdate(func(_, newValue iotago.SlotIndex) { + s.orphanedSlot.OnUpdate(func(_ iotago.SlotIndex, newValue iotago.SlotIndex) { callback(newValue) }) } diff --git a/pkg/protocol/engine/mempool/v1/mempool.go b/pkg/protocol/engine/mempool/v1/mempool.go index aa82b1185..af7315843 100644 --- a/pkg/protocol/engine/mempool/v1/mempool.go +++ b/pkg/protocol/engine/mempool/v1/mempool.go @@ -240,7 +240,7 @@ func (m *MemPool[VoteRank]) Evict(slot iotago.SlotIndex) { } } -func (m *MemPool[VoteRank]) storeTransaction(signedTransaction mempool.SignedTransaction, transaction mempool.Transaction, blockID iotago.BlockID) (storedSignedTransaction *SignedTransactionMetadata, isNewSignedTransaction, isNewTransaction bool, err error) { +func (m *MemPool[VoteRank]) storeTransaction(signedTransaction mempool.SignedTransaction, transaction mempool.Transaction, blockID iotago.BlockID) (storedSignedTransaction *SignedTransactionMetadata, isNewSignedTransaction bool, isNewTransaction bool, err error) { m.evictionMutex.RLock() defer m.evictionMutex.RUnlock() @@ -296,7 +296,7 @@ func (m *MemPool[VoteRank]) solidifyInputs(transaction *TransactionMetadata) { } if transaction.markInputSolid() { - transaction.executionContext.OnUpdate(func(_, executionContext context.Context) { + transaction.executionContext.OnUpdate(func(_ context.Context, executionContext context.Context) { m.executeTransaction(executionContext, transaction) }) } @@ -476,7 +476,7 @@ func (m *MemPool[VoteRank]) setupTransaction(transaction *TransactionMetadata) { }) }) - transaction.OnEarliestIncludedAttachmentUpdated(func(prevBlock, newBlock iotago.BlockID) { + transaction.OnEarliestIncludedAttachmentUpdated(func(prevBlock iotago.BlockID, newBlock iotago.BlockID) { if err := m.updateStateDiffs(transaction, prevBlock.Slot(), newBlock.Slot()); err != nil { m.errorHandler(ierrors.Wrap(err, "failed to update state diffs")) } diff --git a/pkg/protocol/engine/mempool/v1/signed_transaction_metadata.go b/pkg/protocol/engine/mempool/v1/signed_transaction_metadata.go index cc582843f..ea2434c25 100644 --- a/pkg/protocol/engine/mempool/v1/signed_transaction_metadata.go +++ b/pkg/protocol/engine/mempool/v1/signed_transaction_metadata.go @@ -49,7 +49,7 @@ func (s *SignedTransactionMetadata) TransactionMetadata() mempool.TransactionMet } func (s *SignedTransactionMetadata) OnSignaturesInvalid(callback func(error)) (unsubscribe func()) { - return s.signaturesInvalid.OnUpdate(func(_, err error) { + return s.signaturesInvalid.OnUpdate(func(_ error, err error) { callback(err) }) } diff --git a/pkg/protocol/engine/mempool/v1/state_metadata.go b/pkg/protocol/engine/mempool/v1/state_metadata.go index 80b30f3de..859024661 100644 --- a/pkg/protocol/engine/mempool/v1/state_metadata.go +++ b/pkg/protocol/engine/mempool/v1/state_metadata.go @@ -83,7 +83,7 @@ func (s *StateMetadata) AcceptedSpender() (mempool.TransactionMetadata, bool) { } func (s *StateMetadata) OnAcceptedSpenderUpdated(callback func(spender mempool.TransactionMetadata)) { - s.spendAccepted.OnUpdate(func(prevValue, newValue *TransactionMetadata) { + s.spendAccepted.OnUpdate(func(prevValue *TransactionMetadata, newValue *TransactionMetadata) { if prevValue != newValue { callback(newValue) } @@ -91,7 +91,7 @@ func (s *StateMetadata) OnAcceptedSpenderUpdated(callback func(spender mempool.T } func (s *StateMetadata) OnSpendCommitted(callback func(spender mempool.TransactionMetadata)) { - s.spendCommitted.OnUpdate(func(prevValue, newValue *TransactionMetadata) { + s.spendCommitted.OnUpdate(func(prevValue *TransactionMetadata, newValue *TransactionMetadata) { if prevValue != newValue { callback(newValue) } diff --git a/pkg/protocol/engine/mempool/v1/transaction_metadata.go b/pkg/protocol/engine/mempool/v1/transaction_metadata.go index a976dcf92..7304e6eb3 100644 --- a/pkg/protocol/engine/mempool/v1/transaction_metadata.go +++ b/pkg/protocol/engine/mempool/v1/transaction_metadata.go @@ -169,7 +169,7 @@ func (t *TransactionMetadata) IsInvalid() bool { } func (t *TransactionMetadata) OnInvalid(callback func(error)) { - t.invalid.OnUpdate(func(oldValue, newValue error) { + t.invalid.OnUpdate(func(_ error, newValue error) { callback(newValue) }) } @@ -294,13 +294,13 @@ func (t *TransactionMetadata) setup() (self *TransactionMetadata) { t.conflictIDs.Replace(ds.NewSet(t.id)) }) - t.allValidAttachmentsEvicted.OnUpdate(func(_, slot iotago.SlotIndex) { + t.allValidAttachmentsEvicted.OnUpdate(func(_ iotago.SlotIndex, slot iotago.SlotIndex) { if !lo.Return2(t.CommittedSlot()) { t.orphanedSlot.Set(slot) } }) - t.OnEarliestIncludedAttachmentUpdated(func(previousIndex, newIndex iotago.BlockID) { + t.OnEarliestIncludedAttachmentUpdated(func(previousIndex iotago.BlockID, newIndex iotago.BlockID) { if isIncluded, wasIncluded := newIndex.Slot() != 0, previousIndex.Slot() != 0; isIncluded != wasIncluded { t.accepted.Set(isIncluded && t.AllInputsAccepted() && t.IsConflictAccepted()) } diff --git a/pkg/protocol/engine/notarization/slotnotarization/manager.go b/pkg/protocol/engine/notarization/slotnotarization/manager.go index 217b3288b..18a3a9a39 100644 --- a/pkg/protocol/engine/notarization/slotnotarization/manager.go +++ b/pkg/protocol/engine/notarization/slotnotarization/manager.go @@ -163,7 +163,7 @@ func (m *Manager) tryCommitSlotUntil(acceptedBlockIndex iotago.SlotIndex) { } } -func (m *Manager) isCommittable(slot, acceptedBlockSlot iotago.SlotIndex) bool { +func (m *Manager) isCommittable(slot iotago.SlotIndex, acceptedBlockSlot iotago.SlotIndex) bool { return slot+m.apiProvider.APIForSlot(slot).ProtocolParameters().MinCommittableAge() <= acceptedBlockSlot } diff --git a/pkg/protocol/engine/tipmanager/v1/tip_metadata.go b/pkg/protocol/engine/tipmanager/v1/tip_metadata.go index 27db6297a..dcb28070b 100644 --- a/pkg/protocol/engine/tipmanager/v1/tip_metadata.go +++ b/pkg/protocol/engine/tipmanager/v1/tip_metadata.go @@ -100,7 +100,7 @@ func NewBlockMetadata(block *blocks.Block) *TipMetadata { weaklyOrphanedWeakParents: reactive.NewCounter[bool](), } - t.isMarkedOrphaned = reactive.NewDerivedVariable2[bool, bool](func(_, isLivenessThresholdReached, isAccepted bool) bool { + t.isMarkedOrphaned = reactive.NewDerivedVariable2[bool, bool](func(_ bool, isLivenessThresholdReached bool, isAccepted bool) bool { return isLivenessThresholdReached && !isAccepted }, t.livenessThresholdReached, block.Accepted()) @@ -112,15 +112,15 @@ func NewBlockMetadata(block *blocks.Block) *TipMetadata { return weaklyOrphanedWeakParents > 0 }, t.weaklyOrphanedWeakParents) - t.isStronglyOrphaned = reactive.NewDerivedVariable3[bool, bool, bool, bool](func(_, isMarkedOrphaned, anyStrongParentStronglyOrphaned, anyWeakParentWeaklyOrphaned bool) bool { + t.isStronglyOrphaned = reactive.NewDerivedVariable3[bool, bool, bool, bool](func(_ bool, isMarkedOrphaned bool, anyStrongParentStronglyOrphaned bool, anyWeakParentWeaklyOrphaned bool) bool { return isMarkedOrphaned || anyStrongParentStronglyOrphaned || anyWeakParentWeaklyOrphaned }, t.isMarkedOrphaned, t.anyStrongParentStronglyOrphaned, t.anyWeakParentWeaklyOrphaned) - t.isWeaklyOrphaned = reactive.NewDerivedVariable2[bool, bool, bool](func(_, isMarkedOrphaned, anyWeakParentWeaklyOrphaned bool) bool { + t.isWeaklyOrphaned = reactive.NewDerivedVariable2[bool, bool, bool](func(_ bool, isMarkedOrphaned bool, anyWeakParentWeaklyOrphaned bool) bool { return isMarkedOrphaned || anyWeakParentWeaklyOrphaned }, t.isMarkedOrphaned, t.anyWeakParentWeaklyOrphaned) - t.isOrphaned = reactive.NewDerivedVariable2[bool, bool, bool](func(_, isStronglyOrphaned, isWeaklyOrphaned bool) bool { + t.isOrphaned = reactive.NewDerivedVariable2[bool, bool, bool](func(_ bool, isStronglyOrphaned bool, isWeaklyOrphaned bool) bool { return isStronglyOrphaned || isWeaklyOrphaned }, t.isStronglyOrphaned, t.isWeaklyOrphaned) @@ -140,23 +140,23 @@ func NewBlockMetadata(block *blocks.Block) *TipMetadata { return connectedWeakChildren > 0 }, t.connectedWeakChildren) - t.isReferencedByTips = reactive.NewDerivedVariable2[bool, bool, bool](func(_, isWeaklyReferencedByTips, isStronglyReferencedByTips bool) bool { + t.isReferencedByTips = reactive.NewDerivedVariable2[bool, bool, bool](func(_ bool, isWeaklyReferencedByTips bool, isStronglyReferencedByTips bool) bool { return isWeaklyReferencedByTips || isStronglyReferencedByTips }, t.isWeaklyReferencedByTips, t.isStronglyReferencedByTips) - t.isStronglyConnectedToTips = reactive.NewDerivedVariable2(func(_, isStrongTipPoolMember, isStronglyReferencedByTips bool) bool { + t.isStronglyConnectedToTips = reactive.NewDerivedVariable2(func(_ bool, isStrongTipPoolMember bool, isStronglyReferencedByTips bool) bool { return isStrongTipPoolMember || isStronglyReferencedByTips }, t.isStrongTipPoolMember, t.isStronglyReferencedByTips) - t.isConnectedToTips = reactive.NewDerivedVariable3(func(_, isReferencedByTips, isStrongTipPoolMember, isWeakTipPoolMember bool) bool { + t.isConnectedToTips = reactive.NewDerivedVariable3(func(_ bool, isReferencedByTips bool, isStrongTipPoolMember bool, isWeakTipPoolMember bool) bool { return isReferencedByTips || isStrongTipPoolMember || isWeakTipPoolMember }, t.isReferencedByTips, t.isStrongTipPoolMember, t.isWeakTipPoolMember) - t.isStrongTip = reactive.NewDerivedVariable2[bool, bool, bool](func(_, isStrongTipPoolMember, isStronglyReferencedByTips bool) bool { + t.isStrongTip = reactive.NewDerivedVariable2[bool, bool, bool](func(_ bool, isStrongTipPoolMember bool, isStronglyReferencedByTips bool) bool { return isStrongTipPoolMember && !isStronglyReferencedByTips }, t.isStrongTipPoolMember, t.isStronglyReferencedByTips) - t.isWeakTip = reactive.NewDerivedVariable2[bool, bool, bool](func(_, isWeakTipPoolMember, isReferencedByTips bool) bool { + t.isWeakTip = reactive.NewDerivedVariable2[bool, bool, bool](func(_ bool, isWeakTipPoolMember bool, isReferencedByTips bool) bool { return isWeakTipPoolMember && !isReferencedByTips }, t.isWeakTipPoolMember, t.isReferencedByTips) @@ -209,7 +209,7 @@ func (t *TipMetadata) connectStrongParent(strongParent *TipMetadata) { // unsubscribe when the parent is evicted, since we otherwise continue to hold a reference to it. unsubscribe := strongParent.stronglyConnectedStrongChildren.Monitor(t.isStronglyConnectedToTips) - strongParent.evicted.OnUpdate(func(_, _ bool) { unsubscribe() }) + strongParent.evicted.OnUpdate(func(_ bool, _ bool) { unsubscribe() }) } // connectWeakParent sets up the parent and children related properties for a weak parent. @@ -218,7 +218,7 @@ func (t *TipMetadata) connectWeakParent(weakParent *TipMetadata) { // unsubscribe when the parent is evicted, since we otherwise continue to hold a reference to it. unsubscribe := weakParent.connectedWeakChildren.Monitor(t.isConnectedToTips) - weakParent.evicted.OnUpdate(func(_, _ bool) { unsubscribe() }) + weakParent.evicted.OnUpdate(func(_ bool, _ bool) { unsubscribe() }) } // String returns a human-readable representation of the TipMetadata. diff --git a/pkg/protocol/engine/tipmanager/v1/tipmanager.go b/pkg/protocol/engine/tipmanager/v1/tipmanager.go index 2b12cc40c..32162956c 100644 --- a/pkg/protocol/engine/tipmanager/v1/tipmanager.go +++ b/pkg/protocol/engine/tipmanager/v1/tipmanager.go @@ -113,7 +113,7 @@ func (t *TipManager) Shutdown() { // setupBlockMetadata sets up the behavior of the given Block. func (t *TipManager) setupBlockMetadata(tipMetadata *TipMetadata) { - tipMetadata.isStrongTip.OnUpdate(func(_, isStrongTip bool) { + tipMetadata.isStrongTip.OnUpdate(func(_ bool, isStrongTip bool) { if isStrongTip { t.strongTipSet.Set(tipMetadata.ID(), tipMetadata) } else { @@ -121,7 +121,7 @@ func (t *TipManager) setupBlockMetadata(tipMetadata *TipMetadata) { } }) - tipMetadata.isWeakTip.OnUpdate(func(_, isWeakTip bool) { + tipMetadata.isWeakTip.OnUpdate(func(_ bool, isWeakTip bool) { if isWeakTip { t.weakTipSet.Set(tipMetadata.Block().ID(), tipMetadata) } else { diff --git a/pkg/protocol/engine/tipselection/v1/tip_selection.go b/pkg/protocol/engine/tipselection/v1/tip_selection.go index a4e180b86..9e2001254 100644 --- a/pkg/protocol/engine/tipselection/v1/tip_selection.go +++ b/pkg/protocol/engine/tipselection/v1/tip_selection.go @@ -87,7 +87,7 @@ func (t *TipSelection) Construct(tipManager tipmanager.TipManager, conflictDAG c t.TriggerConstructed() - t.acceptanceTime.OnUpdate(func(_, acceptanceTime time.Time) { + t.acceptanceTime.OnUpdate(func(_ time.Time, acceptanceTime time.Time) { t.triggerLivenessThreshold(acceptanceTime) }) @@ -123,7 +123,7 @@ func (t *TipSelection) SelectTips(amount int) (references model.ParentReferences rootBlocks := t.rootBlocks() // Sort the rootBlocks in descending order according to their slot. - slices.SortFunc(rootBlocks, func(i, j iotago.BlockID) int { + slices.SortFunc(rootBlocks, func(i iotago.BlockID, j iotago.BlockID) int { if i.Slot() == j.Slot() { return 0 } else if i.Slot() < j.Slot() { diff --git a/pkg/protocol/engine/utxoledger/output.go b/pkg/protocol/engine/utxoledger/output.go index 0194b65c1..9e2b02631 100644 --- a/pkg/protocol/engine/utxoledger/output.go +++ b/pkg/protocol/engine/utxoledger/output.go @@ -19,11 +19,11 @@ func (l LexicalOrderedOutputs) Len() int { return len(l) } -func (l LexicalOrderedOutputs) Less(i, j int) bool { +func (l LexicalOrderedOutputs) Less(i int, j int) bool { return bytes.Compare(l[i].outputID[:], l[j].outputID[:]) < 0 } -func (l LexicalOrderedOutputs) Swap(i, j int) { +func (l LexicalOrderedOutputs) Swap(i int, j int) { l[i], l[j] = l[j], l[i] } diff --git a/pkg/protocol/engine/utxoledger/spent.go b/pkg/protocol/engine/utxoledger/spent.go index 1b1a0a888..7df74b326 100644 --- a/pkg/protocol/engine/utxoledger/spent.go +++ b/pkg/protocol/engine/utxoledger/spent.go @@ -22,11 +22,11 @@ func (l LexicalOrderedSpents) Len() int { return len(l) } -func (l LexicalOrderedSpents) Less(i, j int) bool { +func (l LexicalOrderedSpents) Less(i int, j int) bool { return bytes.Compare(l[i].outputID[:], l[j].outputID[:]) < 0 } -func (l LexicalOrderedSpents) Swap(i, j int) { +func (l LexicalOrderedSpents) Swap(i int, j int) { l[i], l[j] = l[j], l[i] } diff --git a/pkg/protocol/engine/utxoledger/tpkg/equal.go b/pkg/protocol/engine/utxoledger/tpkg/equal.go index 410bc85c2..9d98ee2e4 100644 --- a/pkg/protocol/engine/utxoledger/tpkg/equal.go +++ b/pkg/protocol/engine/utxoledger/tpkg/equal.go @@ -57,13 +57,13 @@ func EqualOutputs(t *testing.T, expected utxoledger.Outputs, actual utxoledger.O require.Equal(t, len(expected), len(actual)) // Sort Outputs by output ID. - sort.Slice(expected, func(i, j int) bool { + sort.Slice(expected, func(i int, j int) bool { iOutputID := expected[i].OutputID() jOutputID := expected[j].OutputID() return bytes.Compare(iOutputID[:], jOutputID[:]) == -1 }) - sort.Slice(actual, func(i, j int) bool { + sort.Slice(actual, func(i int, j int) bool { iOutputID := actual[i].OutputID() jOutputID := actual[j].OutputID() @@ -79,13 +79,13 @@ func EqualSpents(t *testing.T, expected utxoledger.Spents, actual utxoledger.Spe require.Equal(t, len(expected), len(actual)) // Sort Spents by output ID. - sort.Slice(expected, func(i, j int) bool { + sort.Slice(expected, func(i int, j int) bool { iOutputID := expected[i].OutputID() jOutputID := expected[j].OutputID() return bytes.Compare(iOutputID[:], jOutputID[:]) == -1 }) - sort.Slice(actual, func(i, j int) bool { + sort.Slice(actual, func(i int, j int) bool { iOutputID := actual[i].OutputID() jOutputID := actual[j].OutputID() diff --git a/pkg/protocol/protocol_fork.go b/pkg/protocol/protocol_fork.go index 458ee4ccc..e463e3b28 100644 --- a/pkg/protocol/protocol_fork.go +++ b/pkg/protocol/protocol_fork.go @@ -185,7 +185,7 @@ type commitmentVerificationResult struct { err error } -func (p *Protocol) processFork(fork *chainmanager.Fork) (anchorBlockIDs iotago.BlockIDs, shouldSwitch, banSource bool, err error) { +func (p *Protocol) processFork(fork *chainmanager.Fork) (anchorBlockIDs iotago.BlockIDs, shouldSwitch bool, banSource bool, err error) { // Flow: // 1. request attestations starting from forking point + AttestationCommitmentOffset // 2. request 1 by 1 diff --git a/pkg/protocol/sybilprotection/seatmanager/topstakers/topstakers.go b/pkg/protocol/sybilprotection/seatmanager/topstakers/topstakers.go index 464b83c9c..7183d6aca 100644 --- a/pkg/protocol/sybilprotection/seatmanager/topstakers/topstakers.go +++ b/pkg/protocol/sybilprotection/seatmanager/topstakers/topstakers.go @@ -215,7 +215,7 @@ func (s *SeatManager) SetCommittee(epoch iotago.EpochIndex, validators *account. } func (s *SeatManager) selectNewCommittee(candidates accounts.AccountsData) (*account.SeatedAccounts, error) { - sort.Slice(candidates, func(i, j int) bool { + sort.Slice(candidates, func(i int, j int) bool { // Prioritize the candidate that has a larger pool stake. if candidates[i].ValidatorStake+candidates[i].DelegationStake != candidates[j].ValidatorStake+candidates[j].DelegationStake { return candidates[i].ValidatorStake+candidates[i].DelegationStake > candidates[j].ValidatorStake+candidates[j].DelegationStake diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go index 498d00d99..73df3dab9 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/rewards.go @@ -20,7 +20,7 @@ func (t *Tracker) RewardsRoot(epoch iotago.EpochIndex) (iotago.Identifier, error return m.Root(), nil } -func (t *Tracker) ValidatorReward(validatorID iotago.AccountID, stakeAmount iotago.BaseToken, epochStart, epochEnd iotago.EpochIndex) (iotago.Mana, iotago.EpochIndex, iotago.EpochIndex, error) { +func (t *Tracker) ValidatorReward(validatorID iotago.AccountID, stakeAmount iotago.BaseToken, epochStart iotago.EpochIndex, epochEnd iotago.EpochIndex) (iotago.Mana, iotago.EpochIndex, iotago.EpochIndex, error) { t.mutex.RLock() defer t.mutex.RUnlock() @@ -109,7 +109,7 @@ func (t *Tracker) ValidatorReward(validatorID iotago.AccountID, stakeAmount iota return validatorReward, epochStart, epochEnd, nil } -func (t *Tracker) DelegatorReward(validatorID iotago.AccountID, delegatedAmount iotago.BaseToken, epochStart, epochEnd iotago.EpochIndex) (iotago.Mana, iotago.EpochIndex, iotago.EpochIndex, error) { +func (t *Tracker) DelegatorReward(validatorID iotago.AccountID, delegatedAmount iotago.BaseToken, epochStart iotago.EpochIndex, epochEnd iotago.EpochIndex) (iotago.Mana, iotago.EpochIndex, iotago.EpochIndex, error) { t.mutex.RLock() defer t.mutex.RUnlock() @@ -208,7 +208,7 @@ func (t *Tracker) rewardsForAccount(accountID iotago.AccountID, epoch iotago.Epo return m.Get(accountID) } -func (t *Tracker) poolReward(slot iotago.SlotIndex, totalValidatorsStake, totalStake, poolStake, validatorStake iotago.BaseToken, performanceFactor uint64) (iotago.Mana, error) { +func (t *Tracker) poolReward(slot iotago.SlotIndex, totalValidatorsStake iotago.BaseToken, totalStake iotago.BaseToken, poolStake iotago.BaseToken, validatorStake iotago.BaseToken, performanceFactor uint64) (iotago.Mana, error) { apiForSlot := t.apiProvider.APIForSlot(slot) epoch := apiForSlot.TimeProvider().EpochFromSlot(slot) params := apiForSlot.ProtocolParameters() @@ -246,7 +246,7 @@ func (t *Tracker) poolReward(slot iotago.SlotIndex, totalValidatorsStake, totalS return poolRewardFixedCost, nil } -func (t *Tracker) calculatePoolCoefficient(poolStake, totalStake, validatorStake, totalValidatorStake iotago.BaseToken, slot iotago.SlotIndex) (uint64, error) { +func (t *Tracker) calculatePoolCoefficient(poolStake iotago.BaseToken, totalStake iotago.BaseToken, validatorStake iotago.BaseToken, totalValidatorStake iotago.BaseToken, slot iotago.SlotIndex) (uint64, error) { poolCoeffExponent := t.apiProvider.APIForSlot(slot).ProtocolParameters().RewardsParameters().PoolCoefficientExponent scaledUpPoolStake, err := safemath.SafeLeftShift(poolStake, poolCoeffExponent) if err != nil { @@ -277,7 +277,7 @@ func (t *Tracker) calculatePoolCoefficient(poolStake, totalStake, validatorStake } // calculateProfitMargin calculates a common profit margin for all validators by firstly increasing the accuracy of the given value, so the profit margin is moved to the power of 2^accuracyShift. -func (t *Tracker) calculateProfitMargin(totalValidatorsStake, totalPoolStake iotago.BaseToken, epoch iotago.EpochIndex) (uint64, error) { +func (t *Tracker) calculateProfitMargin(totalValidatorsStake iotago.BaseToken, totalPoolStake iotago.BaseToken, epoch iotago.EpochIndex) (uint64, error) { scaledUpTotalValidatorStake, err := safemath.SafeLeftShift(totalValidatorsStake, t.apiProvider.APIForEpoch(epoch).ProtocolParameters().RewardsParameters().ProfitMarginExponent) if err != nil { return 0, ierrors.Wrapf(err, "failed to calculate profit margin due to overflow for epoch %d", epoch) diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/snapshot.go b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/snapshot.go index 585aff575..c49904782 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/snapshot.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/snapshot.go @@ -201,7 +201,7 @@ func (t *Tracker) importCommittees(reader io.ReadSeeker) error { return nil } -func (t *Tracker) exportPerformanceFactor(writer io.WriteSeeker, startSlot, targetSlot iotago.SlotIndex) error { +func (t *Tracker) exportPerformanceFactor(writer io.WriteSeeker, startSlot iotago.SlotIndex, targetSlot iotago.SlotIndex) error { t.performanceFactorsMutex.RLock() defer t.performanceFactorsMutex.RUnlock() diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go b/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go index 320f1e5cb..28e86f006 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go @@ -138,7 +138,7 @@ func (o *SybilProtection) TrackBlock(block *blocks.Block) { } } -func (o *SybilProtection) CommitSlot(slot iotago.SlotIndex) (committeeRoot, rewardsRoot iotago.Identifier, err error) { +func (o *SybilProtection) CommitSlot(slot iotago.SlotIndex) (committeeRoot iotago.Identifier, rewardsRoot iotago.Identifier, err error) { o.mutex.Lock() defer o.mutex.Unlock() @@ -252,11 +252,11 @@ func (o *SybilProtection) SeatManager() seatmanager.SeatManager { return o.seatManager } -func (o *SybilProtection) ValidatorReward(validatorID iotago.AccountID, stakeAmount iotago.BaseToken, epochStart, epochEnd iotago.EpochIndex) (validatorReward iotago.Mana, actualEpochStart, actualEpochEnd iotago.EpochIndex, err error) { +func (o *SybilProtection) ValidatorReward(validatorID iotago.AccountID, stakeAmount iotago.BaseToken, epochStart iotago.EpochIndex, epochEnd iotago.EpochIndex) (validatorReward iotago.Mana, actualEpochStart iotago.EpochIndex, actualEpochEnd iotago.EpochIndex, err error) { return o.performanceTracker.ValidatorReward(validatorID, stakeAmount, epochStart, epochEnd) } -func (o *SybilProtection) DelegatorReward(validatorID iotago.AccountID, delegatedAmount iotago.BaseToken, epochStart, epochEnd iotago.EpochIndex) (delegatorsReward iotago.Mana, actualEpochStart, actualEpochEnd iotago.EpochIndex, err error) { +func (o *SybilProtection) DelegatorReward(validatorID iotago.AccountID, delegatedAmount iotago.BaseToken, epochStart iotago.EpochIndex, epochEnd iotago.EpochIndex) (delegatorsReward iotago.Mana, actualEpochStart iotago.EpochIndex, actualEpochEnd iotago.EpochIndex, err error) { return o.performanceTracker.DelegatorReward(validatorID, delegatedAmount, epochStart, epochEnd) } @@ -373,7 +373,7 @@ func (o *SybilProtection) OrderedRegisteredCandidateValidatorsList(epoch iotago. return nil, ierrors.Wrapf(err, "failed to iterate over eligible validator candidates") } // sort candidates by stake - sort.Slice(validatorResp, func(i, j int) bool { + sort.Slice(validatorResp, func(i int, j int) bool { return validatorResp[i].ValidatorStake > validatorResp[j].ValidatorStake }) diff --git a/pkg/retainer/retainer/retainer.go b/pkg/retainer/retainer/retainer.go index d513f540b..933cf87ad 100644 --- a/pkg/retainer/retainer/retainer.go +++ b/pkg/retainer/retainer/retainer.go @@ -122,7 +122,7 @@ func NewProvider() module.Provider[*engine.Engine, retainer.Retainer] { } }) - transactionMetadata.OnEarliestIncludedAttachmentUpdated(func(prevBlock, newBlock iotago.BlockID) { + transactionMetadata.OnEarliestIncludedAttachmentUpdated(func(prevBlock iotago.BlockID, newBlock iotago.BlockID) { // if prevBlock is genesis, we do not need to update anything, bc the tx is included in the block we attached to at start. if prevBlock.Slot() == 0 { return @@ -307,7 +307,7 @@ func (r *Retainer) onTransactionAccepted(blockID iotago.BlockID) error { return store.StoreTransactionNoFailureStatus(blockID, apimodels.TransactionStateAccepted) } -func (r *Retainer) onAttachmentUpdated(prevID, newID iotago.BlockID, accepted bool) error { +func (r *Retainer) onAttachmentUpdated(prevID iotago.BlockID, newID iotago.BlockID, accepted bool) error { store, err := r.store(prevID.Slot()) if err != nil { return ierrors.Wrapf(err, "could not get retainer store for slot %d", prevID.Slot()) diff --git a/pkg/storage/prunable/bucket_manager.go b/pkg/storage/prunable/bucket_manager.go index 980d9d6b6..44737aedb 100644 --- a/pkg/storage/prunable/bucket_manager.go +++ b/pkg/storage/prunable/bucket_manager.go @@ -237,7 +237,7 @@ func (b *BucketManager) DeleteBucket(epoch iotago.EpochIndex) (deleted bool) { } // RollbackBucket removes data in the bucket in slots [targetSlotIndex+1; epochEndSlot]. -func (b *BucketManager) RollbackBucket(epoch iotago.EpochIndex, targetSlot, epochEndSlot iotago.SlotIndex) error { +func (b *BucketManager) RollbackBucket(epoch iotago.EpochIndex, targetSlot iotago.SlotIndex, epochEndSlot iotago.SlotIndex) error { oldBucketKvStore := b.getDBInstance(epoch).KVStore() for clearSlot := targetSlot + 1; clearSlot <= epochEndSlot; clearSlot++ { // delete slot prefix from forkedPrunable storage that will be eventually copied into the new engine diff --git a/pkg/storage/prunable/epochstore/epoch_kv.go b/pkg/storage/prunable/epochstore/epoch_kv.go index 3fd580eb7..91a84143a 100644 --- a/pkg/storage/prunable/epochstore/epoch_kv.go +++ b/pkg/storage/prunable/epochstore/epoch_kv.go @@ -17,7 +17,7 @@ type EpochKVStore struct { lastPrunedEpoch *model.PruningIndex } -func NewEpochKVStore(storeRealm, pruningRealm kvstore.Realm, kv kvstore.KVStore, pruningDelay iotago.EpochIndex) *EpochKVStore { +func NewEpochKVStore(storeRealm kvstore.Realm, pruningRealm kvstore.Realm, kv kvstore.KVStore, pruningDelay iotago.EpochIndex) *EpochKVStore { return &EpochKVStore{ realm: storeRealm, diff --git a/pkg/storage/prunable/epochstore/store.go b/pkg/storage/prunable/epochstore/store.go index f93d71832..35047cf8f 100644 --- a/pkg/storage/prunable/epochstore/store.go +++ b/pkg/storage/prunable/epochstore/store.go @@ -17,7 +17,7 @@ type Store[V any] struct { lastPrunedEpoch *model.PruningIndex } -func NewStore[V any](storeRealm, pruningRealm kvstore.Realm, kv kvstore.KVStore, pruningDelay iotago.EpochIndex, vToBytes kvstore.ObjectToBytes[V], bytesToV kvstore.BytesToObject[V]) *Store[V] { +func NewStore[V any](storeRealm kvstore.Realm, pruningRealm kvstore.Realm, kv kvstore.KVStore, pruningDelay iotago.EpochIndex, vToBytes kvstore.ObjectToBytes[V], bytesToV kvstore.BytesToObject[V]) *Store[V] { return &Store[V]{ realm: storeRealm, kv: kvstore.NewTypedStore(lo.PanicOnErr(kv.WithExtendedRealm(storeRealm)), iotago.EpochIndex.Bytes, iotago.EpochIndexFromBytes, vToBytes, bytesToV), diff --git a/pkg/storage/prunable/utils.go b/pkg/storage/prunable/utils.go index 169771165..769ec797c 100644 --- a/pkg/storage/prunable/utils.go +++ b/pkg/storage/prunable/utils.go @@ -41,7 +41,7 @@ func getSortedDBInstancesFromDisk(baseDir string) (dbInfos []*dbInstanceFileInfo }) dbInfos = lo.Filter(dbInfos, func(info *dbInstanceFileInfo) bool { return info != nil }) - sort.Slice(dbInfos, func(i, j int) bool { + sort.Slice(dbInfos, func(i int, j int) bool { return dbInfos[i].baseEpoch < dbInfos[j].baseEpoch }) diff --git a/pkg/storage/storage_pruning.go b/pkg/storage/storage_pruning.go index dde92862a..72261650f 100644 --- a/pkg/storage/storage_pruning.go +++ b/pkg/storage/storage_pruning.go @@ -80,7 +80,7 @@ func (s *Storage) PruneByEpochIndex(epoch iotago.EpochIndex) error { return nil } -func (s *Storage) PruneByDepth(epochDepth iotago.EpochIndex) (firstPruned, lastPruned iotago.EpochIndex, err error) { +func (s *Storage) PruneByDepth(epochDepth iotago.EpochIndex) (firstPruned iotago.EpochIndex, lastPruned iotago.EpochIndex, err error) { // Depth of 0 and 1 means we prune to the latestPrunableEpoch. if epochDepth == 0 { epochDepth = 1 diff --git a/pkg/testsuite/mock/account.go b/pkg/testsuite/mock/account.go index 7e716eb27..693be09de 100644 --- a/pkg/testsuite/mock/account.go +++ b/pkg/testsuite/mock/account.go @@ -56,7 +56,7 @@ func (e *Ed25519Account) PrivateKey() ed25519.PrivateKey { return e.privateKey } -func AccountFromParams(accountHex, privateKey string) Account { +func AccountFromParams(accountHex string, privateKey string) Account { accountID, err := iotago.AccountIDFromHexString(accountHex) if err != nil { panic(fmt.Sprintln("invalid accountID hex string", err)) diff --git a/pkg/votes/utils.go b/pkg/votes/utils.go index 0823c9fac..e4c5ca06c 100644 --- a/pkg/votes/utils.go +++ b/pkg/votes/utils.go @@ -1,6 +1,6 @@ package votes -func IsThresholdReached(objectWeight, totalWeight int, threshold float64) bool { +func IsThresholdReached(objectWeight int, totalWeight int, threshold float64) bool { if totalWeight == 0 { return false }