From 650a4d62e9a1978639d78187c1684963773236ed Mon Sep 17 00:00:00 2001 From: Luis Carvalho Date: Tue, 24 Sep 2024 10:34:39 +0100 Subject: [PATCH] fix: check from and to fields on log filters The base chain was having some issues and was reporting a current block height lower than what we had already processed. We now check for that condition. --- chain/evm/compass.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/chain/evm/compass.go b/chain/evm/compass.go index 07e6bb4..f2d1f61 100644 --- a/chain/evm/compass.go +++ b/chain/evm/compass.go @@ -982,6 +982,12 @@ func (t *compass) getLogs( t.lastObservedBlockHeight = currentBlockNumber - 10_000 } + if currentBlockNumber < t.lastObservedBlockHeight { + // Either we messed up tracking the current block, or the RPC is + // having some issue. Either way, it's best to sync again. + t.lastObservedBlockHeight = currentBlockNumber + } + filter.FromBlock = big.NewInt(0).SetUint64(t.lastObservedBlockHeight) filter.ToBlock = big.NewInt(0).SetUint64(min(t.lastObservedBlockHeight+10_000, currentBlockNumber)) } else { @@ -1002,6 +1008,16 @@ func (t *compass) getLogs( Debug("Filter is ready") logs, err := t.evm.GetEthClient().FilterLogs(ctx, filter) + if err != nil { + logger.WithField("from", filter.FromBlock). + WithField("to", filter.ToBlock). + WithField("req_from", from). + WithField("req_to", to). + WithField("chain_reference_id", t.ChainReferenceID). + WithError(err). + Warn("Failed to filter events") + } + return logs, filter.ToBlock.Uint64(), err } @@ -1025,7 +1041,6 @@ func (t *compass) GetSkywayEvents( if len(blocks) == 0 { logs, toBlock, err = t.getLogs(ctx, logger, 0, 0) if err != nil { - logger.WithError(err).Warn("Failed to filter events") return nil, err } } else { @@ -1036,7 +1051,6 @@ func (t *compass) GetSkywayEvents( moreLogs, toBlock, err = t.getLogs(ctx, logger, blocks[i], blocks[i]) if err != nil { - logger.WithError(err).Warn("Failed to filter events") return nil, err }