Skip to content

Commit

Permalink
fix: contract events
Browse files Browse the repository at this point in the history
  • Loading branch information
mempirate committed Jun 12, 2022
1 parent 687abe0 commit 12e73c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions chainservice/cached_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package chainservice

import (
"context"
"fmt"
"math/big"
"time"

Expand Down Expand Up @@ -120,7 +119,7 @@ func (c *CachedClient) FilterLogs(ctx context.Context, query ethereum.FilterQuer
// my (big) machine almost crashed. A reasonable improvement we can make here is to use a small amount of concurrency,
// e.g. 2 - 4 concurrent `eth_getLogs` requests. If this fails (context timeouts), we can both increase the block range (parts)
// and decrease the number of concurrent requests.
func (c *CachedClient) SmartFilterLogs(ctx context.Context, topics [][]common.Hash, fromBlock, toBlock *big.Int) ([]types.Log, error) {
func (c *CachedClient) SmartFilterLogs(ctx context.Context, addresses []common.Address, topics [][]common.Hash, fromBlock, toBlock *big.Int) ([]types.Log, error) {
var logs []types.Log

parts := int64(50)
Expand All @@ -138,6 +137,7 @@ func (c *CachedClient) SmartFilterLogs(ctx context.Context, topics [][]common.Ha
}

res, err := c.FilterLogs(ctx, ethereum.FilterQuery{
Addresses: addresses,
Topics: topics,
FromBlock: big.NewInt(i),
ToBlock: big.NewInt(i + chunk),
Expand All @@ -161,7 +161,7 @@ func (c *CachedClient) SmartFilterLogs(ctx context.Context, topics [][]common.Ha
c.logger.Debug().Int64("parts", parts).Msg("smart filter logs")
logs, err := retry(parts)
if err != nil {
fmt.Println(err)
c.logger.Debug().Msg(err.Error())
parts *= 2

c.logger.Debug().Msg("failed, retrying")
Expand Down
5 changes: 3 additions & 2 deletions chainservice/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (c ChainService) FilterEvents(query *dsl.Query, fromBlock, toBlock *big.Int
ctx, cancel := context.WithTimeout(context.Background(), c.defaultTimeout)
defer cancel()

logs, err := rlClient.SmartFilterLogs(ctx, [][]common.Hash{{topic}}, fromBlock, toBlock)
logs, err := rlClient.SmartFilterLogs(ctx, []common.Address{cs.Address()}, [][]common.Hash{{topic}}, fromBlock, toBlock)
if err != nil {
c.logger.Debug().Str("chain", string(query.Chain)).Err(err).Msg("getting logs from node")
out <- apolloTypes.CallResult{
Expand Down Expand Up @@ -152,7 +152,7 @@ func (c ChainService) FilterGlobalEvents(query *dsl.Query, fromBlock, toBlock *b
ctx, cancel := context.WithTimeout(context.Background(), c.defaultTimeout)
defer cancel()

logs, err := rlClient.SmartFilterLogs(ctx, [][]common.Hash{{topic}}, fromBlock, toBlock)
logs, err := rlClient.SmartFilterLogs(ctx, nil, [][]common.Hash{{topic}}, fromBlock, toBlock)
if err != nil {
c.logger.Debug().Str("chain", string(query.Chain)).Err(err).Msg("getting logs from node")
out <- apolloTypes.CallResult{
Expand Down Expand Up @@ -392,6 +392,7 @@ func (c ChainService) ListenForGlobalEvents(query *dsl.Query, res chan<- apolloT

callResult := *aggregateCallResults(results...)
callResult.QueryName = query.Name
callResult.Type = apolloTypes.GlobalEvent
res <- callResult
}(log)
}
Expand Down

0 comments on commit 12e73c9

Please sign in to comment.