Skip to content

Commit

Permalink
fix linter.
Browse files Browse the repository at this point in the history
  • Loading branch information
cristure committed Jan 31, 2024
1 parent 15b0037 commit f2cd036
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions interactors/nonceHandlerV3/nonceTransactionsHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ func (nth *nonceTransactionsHandlerV3) createAddressNonceHandler(address core.Ad
func (nth *nonceTransactionsHandlerV3) filterTransactionsBySenderAddress(transactions []*transaction.FrontendTransaction) map[string][]*transaction.FrontendTransaction {
filterMap := make(map[string][]*transaction.FrontendTransaction)
for _, tx := range transactions {
if entry, ok := filterMap[tx.Sender]; !ok {
if _, ok := filterMap[tx.Sender]; !ok {
transactionsPerAddress := make([]*transaction.FrontendTransaction, 0)
transactionsPerAddress = append(transactionsPerAddress, tx)
filterMap[tx.Sender] = transactionsPerAddress
} else {
entry = append(entry, tx)
filterMap[tx.Sender] = append(filterMap[tx.Sender], tx)
}
}

Expand Down
18 changes: 8 additions & 10 deletions interactors/nonceHandlerV3/workers/transactionWorker.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (tw *TransactionWorker) AddTransaction(transaction *transaction.FrontendTra
tw.mu.Lock()
defer tw.mu.Unlock()

r := make(chan *TransactionResponse)
r := make(chan *TransactionResponse, 1)
tw.responsesChannels[transaction.Nonce] = r

heap.Push(&tw.tq, &TransactionQueueItem{tx: transaction})
Expand Down Expand Up @@ -128,19 +128,17 @@ func (tw *TransactionWorker) start(ctx context.Context, pollingInterval time.Dur
if tx == nil {

// We create a poll where we peek at the queue for the first transaction. If such a transaction
//is found we break out of the poll.
poll:
for {
select {
case <-ticker.C:
tx = tw.peekNextTransaction()
if tx != nil {
break poll
}
// is found we break out of the poll. Otherwise, we keep polling with an interval set by
// the pollingInterval variable.
for range ticker.C {
tx = tw.peekNextTransaction()
if tx != nil {
break
}
}
}

// Retrieve the next transaction to be processed.
tx = tw.nextTransaction()

// We retrieve the channel where we will send the response.
Expand Down
15 changes: 15 additions & 0 deletions interactors/nonceHandlerV3/workers/transactionWorker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package workers

import (
"context"
"fmt"
"strconv"
"sync"
"testing"
Expand Down Expand Up @@ -71,3 +72,17 @@ func TestTransactionWorker_AddTransactionWithLowerNonceAfter(t *testing.T) {
wg.Wait()
require.Equal(t, &TransactionResponse{TxHash: strconv.FormatUint(nonces[2], 10), Error: nil}, <-w.responsesChannels[nonces[2]])
}

func TestMe(t *testing.T) {

ticker := time.NewTicker(time.Second)
i := 0
for range ticker.C {
fmt.Println(i)
i++

if i == 5 {
break
}
}
}

0 comments on commit f2cd036

Please sign in to comment.