Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: ignore block that too old #119

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading