Documentation ¶
Overview ¶
Package indexers implements optional block chain indexes.
Index ¶
- Constants
- type AssertError
- type Checkpoint
- func (c *Checkpoint) DataExtension() string
- func (c *Checkpoint) Deserialize(r io.Reader) (err error)
- func (c *Checkpoint) EffectivePeriod() uint32
- func (c *Checkpoint) Generator() func(buf []byte) checkpoint.ICheckPoint
- func (c *Checkpoint) GetHeight() uint32
- func (c *Checkpoint) Key() string
- func (c *Checkpoint) LogError(err error)
- func (c *Checkpoint) OnBlockSaved(block *types.DposBlock)
- func (c *Checkpoint) OnInit()
- func (c *Checkpoint) OnRollbackTo(height uint32) error
- func (c *Checkpoint) Priority() checkpoint.Priority
- func (c *Checkpoint) SavePeriod() uint32
- func (c *Checkpoint) Serialize(w io.Writer) (err error)
- func (c *Checkpoint) SetHeight(height uint32)
- func (c *Checkpoint) Snapshot() checkpoint.ICheckPoint
- func (c *Checkpoint) StartHeight() uint32
- type IChain
- type ITxStore
- type IndexManager
- type Indexer
- type Manager
- func (m *Manager) ConnectBlock(dbTx database.Tx, block *types.Block) error
- func (m *Manager) DisconnectBlock(dbTx database.Tx, block *types.Block) error
- func (m *Manager) FetchTx(txID common.Uint256) (*types.Transaction, uint32, error)
- func (m *Manager) FetchUTXO(programHash *common.Uint168) ([]*types.UTXO, error)
- func (m *Manager) FetchUnspent(txID common.Uint256) ([]uint16, error)
- func (m *Manager) Init(chain IChain, interrupt <-chan struct{}) error
- func (m *Manager) IsTx3Exist(txHash *common.Uint256) bool
- type Tx3Index
- func (idx *Tx3Index) ConnectBlock(dbTx database.Tx, block *types.Block) error
- func (idx *Tx3Index) Create(dbTx database.Tx) error
- func (idx *Tx3Index) DisconnectBlock(dbTx database.Tx, block *types.Block) error
- func (idx *Tx3Index) Init() error
- func (idx *Tx3Index) Key() []byte
- func (idx *Tx3Index) Name() string
- type TxCache
- type TxIndex
- func (idx *TxIndex) ConnectBlock(dbTx database.Tx, block *types.Block) error
- func (idx *TxIndex) Create(dbTx database.Tx) error
- func (idx *TxIndex) DisconnectBlock(dbTx database.Tx, block *types.Block) error
- func (idx *TxIndex) Init() error
- func (idx *TxIndex) Key() []byte
- func (idx *TxIndex) Name() string
- func (idx *TxIndex) TxBlockRegion(hash *common.Uint256) (*database.BlockRegion, error)
- type TxInfo
- type UnspentIndex
- func (idx *UnspentIndex) ConnectBlock(dbTx database.Tx, block *types.Block) error
- func (idx *UnspentIndex) Create(dbTx database.Tx) error
- func (idx *UnspentIndex) DisconnectBlock(dbTx database.Tx, block *types.Block) error
- func (idx *UnspentIndex) FetchTx(txID common.Uint256) (*types.Transaction, uint32, error)
- func (idx *UnspentIndex) Init() error
- func (idx *UnspentIndex) Key() []byte
- func (idx *UnspentIndex) Name() string
- type UtxoIndex
- func (idx *UtxoIndex) ConnectBlock(dbTx database.Tx, block *types.Block) error
- func (idx *UtxoIndex) Create(dbTx database.Tx) error
- func (idx *UtxoIndex) DisconnectBlock(dbTx database.Tx, block *types.Block) error
- func (idx *UtxoIndex) Init() error
- func (idx *UtxoIndex) Key() []byte
- func (idx *UtxoIndex) Name() string
Constants ¶
const (
// TrimmingInterval is the interval number for each cache trimming.
TrimmingInterval = 10000
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AssertError ¶
type AssertError string
AssertError identifies an error that indicates an internal code consistency issue and should be treated as a critical and unrecoverable error.
func (AssertError) Error ¶
func (e AssertError) Error() string
Error returns the assertion error as a huma-readable string and satisfies the error interface.
type Checkpoint ¶
Checkpoint hold all unspent txn cache to recover from scratch.
func NewCheckpoint ¶
func NewCheckpoint(unspentIndex *UnspentIndex) *Checkpoint
func (*Checkpoint) DataExtension ¶
func (c *Checkpoint) DataExtension() string
func (*Checkpoint) Deserialize ¶
func (c *Checkpoint) Deserialize(r io.Reader) (err error)
func (*Checkpoint) EffectivePeriod ¶
func (c *Checkpoint) EffectivePeriod() uint32
func (*Checkpoint) Generator ¶
func (c *Checkpoint) Generator() func(buf []byte) checkpoint.ICheckPoint
func (*Checkpoint) GetHeight ¶
func (c *Checkpoint) GetHeight() uint32
func (*Checkpoint) Key ¶
func (c *Checkpoint) Key() string
func (*Checkpoint) LogError ¶
func (c *Checkpoint) LogError(err error)
func (*Checkpoint) OnBlockSaved ¶
func (c *Checkpoint) OnBlockSaved(block *types.DposBlock)
func (*Checkpoint) OnInit ¶
func (c *Checkpoint) OnInit()
func (*Checkpoint) OnRollbackTo ¶
func (c *Checkpoint) OnRollbackTo(height uint32) error
func (*Checkpoint) Priority ¶
func (c *Checkpoint) Priority() checkpoint.Priority
func (*Checkpoint) SavePeriod ¶
func (c *Checkpoint) SavePeriod() uint32
func (*Checkpoint) SetHeight ¶
func (c *Checkpoint) SetHeight(height uint32)
func (*Checkpoint) Snapshot ¶
func (c *Checkpoint) Snapshot() checkpoint.ICheckPoint
func (*Checkpoint) StartHeight ¶
func (c *Checkpoint) StartHeight() uint32
type IndexManager ¶
type IndexManager interface { // Init is invoked during chain initialize in order to allow the index // manager to initialize itself and any indexes it is managing. The // channel parameter specifies a channel the caller can close to signal // that the process should be interrupted. It can be nil if that // behavior is not desired. Init(IChain, <-chan struct{}) error // ConnectBlock is invoked when a new block has been connected to the // main chain. ConnectBlock(database.Tx, *types.Block) error // DisconnectBlock is invoked when a block has been disconnected from // the main chain. DisconnectBlock(database.Tx, *types.Block) error // FetchTx retrieval a transaction and a block hash where it // located by transaction hash FetchTx(txID common.Uint256) (*types.Transaction, uint32, error) // FetchUnspent retrieval the unspent set of transaction by its hash FetchUnspent(txID common.Uint256) ([]uint16, error) // FetchUTXO retrieval the utxo set of a account address FetchUTXO(programHash *common.Uint168) ([]*types.UTXO, error) // IsTx3Exist use to find if tx3 exist in db IsTx3Exist(txHash *common.Uint256) bool }
IndexManager provides a generic interface that the is called when blocks are connected and disconnected to and from the tip of the main chain for the purpose of supporting optional indexes.
type Indexer ¶
type Indexer interface { // Key returns the key of the index as a byte slice. Key() []byte // Name returns the human-readable name of the index. Name() string // Create is invoked when the indexer manager determines the index needs // to be created for the first time. Create(dbTx database.Tx) error // Init is invoked when the index manager is first initializing the // index. This differs from the Create method in that it is called on // every load, including the case the index was just created. Init() error // ConnectBlock is invoked when a new block has been connected to the // main chain. ConnectBlock(database.Tx, *types.Block) error // DisconnectBlock is invoked when a block has been disconnected from // the main chain. DisconnectBlock(database.Tx, *types.Block) error }
Indexer provides a generic interface for an indexer that is managed by an index manager such as the Manager type provided by this package.
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 ¶
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 ¶
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 ¶
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) FetchUnspent ¶
func (*Manager) Init ¶
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 Tx3Index ¶
type Tx3Index struct {
// contains filtered or unexported fields
}
Tx3Index implements tx3 hash set which come from side chain.
func NewTx3Index ¶
NewTx3Index returns a new instance of an indexer that is used to create a mapping of the program hashes of all addresses be used in the blockchain to the their utxo.
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 (*Tx3Index) ConnectBlock ¶
ConnectBlock is invoked by the index manager when a new block has been connected to the main chain. This indexer maintains a tx3 hash mapping for every transaction in the passed block.
This is part of the Indexer interface.
func (*Tx3Index) Create ¶
Create is invoked when the indexer manager determines the index needs to be created for the first time. It creates the buckets for the tx3 index.
This is part of the Indexer interface.
func (*Tx3Index) DisconnectBlock ¶
DisconnectBlock is invoked by the index manager when a block has been disconnected from the main chain. This indexer removes the tx3 hash mapping for every transaction in the block.
This is part of the Indexer interface.
func (*Tx3Index) Init ¶
Init initializes the hash-based tx3 index. This is part of the Indexer interface.
type TxCache ¶
func NewTxCache ¶
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 ¶
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) ConnectBlock ¶
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 ¶
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 ¶
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) Init ¶
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 ¶
Key returns the database key to use for the index as a byte slice.
This is part of the Indexer interface.
func (*TxIndex) Name ¶
Name returns the human-readable name of the index.
This is part of the Indexer interface.
func (*TxIndex) TxBlockRegion ¶
TxBlockRegion 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.
type UnspentIndex ¶
type UnspentIndex struct {
// contains filtered or unexported fields
}
UnspentIndex implements a unspent set by tx hash index. That is to say, it supports querying all unspent index by their tx hash.
func NewUnspentIndex ¶
func NewUnspentIndex(db database.DB, params *config.Params) *UnspentIndex
NewUnspentIndex 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 index of output which unspent in 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 (*UnspentIndex) ConnectBlock ¶
ConnectBlock is invoked by the index manager when a new block has been connected to the main chain. This indexer maintains a hash-to-unspent mapping for every transaction in the passed block.
This is part of the Indexer interface.
func (*UnspentIndex) Create ¶
func (idx *UnspentIndex) 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 unspent index.
This is part of the Indexer interface.
func (*UnspentIndex) DisconnectBlock ¶
DisconnectBlock is invoked by the index manager when a block has been disconnected from the main chain. This indexer removes the hash-to-unspent mapping for every transaction in the block.
This is part of the Indexer interface.
func (*UnspentIndex) FetchTx ¶
func (idx *UnspentIndex) FetchTx(txID common.Uint256) (*types.Transaction, uint32, error)
func (*UnspentIndex) Init ¶
func (idx *UnspentIndex) Init() error
Init initializes the hash-based unspent index. This is part of the Indexer interface.
func (*UnspentIndex) Key ¶
func (idx *UnspentIndex) Key() []byte
Key returns the database key to use for the index as a byte slice.
This is part of the Indexer interface.
func (*UnspentIndex) Name ¶
func (idx *UnspentIndex) Name() string
Name returns the human-readable name of the index.
This is part of the Indexer interface.
type UtxoIndex ¶
type UtxoIndex struct {
// contains filtered or unexported fields
}
UtxoIndex implements a utxo by tx hash index.
func NewUtxoIndex ¶
NewUtxoIndex returns a new instance of an indexer that is used to create a mapping of the program hashes of all addresses be used in the blockchain to the their utxo.
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 (*UtxoIndex) ConnectBlock ¶
ConnectBlock is invoked by the index manager when a new block has been connected to the main chain. This indexer maintains a hash-to-utxo mapping for every transaction in the passed block.
This is part of the Indexer interface.
func (*UtxoIndex) Create ¶
Create is invoked when the indexer manager determines the index needs to be created for the first time. It creates the buckets for the utxo index.
This is part of the Indexer interface.
func (*UtxoIndex) DisconnectBlock ¶
DisconnectBlock is invoked by the index manager when a block has been disconnected from the main chain. This indexer removes the hash-to-utxos mapping for every transaction in the block.
This is part of the Indexer interface.
func (*UtxoIndex) Init ¶
Init initializes the hash-based utxo index. This is part of the Indexer interface.