From f9323f647310c849beaba330bb03303d800c34ad Mon Sep 17 00:00:00 2001 From: Thomas Nguy <81727899+thomas-nguy@users.noreply.github.com> Date: Thu, 7 Oct 2021 18:04:04 +0900 Subject: [PATCH] rpc: fix range filter fromBlock logic (#643) --- CHANGELOG.md | 1 + rpc/ethereum/namespaces/eth/filters/filters.go | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85cbcb5b..6ddf8f0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (rpc) [tharsis#642](https://github.com/tharsis/ethermint/issues/642) Fix `eth_getLogs` when string is specified in filter's from or to fields * (evm) [tharsis#616](https://github.com/tharsis/ethermint/issues/616) Fix halt on deeply nested stack of cache context. Stack is now flattened before iterating over the tx logs. * (rpc, evm) [tharsis#614](https://github.com/tharsis/ethermint/issues/614) Use JSON for (un)marshaling tx `Log`s from events. * (rpc) [tharsis#611](https://github.com/tharsis/ethermint/pull/611) Fix panic on JSON-RPC when querying for an invalid block height. diff --git a/rpc/ethereum/namespaces/eth/filters/filters.go b/rpc/ethereum/namespaces/eth/filters/filters.go index 6e0e1bca..82cd3348 100644 --- a/rpc/ethereum/namespaces/eth/filters/filters.go +++ b/rpc/ethereum/namespaces/eth/filters/filters.go @@ -120,11 +120,15 @@ func (f *Filter) Logs(_ context.Context) ([]*ethtypes.Log, error) { } head := header.Number.Int64() - if f.criteria.FromBlock.Int64() == -1 { + if f.criteria.FromBlock.Int64() < 0 { f.criteria.FromBlock = big.NewInt(head) + } else if f.criteria.FromBlock.Int64() == 0 { + f.criteria.FromBlock = big.NewInt(1) } - if f.criteria.ToBlock.Int64() == -1 { + if f.criteria.ToBlock.Int64() < 0 { f.criteria.ToBlock = big.NewInt(head) + } else if f.criteria.ToBlock.Int64() == 0 { + f.criteria.ToBlock = big.NewInt(1) } if f.criteria.ToBlock.Int64()-f.criteria.FromBlock.Int64() > maxFilterBlocks {