Skip to content

Commit fcfaf92

Browse files
authoredNov 18, 2024··
fix: tx search only returning one tx (#1533)
1 parent b28d312 commit fcfaf92

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed
 

‎state/txindex/kv/kv.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,11 @@ func (txi *TxIndex) setTmpHashes(tmpHeights map[string][]byte, it dbm.Iterator,
382382
eventSeq := extractEventSeqFromKey(it.Key())
383383
tmpHeights[string(it.Value())+eventSeq] = it.Value()
384384
} else {
385-
tmpHeights[string(it.Value())] = it.Value()
385+
// Copy it.Value() to ensure tmpHeights stores independent values, as iterators reuse
386+
// the same memory for it.Value(), causing overwrites on each iteration.
387+
valueCopy := make([]byte, len(it.Value()))
388+
copy(valueCopy, it.Value())
389+
tmpHeights[string(it.Value())] = valueCopy
386390
}
387391
}
388392

‎state/txindex/kv/kv_test.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,18 @@ func TestTxSearchMultipleTxs(t *testing.T) {
692692

693693
results, err := indexer.Search(ctx, query.MustParse("account.number >= 1"))
694694
assert.NoError(t, err)
695-
696695
require.Len(t, results, 3)
696+
697+
// since two txs were added at height 1 and 2, we should have two unique transactions
698+
// for both heights
699+
results, err = indexer.Search(ctx, query.MustParse("tx.height=1"))
700+
assert.NoError(t, err)
701+
require.Len(t, results, 2)
702+
703+
results, err = indexer.Search(ctx, query.MustParse("tx.height=2"))
704+
assert.NoError(t, err)
705+
require.Len(t, results, 2)
706+
697707
}
698708

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

0 commit comments

Comments
 (0)
Please sign in to comment.