From 95b322d91d32d0c639e90a67979ded780c3202cb Mon Sep 17 00:00:00 2001 From: p4u Date: Thu, 22 Aug 2024 18:14:20 +0200 Subject: [PATCH] if a token scan producess more than 5 errors, it is removed from the queue Signed-off-by: p4u --- scanner/providers/gitcoin/gitcoin_provider.go | 2 +- scanner/scanner.go | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/scanner/providers/gitcoin/gitcoin_provider.go b/scanner/providers/gitcoin/gitcoin_provider.go index 8a11f309..72b4ff11 100644 --- a/scanner/providers/gitcoin/gitcoin_provider.go +++ b/scanner/providers/gitcoin/gitcoin_provider.go @@ -544,7 +544,7 @@ func (g *GitcoinPassport) saveScore(score *GitcoinScore) error { return fmt.Errorf("error creating tx: %w", err) } defer func() { - if err := tx.Rollback(); err != nil && !errors.Is(sql.ErrTxDone, err) { + if err := tx.Rollback(); err != nil && !errors.Is(err, sql.ErrTxDone) { log.Warnw("error rolling back tx", "err", err) } }() diff --git a/scanner/scanner.go b/scanner/scanner.go index 0e4e6256..74d2b328 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -55,6 +55,12 @@ type Scanner struct { lastUpdatedBlockNumbers time.Time } +// tokensWithErrors is a map to store the tokens that have errors while scanning. Its used as 'addrString -> numberOfErrors' +var tokensWithErrors sync.Map + +// maxErrorsPerToken is the maximum number of errors that a token can have before being removed from the scanner. +const maxErrorsPerToken = 5 + // NewScanner returns a new scanner instance with the required parameters // initialized. func NewScanner(db *db.DB, networks *web3.Web3Pool, pm *manager.ProviderManager, coolDown time.Duration) *Scanner { @@ -115,6 +121,17 @@ func (s *Scanner) Start(ctx context.Context, concurrentTokens int) { defer func() { <-sem }() + // check if the token has too many errors + scannerTokenErrors := 0 + if errors, ok := tokensWithErrors.Load(token.Address.Hex()); ok { + if errors.(int) >= maxErrorsPerToken { + return + } + scannerTokenErrors = errors.(int) + } else { + tokensWithErrors.Store(token.Address.Hex(), 0) + } + // scan the token log.Infow("scanning token", "address", token.Address.Hex(), "chainID", token.ChainID, @@ -130,6 +147,13 @@ func (s *Scanner) Start(ctx context.Context, concurrentTokens int) { return } log.Errorw(err, "error scanning token") + tokensWithErrors.Store(token.Address.Hex(), scannerTokenErrors+1) + if scannerTokenErrors+1 >= maxErrorsPerToken { + log.Warnw("too many errors, token removed from scanner", + "address", token.Address.Hex(), + "chainID", token.ChainID, + ) + } return } if !synced {