Browse Source

[indexer] order results by index if height is the same (#2900)

Fixes #2775
pull/2922/head
Anton Kaliaev 6 years ago
committed by Ethan Buchman
parent
commit
94e63be922
3 changed files with 20 additions and 3 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +4
    -1
      state/txindex/kv/kv.go
  3. +15
    -2
      state/txindex/kv/kv_test.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -37,5 +37,6 @@ 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
- [kv indexer] \#2775 order results by index if height is the same
- [rpc] \#2759 fix tx.height range queries
- [rpc] \#2811 Allow integer IDs in JSON-RPC requests

+ 4
- 1
state/txindex/kv/kv.go View File

@ -207,8 +207,11 @@ func (txi *TxIndex) Search(q *query.Query) ([]*types.TxResult, error) {
i++
}
// sort by height by default
// sort by height & index by default
sort.Slice(results, func(i, j int) bool {
if results[i].Height == results[j].Height {
return results[i].Index < results[j].Index
}
return results[i].Height < results[j].Height
})


+ 15
- 2
state/txindex/kv/kv_test.go View File

@ -133,6 +133,7 @@ func TestTxSearchMultipleTxs(t *testing.T) {
})
txResult.Tx = types.Tx("Bob's account")
txResult.Height = 2
txResult.Index = 1
err := indexer.Index(txResult)
require.NoError(t, err)
@ -142,14 +143,26 @@ func TestTxSearchMultipleTxs(t *testing.T) {
})
txResult2.Tx = types.Tx("Alice's account")
txResult2.Height = 1
txResult2.Index = 2
err = indexer.Index(txResult2)
require.NoError(t, err)
// indexed third (to test the order of transactions)
txResult3 := txResultWithTags([]cmn.KVPair{
{Key: []byte("account.number"), Value: []byte("3")},
})
txResult3.Tx = types.Tx("Jack's account")
txResult3.Height = 1
txResult3.Index = 1
err = indexer.Index(txResult3)
require.NoError(t, err)
results, err := indexer.Search(query.MustParse("account.number >= 1"))
assert.NoError(t, err)
require.Len(t, results, 2)
assert.Equal(t, []*types.TxResult{txResult2, txResult}, results)
require.Len(t, results, 3)
assert.Equal(t, []*types.TxResult{txResult3, txResult2, txResult}, results)
}
func TestIndexAllTags(t *testing.T) {


Loading…
Cancel
Save