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 00f4806
Show file tree
Hide file tree
Showing 2 changed files with 15 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
14 changes: 14 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,19 @@ 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)
Expand Down

0 comments on commit 00f4806

Please sign in to comment.