Skip to content

Commit

Permalink
addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaidashenko committed Jan 20, 2025
1 parent ac867d9 commit 73d3178
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 6 additions & 0 deletions core/chains/evm/logpoller/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ func (v *pgDSLParser) hashedValueCmpToCondition(comp HashedValueComparator, colu
if err != nil {
return "", err
}

// simplify query for Postgres as in some cases, it's not that smart
if len(comp.Values) == 1 {
return fmt.Sprintf("%s %s :%s", column, cmp, v.args.withIndexedField(fieldName, comp.Values[0])), nil
}

return fmt.Sprintf("%s %s ANY(:%s)", column, cmp, v.args.withIndexedField(fieldName, comp.Values)), nil
}

Expand Down
10 changes: 6 additions & 4 deletions core/chains/evm/logpoller/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func TestDSLParser(t *testing.T) {

topicFilter := NewEventByTopicFilter(2, []HashedValueComparator{
{Values: []common.Hash{common.HexToHash("a")}, Operator: primitives.Gt},
{Values: []common.Hash{common.HexToHash("b")}, Operator: primitives.Lt},
{Values: []common.Hash{common.HexToHash("b"), common.HexToHash("c")}, Operator: primitives.Lt},
})

parser := &pgDSLParser{}
Expand All @@ -266,7 +266,7 @@ func TestDSLParser(t *testing.T) {
result, args, err := parser.buildQuery(chainID, expressions, limiter)
expected := logsQuery(
" WHERE evm_chain_id = :evm_chain_id " +
"AND topics[3] > ANY(:topic_value_0) AND topics[3] < ANY(:topic_value_1) ORDER BY " + defaultSort)
"AND topics[3] > :topic_value_0 AND topics[3] < ANY(:topic_value_1) ORDER BY " + defaultSort)

require.NoError(t, err)
assert.Equal(t, expected, result)
Expand Down Expand Up @@ -352,7 +352,7 @@ func TestDSLParser(t *testing.T) {
"AND (block_timestamp = :block_timestamp_0 " +
"AND (tx_hash = :tx_hash_0 " +
"OR (block_number <= (SELECT greatest(block_number - :confs_0, 0) FROM evm.log_poller_blocks WHERE evm_chain_id = :evm_chain_id ORDER BY block_number DESC LIMIT 1) " +
"AND substring(data from 32*8+1 for 32) > ANY(:word_value_0) " +
"AND substring(data from 32*8+1 for 32) > :word_value_0 " +
"AND substring(data from 32*8+1 for 32) <= ANY(:word_value_1)))) ORDER BY " + defaultSort)

require.NoError(t, err)
Expand All @@ -361,8 +361,10 @@ func TestDSLParser(t *testing.T) {
values, err := args.toArgs()
require.NoError(t, err)
require.Len(t, values, 6)
require.Len(t, values["word_value_0"], 1)
// unwraps slice of len 1
require.IsType(t, []uint8{}, values["word_value_0"])
// HashedValueComparator values should be concatenated into single slice
require.IsType(t, [][]uint8{}, values["word_value_1"])
require.Len(t, values["word_value_1"], 2)
})
}
3 changes: 2 additions & 1 deletion core/services/relay/evm/read/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,8 @@ func createTopicFilters(hashedTopics []common.Hash) (query.Expression, error) {
var expressions []query.Expression
for topicID, hash := range hashedTopics {
expressions = append(expressions, logpoller.NewEventByTopicFilter(
uint64(topicID), []logpoller.HashedValueComparator{{Values: []common.Hash{hash}, Operator: primitives.Eq}},
// adding 1 to skip even signature
uint64(topicID+1), []logpoller.HashedValueComparator{{Values: []common.Hash{hash}, Operator: primitives.Eq}},
))
}

Expand Down

0 comments on commit 73d3178

Please sign in to comment.