Documentation ¶
Overview ¶
Package backfill is used to get logs from previous blocks
Index ¶
- Constants
- func BlockHashesInRange(ctx context.Context, backend ScribeBackend, startHeight uint64, ...) (*immutable.Map[uint64, string], error)
- func GetLogsInRange(ctx context.Context, backend ScribeBackend, contractAddress common.Address, ...) (*immutable.List[*[]types.Log], error)
- func LogEvent(level logLevel, msg string, logData LogData)
- func MakeRange[T constraints.Integer](min, max T) []T
- type ChainBackfiller
- type ContractBackfiller
- type LogData
- type LogFetcher
- type ScribeBackend
- type ScribeBackfiller
Constants ¶
const ( // InfoLevel prints a log at the info level. InfoLevel logLevel = iota // WarnLevel prints a log at the warn level. WarnLevel // ErrorLevel prints a log at the error level. ErrorLevel )
Variables ¶
This section is empty.
Functions ¶
func BlockHashesInRange ¶ added in v0.0.194
func BlockHashesInRange(ctx context.Context, backend ScribeBackend, startHeight uint64, endHeight uint64) (*immutable.Map[uint64, string], error)
BlockHashesInRange gets all block hashes in a range with a single batch request in successful cases an immutable map is returned of [height->hash], otherwise an error is returned.
func GetLogsInRange ¶ added in v0.0.74
func GetLogsInRange(ctx context.Context, backend ScribeBackend, contractAddress common.Address, expectedChainID uint64, chunks []*util.Chunk) (*immutable.List[*[]types.Log], error)
GetLogsInRange gets all logs in a range with a single batch request in successful cases an immutable list is returned, otherwise an error is returned.
func MakeRange ¶ added in v0.0.194
func MakeRange[T constraints.Integer](min, max T) []T
MakeRange returns a range of integers from min to max inclusive.
Types ¶
type ChainBackfiller ¶ added in v0.0.2
type ChainBackfiller struct {
// contains filtered or unexported fields
}
ChainBackfiller is a backfiller that fetches logs for a chain. It aggregates logs from a slice of ContractBackfillers.
func NewChainBackfiller ¶ added in v0.0.2
func NewChainBackfiller(eventDB db.EventDB, client []ScribeBackend, chainConfig config.ChainConfig, refreshRate int, handler metrics.Handler) (*ChainBackfiller, error)
NewChainBackfiller creates a new backfiller for a chain. This is done by passing through all the function parameters into the ChainBackfiller struct, as well as iterating through all the contracts in the chain config & creating ContractBackfillers for each contract.
type ContractBackfiller ¶
type ContractBackfiller struct {
// contains filtered or unexported fields
}
ContractBackfiller is a backfiller that fetches logs for a specific contract.
func NewContractBackfiller ¶
func NewContractBackfiller(chainConfig config.ChainConfig, contractConfig config.ContractConfig, eventDB db.EventDB, client []ScribeBackend, handler metrics.Handler, blockMeter otelMetrics.Int64Histogram) (*ContractBackfiller, error)
NewContractBackfiller creates a new backfiller for a contract.
func (*ContractBackfiller) Backfill ¶
func (c *ContractBackfiller) Backfill(parentCtx context.Context, givenStart uint64, endHeight uint64) (err error)
Backfill 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.
type LogData ¶ added in v0.0.56
type LogData map[string]interface{}
LogData holds all the data passed to LogEvent to be logged.
type LogFetcher ¶ added in v0.0.194
type LogFetcher struct {
// contains filtered or unexported fields
}
LogFetcher pre-fetches filter logs into a channel in deterministic order.
func NewLogFetcher ¶ added in v0.0.194
func NewLogFetcher(address ethCommon.Address, backend ScribeBackend, startBlock, endBlock *big.Int, chainConfig *config.ChainConfig) *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 ¶ added in v0.0.194
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 ¶ added in v0.0.194
func (f *LogFetcher) GetChunkArr() (chunkArr []*util.Chunk)
GetChunkArr gets the appropriate amount of block chunks (getLogs ranges).
func (*LogFetcher) Start ¶ added in v0.0.194
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.
type ScribeBackend ¶ added in v0.0.4
type ScribeBackend interface { // ChainID gets the chain id from the rpc server. ChainID(ctx context.Context) (*big.Int, error) // BlockNumber gets the latest block number. BlockNumber(ctx context.Context) (uint64, error) // HeaderByNumber returns the block header with the given block number. HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) // BatchWithContext batches multiple BatchWithContext(ctx context.Context, calls ...w3types.Caller) error }
ScribeBackend is the set of functions that the scribe needs from a client.
func DialBackend ¶ added in v0.0.68
DialBackend returns a scribe backend.
type ScribeBackfiller ¶ added in v0.0.3
type ScribeBackfiller struct { // ChainBackfillers is a mapping of chain IDs -> chain backfillers. ChainBackfillers map[uint32]*ChainBackfiller // contains filtered or unexported fields }
ScribeBackfiller is a backfiller that aggregates all backfilling from ChainBackfillers.
func NewScribeBackfiller ¶ added in v0.0.3
func NewScribeBackfiller(eventDB db.EventDB, clientsMap map[uint32][]ScribeBackend, config config.Config, handler metrics.Handler) (*ScribeBackfiller, error)
NewScribeBackfiller creates a new backfiller for the scribe.