Skip to content

Commit

Permalink
chore: ignore block that too old
Browse files Browse the repository at this point in the history
  • Loading branch information
lehainam-dev committed Aug 23, 2024
1 parent e6c2a8e commit c97b222
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@

# Dependency directories (remove the comment below to include it)
# vendor/
.env
13 changes: 13 additions & 0 deletions pkg/listener/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package listener

import (
"context"
"math/big"

"github.com/KyberNetwork/evmlistener/pkg/block"
"github.com/KyberNetwork/evmlistener/pkg/errors"
Expand Down Expand Up @@ -208,6 +209,18 @@ func (h *Handler) handleNewBlock(ctx context.Context, b types.Block) error {

log.Infow("Handling new block")

blockHead, err := h.blockKeeper.Head()
if err == nil {
blockDiff := new(big.Int).Sub(blockHead.Number, b.Number).Int64()
if blockDiff > int64(h.blockKeeper.Cap()) {
log.Warnw("Ignore block that too old",
"blockNumber", b.Number,
"blockHeadNumber", blockHead.Number,
"blockDiff", blockDiff)
return nil

Check failure on line 220 in pkg/listener/handler.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

return with no blank line before (nlreturn)
}
}

isReorg, err := h.blockKeeper.IsReorg(b)
if err != nil {
log.Errorw("Fail to check for re-organization", "error", err)
Expand Down

0 comments on commit c97b222

Please sign in to comment.