indexers

package
v0.0.0-...-7ee7fde Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2020 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Overview

Copyright (c) 2018-2020. The asimov developers Copyright (c) 2013-2017 The btcsuite developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2013-2017 The btcsuite developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2018-2020. The asimov developers Copyright (c) 2013-2017 The btcsuite developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2013-2017 The btcsuite developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2013-2017 The btcsuite developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2018-2020. The asimov developers Copyright (c) 2013-2017 The btcsuite developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2018-2020. The asimov developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Copyright (c) 2018-2020. The asimov developers Copyright (c) 2013-2017 The btcsuite developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddrIndex

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

AddrIndex implements a transaction by address index. That is to say, it supports querying all transactions that reference a given address because they are either crediting or debiting the address. The returned transactions are ordered according to their order of appearance in the blockchain. In other words, first by block height and then by offset inside the block.

In addition, support is provided for a memory-only index of unconfirmed transactions such as those which are kept in the memory pool before inclusion in a block.

func NewAddrIndex

func NewAddrIndex(db database.Transactor) *AddrIndex

NewAddrIndex returns a new instance of an indexer that is used to create a mapping of all addresses in the blockchain to the respective transactions that involve them.

It implements the Indexer interface which plugs into the IndexManager that in turn is used by the blockchain package. This allows the index to be seamlessly maintained along with the chain.

func (*AddrIndex) AddUnconfirmedTx

func (idx *AddrIndex) AddUnconfirmedTx(tx *asiutil.Tx, utxoView *txo.UtxoViewpoint)

AddUnconfirmedTx adds all addresses related to the transaction to the unconfirmed (memory-only) address index.

NOTE: This transaction MUST have already been validated by the memory pool before calling this function with it and have all of the inputs available in the provided utxo view. Failure to do so could result in some or all addresses not being indexed.

This function is safe for concurrent access.

func (*AddrIndex) Check

func (idx *AddrIndex) Check(dbTx database.Tx) error

func (*AddrIndex) ConnectBlock

func (idx *AddrIndex) ConnectBlock(dbTx database.Tx, block *asiutil.Block,
	stxos []txo.SpentTxOut, vblock *asiutil.VBlock) error

ConnectBlock is invoked by the index manager when a new block has been connected to the main chain. This indexer adds a mapping for each address the transactions in the block involve.

This is part of the Indexer interface.

func (*AddrIndex) Create

func (idx *AddrIndex) Create(dbTx database.Tx) error

Create is invoked when the indexer manager determines the index needs to be created for the first time. It creates the bucket for the address index.

This is part of the Indexer interface.

func (*AddrIndex) DisconnectBlock

func (idx *AddrIndex) DisconnectBlock(dbTx database.Tx, block *asiutil.Block,
	stxos []txo.SpentTxOut, vblock *asiutil.VBlock) error

DisconnectBlock is invoked by the index manager when a block has been disconnected from the main chain. This indexer removes the address mappings each transaction in the block involve.

This is part of the Indexer interface.

func (*AddrIndex) FetchBlockRegion

func (idx *AddrIndex) FetchBlockRegion(thash []byte) (*database.BlockRegion, error)

Simple interface implementation

func (*AddrIndex) Init

func (idx *AddrIndex) Init() error

Init is only provided to satisfy the Indexer interface as there is nothing to initialize for this index.

This is part of the Indexer interface.

func (*AddrIndex) Key

func (idx *AddrIndex) Key() []byte

Key returns the database key to use for the index as a byte slice.

This is part of the Indexer interface.

func (*AddrIndex) Name

func (idx *AddrIndex) Name() string

Name returns the human-readable name of the index.

This is part of the Indexer interface.

func (*AddrIndex) NeedsInputs

func (idx *AddrIndex) NeedsInputs() bool

NeedsInputs signals that the index requires the referenced inputs in order to properly create the index.

This implements the NeedsInputser interface.

func (*AddrIndex) RemoveUnconfirmedTx

func (idx *AddrIndex) RemoveUnconfirmedTx(hash *common.Hash)

RemoveUnconfirmedTx removes the passed transaction from the unconfirmed (memory-only) address index.

This function is safe for concurrent access.

