Skip to content

Commit

Permalink
if a token scan producess more than 5 errors, it is removed from the …
Browse files Browse the repository at this point in the history
…queue

Signed-off-by: p4u <[email protected]>
  • Loading branch information
p4u committed Aug 22, 2024
1 parent b0c5d42 commit 95b322d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scanner/providers/gitcoin/gitcoin_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}()
Expand Down
24 changes: 24 additions & 0 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down

0 comments on commit 95b322d

Please sign in to comment.