Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tx search only returning one tx #1533

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added more tests to make sure that transaction searches return unique results and accurate number of transactions included at a specific block height. While this logic is already covered in the unit tests for this file, the existing implementation seems to work correctly in the local repository even without applying the fix.

It was manually tested by me and the NodesGuru team. #1526 (comment)

// 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
Loading