func (*AddrIndex) TxRegionsForAddress

func (idx *AddrIndex) TxRegionsForAddress(dbTx database.Tx, addr common.IAddress, numToSkip, numRequested uint32, reverse bool) ([]database.BlockRegion, uint32, error)

TxRegionsForAddress returns a slice of block regions which identify each transaction that involves the passed address according to the specified number to skip, number requested, and whether or not the results should be reversed. It also returns the number actually skipped since it could be less in the case where there are not enough entries.

NOTE: These results only include transactions confirmed in blocks. See the UnconfirmedTxnsForAddress method for obtaining unconfirmed transactions that involve a given address.

This function is safe for concurrent access.

func (*AddrIndex) UnconfirmedTxnsForAddress

func (idx *AddrIndex) UnconfirmedTxnsForAddress(addr common.IAddress) []*asiutil.Tx

UnconfirmedTxnsForAddress returns all transactions currently in the unconfirmed (memory-only) address index that involve the passed address. Unsupported address types are ignored and will result in no results.

This function is safe for concurrent access.

type CfIndex

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

CfIndex implements a committed filter (cf) by hash index.

func NewCfIndex

func NewCfIndex(db database.Transactor) *CfIndex

NewCfIndex returns a new instance of an indexer that is used to create a mapping of the hashes of all blocks in the blockchain to their respective committed filters.

It implements the Indexer interface which plugs into the IndexManager that in turn is used by the blockchain package. This allows the index to be seamlessly maintained along with the chain.

func (*CfIndex) Check

func (idx *CfIndex) Check(dbTx database.Tx) error

Checking if there is a new bucket added to this indexer This method is invoked each time when node started.

func (*CfIndex) ConnectBlock

func (idx *CfIndex) ConnectBlock(dbTx database.Tx, block *asiutil.Block,
	stxos []txo.SpentTxOut, vblock *asiutil.VBlock) error

ConnectBlock is invoked by the index manager when a new block has been connected to the main chain. This indexer adds a hash-to-cf mapping for every passed block. This is part of the Indexer interface.

func (*CfIndex) Create

func (idx *CfIndex) Create(dbTx database.Tx) error

Create is invoked when the indexer manager determines the index needs to be created for the first time. It creates buckets for the two hash-based cf indexes (regular only currently).

func (*CfIndex) DisconnectBlock

func (idx *CfIndex) DisconnectBlock(dbTx database.Tx, block *asiutil.Block,
	_ []txo.SpentTxOut, vblock *asiutil.VBlock) error

DisconnectBlock is invoked by the index manager when a block has been disconnected from the main chain. This indexer removes the hash-to-cf mapping for every passed block. This is part of the Indexer interface.

func (*CfIndex) FetchBlockRegion

func (idx *CfIndex) FetchBlockRegion(thash []byte) (*database.BlockRegion, error)

func (*CfIndex) FilterByBlockHash

func (idx *CfIndex) FilterByBlockHash(h *common.Hash,
	filterType protos.FilterType) ([]byte, error)

FilterByBlockHash returns the serialized contents of a block's basic or committed filter.

func (*CfIndex) FilterHashByBlockHash

func (idx *CfIndex) FilterHashByBlockHash(h *common.Hash,
	filterType protos.FilterType) ([]byte, error)

FilterHashByBlockHash returns the serialized contents of a block's basic committed filter hash.

func (*CfIndex) FilterHashesByBlockHashes

func (idx *CfIndex) FilterHashesByBlockHashes(blockHashes []*common.Hash,
	filterType protos.FilterType) ([][]byte, error)

FilterHashesByBlockHashes returns the serialized contents of a block's basic committed filter hash for a set of blocks by hash.

func (*CfIndex) FilterHeaderByBlockHash

func (idx *CfIndex) FilterHeaderByBlockHash(h *common.Hash,
	filterType protos.FilterType) ([]byte, error)

FilterHeaderByBlockHash returns the serialized contents of a block's basic committed filter header.

func (*CfIndex) FilterHeadersByBlockHashes

func (idx *CfIndex) FilterHeadersByBlockHashes(blockHashes []*common.Hash,
	filterType protos.FilterType) ([][]byte, error)

