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

[EVM-747]: eth_subscribe issue with LogIndex #1744

Merged
merged 1 commit into from
Jul 25, 2023
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
5 changes: 5 additions & 0 deletions jsonrpc/filter_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,8 @@ func (f *FilterManager) appendLogsToFilters(header *block) error {
return nil
}

logIndex := uint64(0)

for indx, receipt := range receipts {
if receipt.TxHash == types.ZeroHash {
// Extract tx Hash
Expand All @@ -696,9 +698,12 @@ func (f *FilterManager) appendLogsToFilters(header *block) error {
TxHash: receipt.TxHash,
TxIndex: argUint64(indx),
Removed: false,
LogIndex: argUint64(logIndex),
})
}
}

logIndex++
}
}

Expand Down
87 changes: 87 additions & 0 deletions jsonrpc/filter_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,3 +715,90 @@ func TestClosedFilterDeletion(t *testing.T) {
// false because filter was removed automatically
assert.False(t, m.Exists(id))
}

func Test_appendLogsToFilters(t *testing.T) {
t.Parallel()

numOfLogs := 4

block := &types.Block{
Header: &types.Header{Hash: types.StringToHash("someHash"), Number: 1},
Transactions: []*types.Transaction{
createTestTransaction(types.StringToHash("tx1")),
createTestTransaction(types.StringToHash("tx2")),
createTestTransaction(types.StringToHash("tx3")),
},
}

// setup test with block with 3 transactions and 4 logs
store := &mockBlockStore{
receipts: map[types.Hash][]*types.Receipt{
block.Header.Hash: {
{
// transaction 1 logs
Logs: []*types.Log{
{
Topics: []types.Hash{
hash1,
},
},
{
Topics: []types.Hash{
hash2,
},
},
},
},
{
// transaction 2 logs
Logs: []*types.Log{
{
Topics: []types.Hash{
hash3,
},
},
},
},
{
// transaction 3 logs
Logs: []*types.Log{
{
Topics: []types.Hash{
hash4,
},
},
},
},
},
}}

store.appendBlocksToStore([]*types.Block{block})

f := NewFilterManager(hclog.NewNullLogger(), store, 1000)

logFilter := &logFilter{
filterBase: newFilterBase(nil),
query: &LogQuery{
fromBlock: 1,
toBlock: 1,
},
}

f.filters = map[string]filter{
"test": logFilter,
}

t.Cleanup(func() {
defer f.Close()
})

b := toBlock(&types.Block{Header: block.Header}, false)
err := f.appendLogsToFilters(b)

require.NoError(t, err)
require.Len(t, logFilter.logs, numOfLogs)

for i := 0; i < numOfLogs; i++ {
require.Equal(t, uint64(i), uint64(logFilter.logs[i].LogIndex))
}
}
Loading