From 9570ac4d3ef6e007d4da30b2686b0f8d890c0d96 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 27 Nov 2018 16:47:50 +0400 Subject: [PATCH] rpc: Fix tx.height range queries (#2899) Modify lookForHeight to return a height only there's a equal operator. Previously, it was returning a height even for range conditions: "height < 10000". Fixes #2759 --- CHANGELOG_PENDING.md | 3 ++- rpc/client/rpc_test.go | 13 ++++++++++--- state/txindex/kv/kv.go | 3 ++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 04394bd52..e1215f79e 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -37,4 +37,5 @@ program](https://hackerone.com/tendermint). - [blockchain] \#2731 Retry both blocks if either is bad to avoid getting stuck during fast sync (@goolAdapter) - [log] \#2868 fix module=main setting overriding all others - [rpc] \#2808 RPC validators calls IncrementAccum if necessary -- [rpc] \#2811 Allow integer IDs in JSON-RPC requests +- [rpc] \#2759 fix tx.height range queries +- [rpc] \#2811 Allow integer IDs in JSON-RPC requests \ No newline at end of file diff --git a/rpc/client/rpc_test.go b/rpc/client/rpc_test.go index 217971fda..b07b74a39 100644 --- a/rpc/client/rpc_test.go +++ b/rpc/client/rpc_test.go @@ -370,20 +370,27 @@ func TestTxSearch(t *testing.T) { } // query by height - result, err = c.TxSearch(fmt.Sprintf("tx.height >= %d", txHeight), true, 1, 30) + result, err = c.TxSearch(fmt.Sprintf("tx.height=%d", txHeight), true, 1, 30) require.Nil(t, err, "%+v", err) require.Len(t, result.Txs, 1) - // we query for non existing tx + // query for non existing tx result, err = c.TxSearch(fmt.Sprintf("tx.hash='%X'", anotherTxHash), false, 1, 30) require.Nil(t, err, "%+v", err) require.Len(t, result.Txs, 0) - // we query using a tag (see kvstore application) + // query using a tag (see kvstore application) result, err = c.TxSearch("app.creator='Cosmoshi Netowoko'", false, 1, 30) require.Nil(t, err, "%+v", err) if len(result.Txs) == 0 { t.Fatal("expected a lot of transactions") } + + // query using a tag (see kvstore application) and height + result, err = c.TxSearch("app.creator='Cosmoshi Netowoko' AND tx.height<10000", true, 1, 30) + require.Nil(t, err, "%+v", err) + if len(result.Txs) == 0 { + t.Fatal("expected a lot of transactions") + } } } diff --git a/state/txindex/kv/kv.go b/state/txindex/kv/kv.go index 363ab1193..1137853c2 100644 --- a/state/txindex/kv/kv.go +++ b/state/txindex/kv/kv.go @@ -225,9 +225,10 @@ func lookForHash(conditions []query.Condition) (hash []byte, err error, ok bool) return } +// lookForHeight returns a height if there is an "height=X" condition. func lookForHeight(conditions []query.Condition) (height int64) { for _, c := range conditions { - if c.Tag == types.TxHeightKey { + if c.Tag == types.TxHeightKey && c.Op == query.OpEqual { return c.Operand.(int64) } }