Skip to content

Commit

Permalink
fix: tx search only returning one tx (#1533)
Browse files Browse the repository at this point in the history
  • Loading branch information
ninabarbakadze authored Nov 18, 2024
1 parent b28d312 commit fcfaf92
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion state/txindex/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,11 @@ func (txi *TxIndex) setTmpHashes(tmpHeights map[string][]byte, it dbm.Iterator,
eventSeq := extractEventSeqFromKey(it.Key())
tmpHeights[string(it.Value())+eventSeq] = it.Value()
} else {
tmpHeights[string(it.Value())] = it.Value()
// Copy it.Value() to ensure tmpHeights stores independent values, as iterators reuse
// the same memory for it.Value(), causing overwrites on each iteration.
valueCopy := make([]byte, len(it.Value()))
copy(valueCopy, it.Value())
tmpHeights[string(it.Value())] = valueCopy
}
}

Expand Down
12 changes: 11 additions & 1 deletion state/txindex/kv/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,18 @@ func TestTxSearchMultipleTxs(t *testing.T) {

results, err := indexer.Search(ctx, query.MustParse("account.number >= 1"))
assert.NoError(t, err)

require.Len(t, results, 3)

// since two txs were added at height 1 and 2, we should have two unique transactions
// for both heights
results, err = indexer.Search(ctx, query.MustParse("tx.height=1"))
assert.NoError(t, err)
require.Len(t, results, 2)

results, err = indexer.Search(ctx, query.MustParse("tx.height=2"))
assert.NoError(t, err)
require.Len(t, results, 2)

}

func txResultWithEvents(events []abci.Event) *abci.TxResult {
Expand Down

0 comments on commit fcfaf92

Please sign in to comment.