Documentation
¶
Index ¶
- Variables
- func GetPotentialMatches(ctx context.Context, backend MatcherBackend, firstBlock, lastBlock uint64, ...) ([]*types.Log, error)
- type ChainView
- func (cv *ChainView) BlockHash(number uint64) common.Hash
- func (cv *ChainView) BlockId(number uint64) common.Hash
- func (cv *ChainView) HeadNumber() uint64
- func (cv *ChainView) Header(number uint64) *types.Header
- func (cv *ChainView) Receipts(number uint64) types.Receipts
- func (cv *ChainView) SharedRange(cv2 *ChainView) common.Range[uint64]
- type Config
- type FilterMaps
- func (f *FilterMaps) NewMatcherBackend() *FilterMapsMatcherBackend
- func (f *FilterMaps) SetBlockProcessing(blockProcessing bool)
- func (f *FilterMaps) SetTarget(targetView *ChainView, historyCutoff, finalBlock uint64)
- func (f *FilterMaps) Start()
- func (f *FilterMaps) Stop()
- func (f *FilterMaps) WaitIdle()
- type FilterMapsMatcherBackend
- func (fm *FilterMapsMatcherBackend) Close()
- func (fm *FilterMapsMatcherBackend) GetBlockLvPointer(ctx context.Context, blockNumber uint64) (uint64, error)
- func (fm *FilterMapsMatcherBackend) GetFilterMapRow(ctx context.Context, mapIndex, rowIndex uint32, baseLayerOnly bool) (FilterRow, error)
- func (fm *FilterMapsMatcherBackend) GetLogByLvIndex(ctx context.Context, lvIndex uint64) (*types.Log, error)
- func (fm *FilterMapsMatcherBackend) GetParams() *Params
- func (fm *FilterMapsMatcherBackend) SyncLogIndex(ctx context.Context) (SyncRange, error)
- type FilterRow
- type MatcherBackend
- type Params
- type SyncRange
Constants ¶
This section is empty.
Variables ¶
var DefaultParams = Params{ // contains filtered or unexported fields }
DefaultParams is the set of parameters used on mainnet.
var ErrMatchAll = errors.New("match all patterns not supported")
ErrMatchAll is returned when the specified filter matches everything. Handling this case in filtermaps would require an extra special case and would actually be slower than reverting to legacy filter.
var RangeTestParams = Params{ // contains filtered or unexported fields }
RangeTestParams puts one log value per epoch, ensuring block exact tail unindexing for testing
Functions ¶
func GetPotentialMatches ¶
func GetPotentialMatches(ctx context.Context, backend MatcherBackend, firstBlock, lastBlock uint64, addresses []common.Address, topics [][]common.Hash) ([]*types.Log, error)
GetPotentialMatches returns a list of logs that are potential matches for the given filter criteria. If parts of the log index in the searched range are missing or changed during the search process then the resulting logs belonging to that block range might be missing or incorrect. Also note that the returned list may contain false positives.
Types ¶
type ChainView ¶
type ChainView struct {
// contains filtered or unexported fields
}
ChainView represents an immutable view of a chain with a block id and a set of receipts associated to each block number and a block hash associated with all block numbers except the head block. This is because in the future ChainView might represent a view where the head block is currently being created. Block id is a unique identifier that can also be calculated for the head block. Note that the view's head does not have to be the current canonical head of the underlying blockchain, it should only possess the block headers and receipts up until the expected chain view head.
func NewChainView ¶
NewChainView creates a new ChainView.
func (*ChainView) BlockHash ¶ added in v1.15.9
BlockHash returns the block hash belonging to the given block number. Note that the hash of the head block is not returned because ChainView might represent a view where the head block is currently being created.
func (*ChainView) BlockId ¶ added in v1.15.9
BlockId returns the unique block id belonging to the given block number. Note that it is currently equal to the block hash. In the future it might be a different id for future blocks if the log index root becomes part of consensus and therefore rendering the index with the new head will happen before the hash of that new head is available.
func (*ChainView) HeadNumber ¶ added in v1.15.9
HeadNumber returns the head block number of the chain view.
func (*ChainView) Header ¶ added in v1.15.9
Header returns the block header at the given block number.
type Config ¶
type Config struct { History uint64 // number of historical blocks to index Disabled bool // disables indexing completely // This option enables the checkpoint JSON file generator. // If set, the given file will be updated with checkpoint information. ExportFileName string // expect trie nodes of hash based state scheme in the filtermaps key range; // use safe iterator based implementation of DeleteRange that skips them HashScheme bool }
Config contains the configuration options for NewFilterMaps.
type FilterMaps ¶
type FilterMaps struct { Params // contains filtered or unexported fields }
FilterMaps is the in-memory representation of the log index structure that is responsible for building and updating the index according to the canonical chain.
Note that FilterMaps implements the same data structure as proposed in EIP-7745 without the tree hashing and consensus changes: https://eips.ethereum.org/EIPS/eip-7745
func NewFilterMaps ¶
func NewFilterMaps(db ethdb.KeyValueStore, initView *ChainView, historyCutoff, finalBlock uint64, params Params, config Config) *FilterMaps
NewFilterMaps creates a new FilterMaps and starts the indexer.
func (*FilterMaps) NewMatcherBackend ¶
func (f *FilterMaps) NewMatcherBackend() *FilterMapsMatcherBackend
NewMatcherBackend returns a FilterMapsMatcherBackend after registering it in the active matcher set. Note that Close should always be called when the matcher is no longer used.
func (*FilterMaps) SetBlockProcessing ¶
func (f *FilterMaps) SetBlockProcessing(blockProcessing bool)
SetBlockProcessing sets the block processing flag that temporarily suspends log index rendering. Note that SetBlockProcessing never blocks.
func (*FilterMaps) SetTarget ¶
func (f *FilterMaps) SetTarget(targetView *ChainView, historyCutoff, finalBlock uint64)
SetTarget sets a new target chain view for the indexer to render. Note that SetTargetView never blocks.
func (*FilterMaps) Stop ¶
func (f *FilterMaps) Stop()
Stop ensures that the indexer is fully stopped before returning.
func (*FilterMaps) WaitIdle ¶
func (f *FilterMaps) WaitIdle()
WaitIdle blocks until the indexer is in an idle state while synced up to the latest targetView.
type FilterMapsMatcherBackend ¶
type FilterMapsMatcherBackend struct {
// contains filtered or unexported fields
}
FilterMapsMatcherBackend implements MatcherBackend.
func (*FilterMapsMatcherBackend) Close ¶
func (fm *FilterMapsMatcherBackend) Close()
Close removes the matcher from the set of active matchers and ensures that any SyncLogIndex calls are cancelled. Close implements MatcherBackend.
func (*FilterMapsMatcherBackend) GetBlockLvPointer ¶
func (fm *FilterMapsMatcherBackend) GetBlockLvPointer(ctx context.Context, blockNumber uint64) (uint64, error)
GetBlockLvPointer returns the starting log value index where the log values generated by the given block are located. If blockNumber is beyond the current head then the first unoccupied log value index is returned. GetBlockLvPointer implements MatcherBackend.
func (*FilterMapsMatcherBackend) GetFilterMapRow ¶
func (fm *FilterMapsMatcherBackend) GetFilterMapRow(ctx context.Context, mapIndex, rowIndex uint32, baseLayerOnly bool) (FilterRow, error)
GetFilterMapRow returns the given row of the given map. If the row is empty then a non-nil zero length row is returned. If baseLayerOnly is true then only the first baseRowLength entries of the row are guaranteed to be returned. Note that the returned slices should not be modified, they should be copied on write. GetFilterMapRow implements MatcherBackend.
func (*FilterMapsMatcherBackend) GetLogByLvIndex ¶
func (fm *FilterMapsMatcherBackend) GetLogByLvIndex(ctx context.Context, lvIndex uint64) (*types.Log, error)
GetLogByLvIndex returns the log at the given log value index. Note that this function assumes that the log index structure is consistent with the canonical chain at the point where the given log value index points. If this is not the case then an invalid result may be returned or certain logs might not be returned at all. No error is returned though because of an inconsistency between the chain and the log index. It is the caller's responsibility to verify this consistency using SyncLogIndex and re-process certain blocks if necessary. GetLogByLvIndex implements MatcherBackend.
func (*FilterMapsMatcherBackend) GetParams ¶
func (fm *FilterMapsMatcherBackend) GetParams() *Params
GetParams returns the filtermaps parameters. GetParams implements MatcherBackend.
func (*FilterMapsMatcherBackend) SyncLogIndex ¶
func (fm *FilterMapsMatcherBackend) SyncLogIndex(ctx context.Context) (SyncRange, error)
SyncLogIndex ensures that the log index is consistent with the current state of the chain and is synced up to the current head. It blocks until this state is achieved or the context is cancelled. If successful, it returns a SyncRange that contains the latest chain head, the indexed range that is currently consistent with the chain and the valid range that has not been changed and has been consistent with all states of the chain since the previous SyncLogIndex or the creation of the matcher backend.
type FilterRow ¶
type FilterRow []uint32
FilterRow encodes a single row of a filter map as a list of column indices. Note that the values are always stored in the same order as they were added and if the same column index is added twice, it is also stored twice. Order of column indices and potential duplications do not matter when searching for a value but leaving the original order makes reverting to a previous state simpler.
type MatcherBackend ¶
type MatcherBackend interface { GetParams() *Params GetBlockLvPointer(ctx context.Context, blockNumber uint64) (uint64, error) GetFilterMapRow(ctx context.Context, mapIndex, rowIndex uint32, baseLayerOnly bool) (FilterRow, error) GetLogByLvIndex(ctx context.Context, lvIndex uint64) (*types.Log, error) SyncLogIndex(ctx context.Context) (SyncRange, error) Close() }
MatcherBackend defines the functions required for searching in the log index data structure. It is currently implemented by FilterMapsMatcherBackend but once EIP-7745 is implemented and active, these functions can also be trustlessly served by a remote prover.
type Params ¶
type Params struct {
// contains filtered or unexported fields
}
Params defines the basic parameters of the log index structure.
type SyncRange ¶
type SyncRange struct { IndexedView *ChainView // block range where the index has not changed since the last matcher sync // and therefore the set of matches found in this region is guaranteed to // be valid and complete. ValidBlocks common.Range[uint64] // block range indexed according to the given chain head. IndexedBlocks common.Range[uint64] }
SyncRange is returned by MatcherBackend.SyncLogIndex. It contains the latest chain head, the indexed range that is currently consistent with the chain and the valid range that has not been changed and has been consistent with all states of the chain since the previous SyncLogIndex or the creation of the matcher backend.