FilterHeadersByBlockHashes returns the serialized contents of a block's basic committed filter header for a set of blocks by hash.

func (*CfIndex) FiltersByBlockHashes

func (idx *CfIndex) FiltersByBlockHashes(blockHashes []*common.Hash,
	filterType protos.FilterType) ([][]byte, error)

FiltersByBlockHashes returns the serialized contents of a block's basic or committed filter for a set of blocks by hash.

func (*CfIndex) Init

func (idx *CfIndex) Init() error

Init initializes the hash-based cf index. This is part of the Indexer interface.

func (*CfIndex) Key

func (idx *CfIndex) Key() []byte

Key returns the database key to use for the index as a byte slice. This is part of the Indexer interface.

func (*CfIndex) Name

func (idx *CfIndex) Name() string

Name returns the human-readable name of the index. This is part of the Indexer interface.

func (*CfIndex) NeedsInputs

func (idx *CfIndex) NeedsInputs() bool

NeedsInputs signals that the index requires the referenced inputs in order to properly create the index.

This implements the NeedsInputser interface.

type Manager

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

Manager defines an index manager that manages multiple optional indexes and implements the blockchain.IndexManager interface so it can be seamlessly plugged into normal chain processing.

func NewManager

func NewManager(db database.Transactor, enabledIndexes []blockchain.Indexer) *Manager

NewManager returns a new index manager with the provided indexes enabled.

The manager returned satisfies the blockchain.IndexManager interface and thus cleanly plugs into the normal blockchain processing path.

func (*Manager) ConnectBlock

func (m *Manager) ConnectBlock(dbTx database.Tx, block *asiutil.Block,
	stxos []txo.SpentTxOut, vblock *asiutil.VBlock) error

ConnectBlock must be invoked when a block is extending the main chain. It keeps track of the state of each index it is managing, performs some sanity checks, and invokes each indexer.

This is part of the blockchain.IndexManager interface.

func (*Manager) DisconnectBlock

func (m *Manager) DisconnectBlock(dbTx database.Tx, block *asiutil.Block,
	stxo []txo.SpentTxOut, vblock *asiutil.VBlock) error

DisconnectBlock must be invoked when a block is being disconnected from the end of the main chain. It keeps track of the state of each index it is managing, performs some sanity checks, and invokes each indexer to remove the index entries associated with the block.

This is part of the blockchain.IndexManager interface.

func (*Manager) Init

func (m *Manager) Init(chain *blockchain.BlockChain, interrupt <-chan struct{}) error

Init initializes the enabled indexes. This is called during chain initialization and primarily consists of catching up all indexes to the current best chain tip. This is necessary since each index can be disabled and re-enabled at any time and attempting to catch-up indexes at the same time new blocks are being downloaded would lead to an overall longer time to catch up due to the I/O contention.

This is part of the blockchain.IndexManager interface.

type NeedsInputser

type NeedsInputser interface {
	NeedsInputs() bool
}

NeedsInputser provides a generic interface for an indexer to specify the it requires the ability to look up inputs for a transaction.

type TemplateIndex

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

TemplateIndex implements a transaction by hash index. That is to say, it supports querying all templates by their hash.

func NewTemplateIndex

func NewTemplateIndex(db database.Transactor) *TemplateIndex

NewTemplateIndex returns a new instance of an indexer that is used to create a mapping of the hashes of all templates in the blockchain to the respective block, location within the block, and size of the template.

It implements the Indexer interface which plugs into the IndexManager that in turn is used by the blockchain package. This allows the index to be seamlessly maintained along with the chain.

func (*TemplateIndex) Check

func (idx *TemplateIndex) Check(dbTx database.Tx) error

Checking if there is a new bucket added to this indexer This method is invoked each time when node started.

func (*TemplateIndex) ConnectBlock

func (idx *TemplateIndex) ConnectBlock(dbTx database.Tx, block *asiutil.Block,
	stxos []txo.SpentTxOut, vblock *asiutil.VBlock) error

ConnectBlock is invoked by the index manager when a new block has been connected to the main chain. This indexer adds a hash-to-transaction mapping for every transaction in the passed block.

This is part of the Indexer interface.

func (*TemplateIndex) Create

