Documentation ¶
Overview ¶
Package indexer takes a range of blocks, fetches logs, gets txs, receipts, and block headers, and stores them.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Indexer ¶
type Indexer struct {
// contains filtered or unexported fields
}
Indexer is a backfiller that fetches logs for a specific contract.
func NewIndexer ¶
func NewIndexer(chainConfig config.ChainConfig, addresses []common.Address, eventDB db.EventDB, client []backend.ScribeBackend, handler metrics.Handler, blockMeter otelMetrics.Int64Histogram, toHead bool) (*Indexer, error)
NewIndexer creates a new backfiller for a contract.
func (*Indexer) GetIndexerConfig ¶
func (x *Indexer) GetIndexerConfig() scribeTypes.IndexerConfig
GetIndexerConfig returns the indexer config.
func (*Indexer) Index ¶
func (x *Indexer) Index(parentCtx context.Context, startHeight uint64, endHeight uint64) (err error)
Index retrieves logs, receipts, and transactions for a contract from a given range and does so in the following manner. 1. Get logs for the contract in chunks of batch requests. 2. Iterate through each log's Tx Hash and performs the following
- Get the receipt for each log and store it and all of its logs.
- Get the transaction for each log and store it.
func (*Indexer) RefreshRate ¶
RefreshRate returns the refresh rate for the indexer.
func (*Indexer) SetToBackfill ¶
func (x *Indexer) SetToBackfill()
SetToBackfill sets the indexer to backfill (will not update last indexed).
func (*Indexer) UpdateAddress ¶
UpdateAddress updates the address arrays for the indexer.
type LogFetcher ¶
type LogFetcher struct {
// contains filtered or unexported fields
}
LogFetcher pre-fetches filter logs into a channel in deterministic order.
func NewLogFetcher ¶
func NewLogFetcher(backend backend.ScribeBackend, startBlock, endBlock *big.Int, indexerConfig *scribeTypes.IndexerConfig, ascending bool) *LogFetcher
NewLogFetcher creates a new filtering interface for a range of blocks. If reverse is not set, block heights are filtered from start->end.
func (*LogFetcher) FetchLogs ¶
FetchLogs safely calls FilterLogs with the filtering implementing a backoff in the case of rate limiting and respects context cancellation.
nolint:cyclop
func (*LogFetcher) GetChunkArr ¶
func (f *LogFetcher) GetChunkArr() (chunkArr []*util.Chunk)
GetChunkArr gets the appropriate amount of block chunks (getLogs ranges).
func (*LogFetcher) GetFetchedLogsChan ¶
func (f *LogFetcher) GetFetchedLogsChan() *chan types.Log
GetFetchedLogsChan returns the fetchedLogsChan channel as a pointer for access by the indexer and tests.
func (*LogFetcher) Start ¶
func (f *LogFetcher) Start(ctx context.Context) error
Start starts the log fetching process. If the context is canceled, logs will stop being filtered. 1. Within an infinite for loop, chunks of getLogs blocks are constructed and used to get logs. This flow is paused when the logs channel's buffer of 15 is reached. 2. Each time the logs are received, a wait group is used to ensure that there is no race condition where channels could be closed before a log could be saved. 3. When the range to get logs is completed (GetChunkArr returns a zero array), the wait group is used to ensure that all logs are added to the logs channel before returning and terminating the function. 4. Completing the Start function triggers the closeOnDone function, which sends a boolean in the done channel that signals that the fetcher has completed. The consumer of these logs then performs a drain to fully empty the logs channel. See contract.go to learn more how the logs from this file are consumed.