diff --git a/cmd/export.go b/cmd/export.go index 2048a42..f39bb50 100644 --- a/cmd/export.go +++ b/cmd/export.go @@ -133,8 +133,8 @@ The process can be interrupted at any time (Ctrl+C), and it will attempt to save } cmd.Flags().Uint64VarP(&startBlock, "start", "", 31306381, "Start block (optional, uses contract start block if 0)") - cmd.Flags().Uint64VarP(&endBlock, "end", "", 39810670, "End block (optional, uses latest block if 0)") - cmd.Flags().StringVarP(&rpcEndpoint, "endpoint", "e", "https://wandering-evocative-gas.xdai.quiknode.pro/0f2525676e3ba76259ab3b72243f7f60334b0000/", "Ethereum RPC endpoint URL") + cmd.Flags().Uint64VarP(&endBlock, "end", "", 0, "End block (optional, uses latest block if 0)") + cmd.Flags().StringVarP(&rpcEndpoint, "endpoint", "e", "https://rpc.gnosis.gateway.fm", "Ethereum based RPC endpoint URL") cmd.Flags().IntVarP(&maxRequest, "max-request", "m", 15, "Max RPC requests/sec") cmd.Flags().Uint32VarP(&blockRangeLimit, "block-range-limit", "b", 5, "Max blocks per log query") cmd.Flags().StringVarP(&outputFile, "output", "o", "export.ndjson", "Output file path (NDJSON)") diff --git a/pkg/eventfetcher/eventfetcher.go b/pkg/eventfetcher/eventfetcher.go index 09d6de9..6a87922 100644 --- a/pkg/eventfetcher/eventfetcher.go +++ b/pkg/eventfetcher/eventfetcher.go @@ -13,7 +13,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethersphere/batch-export/pkg/ethclientwrapper" - "github.com/ethersphere/batch-export/pkg/logcache" ) type Client struct { @@ -21,19 +20,17 @@ type Client struct { client *ethclientwrapper.Client logger log.Logger blockRangeLimit uint32 - logCache *logcache.Cache batchCreatedTopic common.Hash batchTopUpTopic common.Hash batchDepthIncreaseTopic common.Hash priceUpdateTopic common.Hash - pausedTopic common.Hash + // pausedTopic common.Hash } func NewClient(client *ethclientwrapper.Client, postageStampContractABI abi.ABI, blockRangeLimit uint32, logger log.Logger) *Client { return &Client{ validate: validator.New(), - logCache: logcache.New(), client: client, logger: logger, blockRangeLimit: blockRangeLimit, @@ -59,14 +56,6 @@ func (c *Client) GetLogs(ctx context.Context, tr *Request) (<-chan types.Log, <- go func() { defer close(logChan) defer close(errorChan) - // send the last cached value to the channel - // defer func() { - // priceUpdateLog := c.logCache.Get() - // if priceUpdateLog != nil { - // c.logger.Info("sending last cached value", "transactionHash", priceUpdateLog.TxHash) - // logChan <- *priceUpdateLog - // } - // }() if err := c.validate.Struct(tr); err != nil { errorChan <- fmt.Errorf("error validating request: %w", err) @@ -97,6 +86,7 @@ func (c *Client) GetLogs(ctx context.Context, tr *Request) (<-chan types.Log, <- errorChan <- fmt.Errorf("start block (%s) cannot be greater than end block (%s)", fromBlock.String(), toBlock.String()) return } + query := c.filterQuery(tr.Address, fromBlock, toBlock) c.fetchLogs(ctx, query, logChan, errorChan) }() @@ -136,16 +126,11 @@ func (c *Client) fetchLogs(ctx context.Context, query ethereum.FilterQuery, logs } for _, log := range logs { - // cache the price update log and skip sending it to the channel - // if log.Topics[0] == c.priceUpdateTopic { - // c.logCache.Set(&log) - // continue - // } select { case logsChan <- log: case <-ctx.Done(): errorChan <- ctx.Err() - return // stop processing if context is cancelled + return } } @@ -173,7 +158,7 @@ func (c *Client) filterQuery(postageStampContractAddress common.Address, from, t c.batchTopUpTopic, c.batchDepthIncreaseTopic, c.priceUpdateTopic, - c.pausedTopic, + // c.pausedTopic, }, }, } diff --git a/pkg/logcache/logcache.go b/pkg/logcache/logcache.go deleted file mode 100644 index 54ed98e..0000000 --- a/pkg/logcache/logcache.go +++ /dev/null @@ -1,28 +0,0 @@ -package logcache - -import ( - "sync" - - "github.com/ethereum/go-ethereum/core/types" -) - -type Cache struct { - l *types.Log - m sync.Mutex -} - -func New() *Cache { - return &Cache{} -} - -func (c *Cache) Set(l *types.Log) { - c.m.Lock() - c.l = l - c.m.Unlock() -} - -func (c *Cache) Get() *types.Log { - c.m.Lock() - defer c.m.Unlock() - return c.l -} diff --git a/pkg/logcache/logcache_test.go b/pkg/logcache/logcache_test.go deleted file mode 100644 index 2d0d3d5..0000000 --- a/pkg/logcache/logcache_test.go +++ /dev/null @@ -1,18 +0,0 @@ -package logcache_test - -import ( - "testing" - - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethersphere/batch-export/pkg/logcache" -) - -func TestBasic(t *testing.T) { - t.Parallel() - c := logcache.New() - b := &types.Log{} - c.Set(b) - if c.Get() == nil { - t.Fatal("expected block to be cached") - } -}