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 committed Aug 23, 2024
1 parent d010aec commit 0cc1f93
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@

# Dependency directories (remove the comment below to include it)
# vendor/

# Others
.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/encoder"
Expand Down Expand Up @@ -287,5 +288,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 0cc1f93

Please sign in to comment.