From 7818583b21a995d329371f03bf829502bd89dfd0 Mon Sep 17 00:00:00 2001 From: nick Date: Sun, 8 Dec 2024 00:49:14 +0900 Subject: [PATCH] fix: update based on feedback --- node/pkg/chain/noncemanagerv2/noncemanagerv2.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/node/pkg/chain/noncemanagerv2/noncemanagerv2.go b/node/pkg/chain/noncemanagerv2/noncemanagerv2.go index 52ec78132..7db077b73 100644 --- a/node/pkg/chain/noncemanagerv2/noncemanagerv2.go +++ b/node/pkg/chain/noncemanagerv2/noncemanagerv2.go @@ -2,6 +2,7 @@ package noncemanagerv2 import ( "context" + "errors" "sync" "time" @@ -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 { @@ -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() {