Skip to content

Commit

Permalink
fix: update based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Dec 7, 2024
1 parent 0f1926d commit 7818583
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions node/pkg/chain/noncemanagerv2/noncemanagerv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package noncemanagerv2

import (
"context"
"errors"
"sync"
"time"

Expand All @@ -17,11 +18,19 @@ type NonceManagerV2 struct {

const (
poolSize = 100
minimumNoncePoolSize = 5
minimumNoncePoolSize = 10
poolAutoRefillInterval = time.Minute
)

func New(ctx context.Context, client utils.ClientInterface, wallet string) (*NonceManagerV2, error) {
if client == nil {
return nil, errors.New("empty client")
}

if wallet == "" {
return nil, errors.New("empty wallet")
}

pool := make(chan uint64, poolSize)
currentNonce, err := utils.GetNonceFromPk(ctx, wallet, client)
if err != nil {
Expand Down Expand Up @@ -70,9 +79,11 @@ func (m *NonceManagerV2) Reset(ctx context.Context) error {

func (m *NonceManagerV2) fillPool() {
nonce := <-m.noncePool
for i := 0; i < poolSize-len(m.noncePool); i++ {
m.noncePool <- nonce + uint64(i)
pool := make(chan uint64, poolSize)
for i := 0; i < poolSize; i++ {
pool <- nonce + uint64(i)
}
m.noncePool = pool
}

func (m *NonceManagerV2) flushPool() {
Expand Down

0 comments on commit 7818583

Please sign in to comment.