extended

package
v0.47.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultBackfillDelay defines the delay between consecutive backfill attempts.
	// Set carefully to avoid overwhelming the system.
	// With the default value of 5ms, the maximum catch-up rate is approximately
	// 200 blocks per second.
	DefaultBackfillDelay = 5 * time.Millisecond
)

Variables

View Source
var (
	ErrAlreadyIndexed = errors.New("data already indexed for height")
	ErrFutureHeight   = errors.New("cannot index future height")
)

Functions

This section is empty.

Types

type AccountTransactions

type AccountTransactions struct {
	// contains filtered or unexported fields
}

AccountTransactions indexes account-transaction associations for a block.

func NewAccountTransactions

func NewAccountTransactions(
	log zerolog.Logger,
	store storage.AccountTransactionsBootstrapper,
	chainID flow.ChainID,
	lockManager storage.LockManager,
) *AccountTransactions

func (*AccountTransactions) IndexBlockData

func (a *AccountTransactions) IndexBlockData(lctx lockctx.Proof, data BlockData, batch storage.ReaderBatchWriter) error

IndexBlockData indexes the block data for the given height. If the header in `data` does not match the expected height, an error is returned.

The caller must hold the storage.LockIndexAccountTransactions lock until the batch is committed.

Not safe for concurrent use.

Expected error returns during normal operations:

func (*AccountTransactions) Name

func (a *AccountTransactions) Name() string

Name returns the name of the indexer.

func (*AccountTransactions) NextHeight

func (a *AccountTransactions) NextHeight() (uint64, error)

NextHeight returns the next height that the indexer will index.

No error returns are expected during normal operation.

type BlockData

type BlockData struct {
	Header       *flow.Header
	Transactions []*flow.TransactionBody
	Events       map[uint32][]flow.Event // grouped by transaction index
}

type ExtendedIndexer

type ExtendedIndexer struct {
	component.Component
	// contains filtered or unexported fields
}

ExtendedIndexer orchestrates indexing for all extended indexers.

Indexing is performed in a single-threaded loop, where each iteration indexes the next height for all indexers. Indexers are grouped by their next height to reduce database lookups. All data for each height is written to a batch and committed at once.

NOT CONCURRENCY SAFE.

func BootstrapExtendedIndexes

func BootstrapExtendedIndexes(
	log zerolog.Logger,
	state protocol.State,
	headers storage.Headers,
	index storage.Index,
	guarantees storage.Guarantees,
	collections storage.Collections,
	events storage.Events,
	lightTransactionResults storage.LightTransactionResults,
	lockManager storage.LockManager,
	dbPath string,
	backfillDelay time.Duration,
) (*ExtendedIndexer, io.Closer, error)

BootstrapExtendedIndexes bootstraps the extended index database, and instantiates the extended indexer.

No error returns are expected during normal operation.

func NewExtendedIndexer

func NewExtendedIndexer(
	log zerolog.Logger,
	metrics module.ExtendedIndexingMetrics,
	db storage.DB,
	lockManager storage.LockManager,
	state protocol.State,
	headers storage.Headers,
	index storage.Index,
	guarantees storage.Guarantees,
	collections storage.Collections,
	events storage.Events,
	results storage.LightTransactionResults,
	indexers []Indexer,
	chainID flow.ChainID,
	backfillDelay time.Duration,
) (*ExtendedIndexer, error)

func (*ExtendedIndexer) IndexBlockData

func (c *ExtendedIndexer) IndexBlockData(
	header *flow.Header,
	transactions []*flow.TransactionBody,
	events []flow.Event,
) error

IndexBlockData stores block data and exposes it to the indexers. It must be called sequentially, with blocks provided in strictly increasing height order.

Typically, this method is invoked when the latest block is received. If the indexer is fully caught up, this latest block will be the next one to process, and indexing it will advance the indexed height.

If the indexer is still catching up, however, the latest block is not immediately needed because the indexer must first process older blocks.

For this reason, we do not index the latest block right away. Instead, we cache it and notify the worker to proceed with the next job.

If the next job is to process the latest block, the cached c.latestBlockData will be used. Otherwise, if the job is to process older blocks, the cache is ignored and the worker fetches the required block data for indexing.

No error returns are expected during normal operation.

func (*ExtendedIndexer) IndexBlockExecutionData

func (c *ExtendedIndexer) IndexBlockExecutionData(
	data *execution_data.BlockExecutionDataEntity,
) error

IndexBlockExecutionData captures the block data and makes it available to the indexers.

No error returns are expected during normal operation.

type Indexer

type Indexer interface {
	// Name returns the name of the indexer.
	Name() string

	// IndexBlockData indexes the block data for the given height.
	// If the header in `data` does not match the expected height, an error is returned.
	//
	// Not safe for concurrent use.
	//
	// Expected error returns during normal operations:
	//   - [ErrAlreadyIndexed]: if the data is already indexed for the height.
	//   - [ErrFutureHeight]: if the data is for a future height.
	IndexBlockData(lctx lockctx.Proof, data BlockData, batch storage.ReaderBatchWriter) error

	// NextHeight returns the next height that the indexer will index.
	//
	// No error returns are expected during normal operation.
	NextHeight() (uint64, error)
}

type IndexerManager

type IndexerManager interface {
	// IndexBlockExecutionData indexes the block data for the given height.
	// If the header in `data` does not match the expected height, an error is returned.
	//
	// Not safe for concurrent use.
	//
	// Expected error returns during normal operations:
	//   - [ErrAlreadyIndexed]: if the data is already indexed for the height.
	//   - [ErrFutureHeight]: if the data is for a future height.
	IndexBlockExecutionData(data *execution_data.BlockExecutionDataEntity) error

	// IndexBlockData indexes the block data for the given height.
	// If the header in `data` does not match the expected height, an error is returned.
	//
	// Not safe for concurrent use.
	//
	// Expected error returns during normal operations:
	//   - [ErrAlreadyIndexed]: if the data is already indexed for the height.
	//   - [ErrFutureHeight]: if the data is for a future height.
	IndexBlockData(header *flow.Header, transactions []*flow.TransactionBody, events []flow.Event) error
}

IndexerManager orchestrates indexing for all extended indexers. It handles both indexing from the latest block submitted via the Index methods, and backfilling from storage.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL