diff --git a/.gitignore b/.gitignore index 66fd13c..238d5cf 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ # Dependency directories (remove the comment below to include it) # vendor/ +.env diff --git a/pkg/listener/handler.go b/pkg/listener/handler.go index 217bd46..cb588f6 100644 --- a/pkg/listener/handler.go +++ b/pkg/listener/handler.go @@ -2,6 +2,7 @@ package listener import ( "context" + "math/big" "github.com/KyberNetwork/evmlistener/pkg/block" "github.com/KyberNetwork/evmlistener/pkg/errors" @@ -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 + } + } + isReorg, err := h.blockKeeper.IsReorg(b) if err != nil { log.Errorw("Fail to check for re-organization", "error", err)