func (idx *TemplateIndex) Create(dbTx database.Tx) error

Create is invoked when the indexer manager determines the index needs to be created for the first time. It creates the buckets for the hash-based transaction index and the internal block ID indexes.

This is part of the Indexer interface.

func (*TemplateIndex) DisconnectBlock

func (idx *TemplateIndex) DisconnectBlock(dbTx database.Tx, block *asiutil.Block,
	stxos []txo.SpentTxOut, vblock *asiutil.VBlock) error

DisconnectBlock is invoked by the index manager when a block has been disconnected from the main chain. This indexer removes the hash-to-transaction mapping for every transaction in the block.

This is part of the Indexer interface.

func (*TemplateIndex) FetchBlockRegion

func (idx *TemplateIndex) FetchBlockRegion(txhash []byte) (*database.BlockRegion, error)

FetchBlockRegion returns the block region for the provided key from the index. The block region can in turn be used to load the raw object bytes. When there is no entry for the provided hash, nil will be returned for the both the entry and the error.

This function is safe for concurrent access.

func (*TemplateIndex) Init

func (idx *TemplateIndex) Init() error

func (*TemplateIndex) Key

func (idx *TemplateIndex) Key() []byte

Key returns the database key to use for the index as a byte slice.

This is part of the Indexer interface.

func (*TemplateIndex) Name

func (idx *TemplateIndex) Name() string

Name returns the human-readable name of the index.

This is part of the Indexer interface.

type TxIndex

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

TxIndex implements a transaction by hash index. That is to say, it supports querying all transactions by their hash.

func NewTxIndex

func NewTxIndex(db database.Transactor) *TxIndex

NewTxIndex returns a new instance of an indexer that is used to create a mapping of the hashes of all transactions in the blockchain to the respective block, location within the block, and size of the transaction.

It implements the Indexer interface which plugs into the IndexManager that in turn is used by the blockchain package. This allows the index to be seamlessly maintained along with the chain.

func (*TxIndex) Check

func (idx *TxIndex) Check(dbTx database.Tx) error

Checking if there is a new bucket added to this indexer This method is invoked each time when node started.

func (*TxIndex) ConnectBlock

func (idx *TxIndex) ConnectBlock(dbTx database.Tx, block *asiutil.Block,
	stxos []txo.SpentTxOut, vblock *asiutil.VBlock) error

ConnectBlock is invoked by the index manager when a new block has been connected to the main chain. This indexer adds a hash-to-transaction mapping for every transaction in the passed block.

This is part of the Indexer interface.

func (*TxIndex) Create

func (idx *TxIndex) Create(dbTx database.Tx) error

Create is invoked when the indexer manager determines the index needs to be created for the first time. It creates the buckets for the hash-based transaction index and the internal block ID indexes.

This is part of the Indexer interface.

func (*TxIndex) DisconnectBlock

func (idx *TxIndex) DisconnectBlock(dbTx database.Tx, block *asiutil.Block,
	stxos []txo.SpentTxOut, vblock *asiutil.VBlock) error

DisconnectBlock is invoked by the index manager when a block has been disconnected from the main chain. This indexer removes the hash-to-transaction mapping for every transaction in the block.

This is part of the Indexer interface.

func (*TxIndex) FetchBlockRegion

func (idx *TxIndex) FetchBlockRegion(hash []byte) (*database.BlockRegion, error)

FetchBlockRegion returns the block region for the provided transaction hash from the transaction index. The block region can in turn be used to load the raw transaction bytes. When there is no entry for the provided hash, nil will be returned for the both the entry and the error.

This function is safe for concurrent access.

func (*TxIndex) Init

func (idx *TxIndex) Init() error

Init initializes the hash-based transaction index. In particular, it finds the highest used block ID and stores it for later use when connecting or disconnecting blocks.

This is part of the Indexer interface.

func (*TxIndex) Key

func (idx *TxIndex) Key() []byte

Key returns the database key to use for the index as a byte slice.

This is part of the Indexer interface.

func (*TxIndex) Name

func (idx *TxIndex) Name() string

Name returns the human-readable name of the index.

This is part of the Indexer interface.

Jump to

Keyboard shortcuts

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