Skip to content

Commit

Permalink
chore: ignore block that too old (#119)
Browse files Browse the repository at this point in the history
* chore: ignore block that too old

* chore: move to more meaningful block
  • Loading branch information
lehainam-dev authored Aug 23, 2024
1 parent e6c2a8e commit e3280dd
Show file tree
Hide file tree
Showing 2 changed files with 16 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
15 changes: 15 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 @@ -276,5 +277,19 @@ func (h *Handler) Handle(ctx context.Context, b types.Block) error {
return nil
}

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
}
}

return h.handleNewBlock(ctx, b)
}

0 comments on commit e3280dd

Please sign in to comment.