Skip to content

Commit

Permalink
feat: add flush on nonce error
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Dec 7, 2024
1 parent ec5cafa commit 58a7350
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions node/pkg/chain/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,7 @@ func (t *ChainHelper) SubmitDirect(ctx context.Context, contractAddress, functio

return utils.SubmitRawTx(ctx, t.client, tx)
}

func (t *ChainHelper) FlushNoncePool(ctx context.Context) error {
return t.noncemanager.Refill(ctx, t.wallet)
}
6 changes: 6 additions & 0 deletions node/pkg/chain/noncemanagerv2/noncemanagerv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func (m *NonceManagerV2) GetNonce(ctx context.Context, address string) (uint64,
return nonce, nil
}

func (m *NonceManagerV2) Refill(ctx context.Context, address string) error {
m.mu.Lock()
defer m.mu.Unlock()
return m.unsafeRefill(ctx, address)
}

func (m *NonceManagerV2) unsafeRefill(ctx context.Context, address string) error {
currentNonce, err := utils.GetNonceFromPk(ctx, address, m.client)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions node/pkg/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sync"
"time"

"bisonai.com/miko/node/pkg/chain/utils"
errorSentinel "bisonai.com/miko/node/pkg/error"

"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -145,12 +146,18 @@ func (r *Reporter) report(ctx context.Context, pairs map[string]SubmissionData)
wg.Wait()
close(errorsChan)

isNonceErrorIncluded := false

for err := range errorsChan {
tmp := []error{}
tmp = append(tmp, err)
if len(tmp) > 0 {
return mergeErrors(tmp)
}

if utils.IsNonceError(err) {
isNonceErrorIncluded = true
}
}

for i, pair := range submittedPairs {
Expand All @@ -159,6 +166,10 @@ func (r *Reporter) report(ctx context.Context, pairs map[string]SubmissionData)

log.Debug().Str("Player", "Reporter").Msgf("reporting done for reporter with interval: %v", r.SubmissionInterval)

if isNonceErrorIncluded {
return r.KaiaHelper.FlushNoncePool(ctx)
}

return nil
}

Expand Down

0 comments on commit 58a7350

Please sign in to comment.