Documentation ¶
Overview ¶
Package indexers implements optional block chain indexes.
Index ¶
- func CfIndexInitialized(db database.DB) bool
- func DisableLog()
- func DropAddrIndex(db database.DB, interrupt <-chan struct{}) error
- func DropCfIndex(db database.DB, interrupt <-chan struct{}) error
- func DropFlatUtreexoProofIndex(db database.DB, dataDir string, interrupt <-chan struct{}) error
- func DropTTLIndex(db database.DB, interrupt <-chan struct{}) error
- func DropTxIndex(db database.DB, interrupt <-chan struct{}) error
- func DropUtreexoProofIndex(db database.DB, dataDir string, interrupt <-chan struct{}) error
- func FlatUtreexoProofIndexInitialized(db database.DB) bool
- func UseLogger(logger btclog.Logger)
- func UtreexoProofIndexInitialized(db database.DB) bool
- type AddrIndex
- func (idx *AddrIndex) AddUnconfirmedTx(tx *btcutil.Tx, utxoView *blockchain.UtxoViewpoint)
- func (idx *AddrIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) error
- func (idx *AddrIndex) Create(dbTx database.Tx) error
- func (idx *AddrIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) error
- func (idx *AddrIndex) Flush(_ *chainhash.Hash, _ blockchain.FlushMode, _ bool) error
- func (idx *AddrIndex) Init(_ *blockchain.BlockChain, _ *chainhash.Hash, _ int32) error
- func (idx *AddrIndex) Key() []byte
- func (idx *AddrIndex) Name() string
- func (idx *AddrIndex) NeedsInputs() bool
- func (idx *AddrIndex) PruneBlock(_ database.Tx, _ *chainhash.Hash, _ int32) error
- func (idx *AddrIndex) RemoveUnconfirmedTx(hash *chainhash.Hash)
- func (idx *AddrIndex) TxRegionsForAddress(dbTx database.Tx, addr btcutil.Address, numToSkip, numRequested uint32, ...) ([]database.BlockRegion, uint32, error)
- func (idx *AddrIndex) UnconfirmedTxnsForAddress(addr btcutil.Address) []*btcutil.Tx
- type AssertError
- type CfIndex
- func (idx *CfIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) error
- func (idx *CfIndex) Create(dbTx database.Tx) error
- func (idx *CfIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, _ []blockchain.SpentTxOut) error
- func (idx *CfIndex) FilterByBlockHash(h *chainhash.Hash, filterType wire.FilterType) ([]byte, error)
- func (idx *CfIndex) FilterHashByBlockHash(h *chainhash.Hash, filterType wire.FilterType) ([]byte, error)
- func (idx *CfIndex) FilterHashesByBlockHashes(blockHashes []*chainhash.Hash, filterType wire.FilterType) ([][]byte, error)
- func (idx *CfIndex) FilterHeaderByBlockHash(h *chainhash.Hash, filterType wire.FilterType) ([]byte, error)
- func (idx *CfIndex) FilterHeadersByBlockHashes(blockHashes []*chainhash.Hash, filterType wire.FilterType) ([][]byte, error)
- func (idx *CfIndex) FiltersByBlockHashes(blockHashes []*chainhash.Hash, filterType wire.FilterType) ([][]byte, error)
- func (idx *CfIndex) Flush(_ *chainhash.Hash, _ blockchain.FlushMode, _ bool) error
- func (idx *CfIndex) Init(_ *blockchain.BlockChain, _ *chainhash.Hash, _ int32) error
- func (idx *CfIndex) Key() []byte
- func (idx *CfIndex) Name() string
- func (idx *CfIndex) NeedsInputs() bool
- func (idx *CfIndex) PruneBlock(dbTx database.Tx, blockHash *chainhash.Hash, _ int32) error
- type FlatFileState
- type FlatUtreexoProofIndex
- func (idx *FlatUtreexoProofIndex) CloseUtreexoState() error
- func (idx *FlatUtreexoProofIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) error
- func (idx *FlatUtreexoProofIndex) Create(dbTx database.Tx) error
- func (idx *FlatUtreexoProofIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) error
- func (idx *FlatUtreexoProofIndex) FetchCurrentUtreexoState() ([]*chainhash.Hash, uint64)
- func (idx *FlatUtreexoProofIndex) FetchMultiUtreexoProof(height int32) (*wire.UData, *wire.UData, []utreexo.Hash, error)
- func (idx *FlatUtreexoProofIndex) FetchRemembers(height int32) ([]uint32, error)
- func (idx *FlatUtreexoProofIndex) FetchUtreexoProof(height int32, excludeAccProof bool) (*wire.UData, error)
- func (idx *FlatUtreexoProofIndex) FetchUtreexoState(blockHeight int32) ([]*chainhash.Hash, uint64, error)
- func (idx *FlatUtreexoProofIndex) Flush(bestHash *chainhash.Hash, mode blockchain.FlushMode, onConnect bool) error
- func (idx *FlatUtreexoProofIndex) GenerateUData(dels []wire.LeafData) (*wire.UData, error)
- func (idx *FlatUtreexoProofIndex) GenerateUDataPartial(dels []wire.LeafData, positions []uint64) (*wire.UData, error)
- func (idx *FlatUtreexoProofIndex) GetLeafHashPositions(delHashes []utreexo.Hash) []uint64
- func (idx *FlatUtreexoProofIndex) Init(chain *blockchain.BlockChain, tipHash *chainhash.Hash, tipHeight int32) error
- func (idx *FlatUtreexoProofIndex) Key() []byte
- func (idx *FlatUtreexoProofIndex) MakeMultiBlockProof(currentHeight, proveHeight int32, block *btcutil.Block, currentUD *wire.UData, ...) error
- func (idx *FlatUtreexoProofIndex) Name() string
- func (idx *FlatUtreexoProofIndex) NeedsInputs() bool
- func (idx *FlatUtreexoProofIndex) ProveUtxos(utxos []*blockchain.UtxoEntry, outpoints *[]wire.OutPoint) (*blockchain.ChainTipProof, error)
- func (idx *FlatUtreexoProofIndex) PruneBlock(_ database.Tx, _ *chainhash.Hash, lastKeptHeight int32) error
- func (idx *FlatUtreexoProofIndex) VerifyAccProof(toProve []utreexo.Hash, proof *utreexo.Proof) error
- type Indexer
- type Manager
- func (m *Manager) ConnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) error
- func (m *Manager) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, stxo []blockchain.SpentTxOut) error
- func (m *Manager) Flush(bestHash *chainhash.Hash, mode blockchain.FlushMode, onConnect bool) error
- func (m *Manager) Init(chain *blockchain.BlockChain, interrupt <-chan struct{}) error
- func (m *Manager) PruneBlocks(dbTx database.Tx, lastKeptHeight int32, ...) error
- type NeedsInputser
- type TTLIndex
- func (idx *TTLIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) error
- func (idx *TTLIndex) Create(dbTx database.Tx) error
- func (idx *TTLIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) error
- func (idx *TTLIndex) Flush(_ *chainhash.Hash, _ blockchain.FlushMode, _ bool) error
- func (idx *TTLIndex) GetTTL(op *wire.OutPoint) *int32
- func (idx *TTLIndex) Init(_ *blockchain.BlockChain, _ *chainhash.Hash, _ int32) error
- func (idx *TTLIndex) Key() []byte
- func (idx *TTLIndex) Name() string
- func (idx *TTLIndex) NeedsInputs() bool
- func (idx *TTLIndex) PruneBlock(_ database.Tx, _ *chainhash.Hash, _ int32) error
- type TxIndex
- func (idx *TxIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) error
- func (idx *TxIndex) Create(dbTx database.Tx) error
- func (idx *TxIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) error
- func (idx *TxIndex) Flush(_ *chainhash.Hash, _ blockchain.FlushMode, _ bool) error
- func (idx *TxIndex) Init(_ *blockchain.BlockChain, _ *chainhash.Hash, _ int32) error
- func (idx *TxIndex) Key() []byte
- func (idx *TxIndex) Name() string
- func (idx *TxIndex) PruneBlock(_ database.Tx, _ *chainhash.Hash, _ int32) error
- func (idx *TxIndex) TxBlockRegion(hash *chainhash.Hash) (*database.BlockRegion, error)
- type UtreexoConfig
- type UtreexoProofIndex
- func (idx *UtreexoProofIndex) CloseUtreexoState() error
- func (idx *UtreexoProofIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) error
- func (idx *UtreexoProofIndex) Create(dbTx database.Tx) error
- func (idx *UtreexoProofIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) error
- func (idx *UtreexoProofIndex) FetchCurrentUtreexoState() ([]*chainhash.Hash, uint64)
- func (idx *UtreexoProofIndex) FetchUtreexoProof(hash *chainhash.Hash) (*wire.UData, error)
- func (idx *UtreexoProofIndex) FetchUtreexoState(dbTx database.Tx, blockHash *chainhash.Hash) ([]*chainhash.Hash, uint64, error)
- func (idx *UtreexoProofIndex) Flush(bestHash *chainhash.Hash, mode blockchain.FlushMode, onConnect bool) error
- func (idx *UtreexoProofIndex) GenerateUData(dels []wire.LeafData) (*wire.UData, error)
- func (idx *UtreexoProofIndex) GenerateUDataPartial(dels []wire.LeafData, positions []uint64) (*wire.UData, error)
- func (idx *UtreexoProofIndex) GetLeafHashPositions(delHashes []utreexo.Hash) []uint64
- func (idx *UtreexoProofIndex) Init(chain *blockchain.BlockChain, tipHash *chainhash.Hash, tipHeight int32) error
- func (idx *UtreexoProofIndex) Key() []byte
- func (idx *UtreexoProofIndex) Name() string
- func (idx *UtreexoProofIndex) NeedsInputs() bool
- func (idx *UtreexoProofIndex) ProveUtxos(utxos []*blockchain.UtxoEntry, outpoints *[]wire.OutPoint) (*blockchain.ChainTipProof, error)
- func (idx *UtreexoProofIndex) PruneBlock(_ database.Tx, _ *chainhash.Hash, lastKeptHeight int32) error
- func (idx *UtreexoProofIndex) VerifyAccProof(toProve []utreexo.Hash, proof *utreexo.Proof) error
- type UtreexoState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CfIndexInitialized ¶
CfIndexInitialized returns true if the cfindex has been created previously.
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.
func DropAddrIndex ¶
DropAddrIndex drops the address index from the provided database if it exists.
func DropCfIndex ¶
DropCfIndex drops the CF index from the provided database if exists.
func DropFlatUtreexoProofIndex ¶
DropFlatUtreexoProofIndex drops the address index from the provided database if it exists.
func DropTTLIndex ¶
DropTTLIndex drops the address index from the provided database if it exists.
func DropTxIndex ¶
DropTxIndex drops the transaction index from the provided database if it exists. Since the address index relies on it, the address index will also be dropped when it exists.
func DropUtreexoProofIndex ¶
DropUtreexoProofIndex drops the address index from the provided database if it exists.
func FlatUtreexoProofIndexInitialized ¶
FlatUtreexoProofIndexInitialized returns true if the cfindex has been created previously.
func UseLogger ¶
UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.
func UtreexoProofIndexInitialized ¶
UtreexoProofIndexInitialized returns true if the cfindex has been created previously.
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 ¶
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 *btcutil.Tx, utxoView *blockchain.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) ConnectBlock ¶
func (idx *AddrIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) 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 ¶
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 *btcutil.Block, stxos []blockchain.SpentTxOut) 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) Flush ¶ added in v0.4.0
For AddrIndex, flush is a no-op.
This is part of the Indexer interface.
func (*AddrIndex) Init ¶
func (idx *AddrIndex) Init(_ *blockchain.BlockChain, _ *chainhash.Hash, _ int32) 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 ¶
Key returns the database key to use for the index as a byte slice.
This is part of the Indexer interface.
func (*AddrIndex) Name ¶
Name returns the human-readable name of the index.
This is part of the Indexer interface.
func (*AddrIndex) NeedsInputs ¶
NeedsInputs signals that the index requires the referenced inputs in order to properly create the index.
This implements the NeedsInputser interface.
func (*AddrIndex) PruneBlock ¶
PruneBlock is invoked when an older block is deleted after it's been processed. NOTE: For AddrIndex, it's a no-op as AddrIndex isn't allowed to be enabled with pruning. This may be visited at a later date so that AddrIndex is supported with pruning.
This is part of the Indexer interface.
func (*AddrIndex) RemoveUnconfirmedTx ¶
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 btcutil.Address, 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 ¶
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 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 CfIndex ¶
type CfIndex struct {
// contains filtered or unexported fields
}
CfIndex implements a committed filter (cf) by hash index.
func NewCfIndex ¶
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) ConnectBlock ¶
func (idx *CfIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) 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 ¶
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 *btcutil.Block, _ []blockchain.SpentTxOut) 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) FilterByBlockHash ¶
func (idx *CfIndex) FilterByBlockHash(h *chainhash.Hash, filterType wire.FilterType) ([]byte, error)
FilterByBlockHash returns the serialized contents of a block's basic or committed filter.
func (*CfIndex) FilterHashByBlockHash ¶
func (idx *CfIndex) FilterHashByBlockHash(h *chainhash.Hash, filterType wire.FilterType) ([]byte, error)
FilterHashByBlockHash returns the serialized contents of a block's basic committed filter hash.
func (*CfIndex) FilterHashesByBlockHashes ¶
func (idx *CfIndex) FilterHashesByBlockHashes(blockHashes []*chainhash.Hash, filterType wire.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 *chainhash.Hash, filterType wire.FilterType) ([]byte, error)
FilterHeaderByBlockHash returns the serialized contents of a block's basic committed filter header.
func (*CfIndex) FilterHeadersByBlockHashes ¶
func (idx *CfIndex) FilterHeadersByBlockHashes(blockHashes []*chainhash.Hash, filterType wire.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 []*chainhash.Hash, filterType wire.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) Flush ¶ added in v0.4.0
For CfIndex, flush is a no-op.
This is part of the Indexer interface.
func (*CfIndex) Init ¶
func (idx *CfIndex) Init(_ *blockchain.BlockChain, _ *chainhash.Hash, _ int32) error
Init initializes the hash-based cf index. This is part of the Indexer interface.
func (*CfIndex) Key ¶
Key returns the database key to use for the index as a byte slice. This is part of the Indexer interface.
func (*CfIndex) Name ¶
Name returns the human-readable name of the index. This is part of the Indexer interface.
func (*CfIndex) NeedsInputs ¶
NeedsInputs signals that the index requires the referenced inputs in order to properly create the index.
This implements the NeedsInputser interface.
func (*CfIndex) PruneBlock ¶
PruneBlock is invoked when an older block is deleted after it's been processed. TODO (kcalvinalvin): Consider keeping the filters at a later date to help with reindexing as a pruned node.
This is part of the Indexer interface.
type FlatFileState ¶
type FlatFileState struct {
// contains filtered or unexported fields
}
FlatFileState is the shared state for storing flatfiles. It is specifically designed for the utreexo proofs and stores data as a [key-value] of [height-data].
func NewFlatFileState ¶
func NewFlatFileState() *FlatFileState
NewFlatFileState returns a new but uninitialized FlatFileState.
func (*FlatFileState) BestHeight ¶ added in v0.4.0
func (ff *FlatFileState) BestHeight() int32
BestHeight returns the current latest height of the flat file state.
func (*FlatFileState) DisconnectBlock ¶
func (ff *FlatFileState) DisconnectBlock(height int32) error
DisconnectBlock is used during reorganizations and it deletes the last data stored to the FlatFileState. The height given is only used to check that the height that is requested to be deleted matches the last data stored.
This function is safe for concurrent access.
func (*FlatFileState) FetchData ¶
func (ff *FlatFileState) FetchData(height int32) ([]byte, error)
FetchData fetches the data stored for the given block height. Returns nil if the requested height is greater than the one it stored. Also returns nil if asked to fetch height 0.
This function is safe for concurrent access.
func (*FlatFileState) Init ¶
func (ff *FlatFileState) Init(path, dataName string) error
Init initializes the FlatFileState. If resuming, it loads the offsets onto memory. If starting new, it creates an offsetFile and a dataFile along with the directories those belong in.
func (*FlatFileState) StoreData ¶
func (ff *FlatFileState) StoreData(height int32, data []byte) error
StoreData stores the given byte slice as a new entry in the dataFile. Two important things to note:
1: The height passed in should be of the corresponding Bitcoin block
height and it is used as a key to later fetch the stored data.
2: The height and data passed in should be for the next Bitcoin block in
sequence. If data for block 50 was stored last, then data for block 51 should be passed in.
This function is safe for concurrent access.
type FlatUtreexoProofIndex ¶
type FlatUtreexoProofIndex struct {
// contains filtered or unexported fields
}
FlatUtreexoProofIndex implements a utreexo accumulator proof index for all the blocks. In a flat file.
func NewFlatUtreexoProofIndex ¶
func NewFlatUtreexoProofIndex(pruned bool, chainParams *chaincfg.Params, proofGenInterVal *int32, maxMemoryUsage int64, dataDir string, flush func() error) (*FlatUtreexoProofIndex, error)
NewFlatUtreexoProofIndex returns a new instance of an indexer that is used to create a flat utreexo proof index. The passed in maxMemoryUsage should be in bytes and it determines how much memory the proof index will use up. A maxMemoryUsage of 0 will keep all the elements on disk and a negative maxMemoryUsage will keep all the elements in memory.
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 (*FlatUtreexoProofIndex) CloseUtreexoState ¶ added in v0.4.0
func (idx *FlatUtreexoProofIndex) CloseUtreexoState() error
CloseUtreexoState flushes and closes the utreexo database state.
func (*FlatUtreexoProofIndex) ConnectBlock ¶
func (idx *FlatUtreexoProofIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) error
ConnectBlock is invoked by the index manager when a new block has been connected to the main chain.
This is part of the Indexer interface.
func (*FlatUtreexoProofIndex) Create ¶
func (idx *FlatUtreexoProofIndex) Create(dbTx database.Tx) error
Create is invoked when the indexer manager determines the index needs to be created for the first time.
This is part of the Indexer interface.
func (*FlatUtreexoProofIndex) DisconnectBlock ¶
func (idx *FlatUtreexoProofIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) error
DisconnectBlock is invoked by the index manager when a new block has been disconnected to the main chain.
This is part of the Indexer interface.
func (*FlatUtreexoProofIndex) FetchCurrentUtreexoState ¶
func (idx *FlatUtreexoProofIndex) FetchCurrentUtreexoState() ([]*chainhash.Hash, uint64)
FetchCurrentUtreexoState returns the current utreexo state.
func (*FlatUtreexoProofIndex) FetchMultiUtreexoProof ¶
func (idx *FlatUtreexoProofIndex) FetchMultiUtreexoProof(height int32) ( *wire.UData, *wire.UData, []utreexo.Hash, error)
FetchMultiUtreexoProof fetches the utreexo data, multi-block proof, and the hashes for the given height. Attempting to fetch multi-block proof at a height where there weren't any mulit-block proof generated will result in an error.
func (*FlatUtreexoProofIndex) FetchRemembers ¶
func (idx *FlatUtreexoProofIndex) FetchRemembers(height int32) ([]uint32, error)
FetchRemembers fetches the remember indexes of the desired block height.
func (*FlatUtreexoProofIndex) FetchUtreexoProof ¶
func (idx *FlatUtreexoProofIndex) FetchUtreexoProof(height int32, excludeAccProof bool) ( *wire.UData, error)
FetchUtreexoProof returns the Utreexo proof data for the given block height.
func (*FlatUtreexoProofIndex) FetchUtreexoState ¶
func (idx *FlatUtreexoProofIndex) FetchUtreexoState(blockHeight int32) ([]*chainhash.Hash, uint64, error)
FetchUtreexoState returns the utreexo state at the desired block.
func (*FlatUtreexoProofIndex) Flush ¶ added in v0.4.0
func (idx *FlatUtreexoProofIndex) Flush(bestHash *chainhash.Hash, mode blockchain.FlushMode, onConnect bool) error
Flush flushes the utreexo state. The different modes pass in as an argument determine if the utreexo state will be flushed or not.
The onConnect bool is if the Flush is called on a block connect or a disconnect. It's important as it determines if we flush the main node db before attempting to flush the utreexo state. For the utreexo state to be recoverable, it has to be behind whatever tip the main database is at. On block connects, we always want to flush first but on disconnects, we want to flush first before the data necessary undo data is removed.
func (*FlatUtreexoProofIndex) GenerateUData ¶
GenerateUData generates utreexo data for the dels passed in. Height passed in should either be of block height of where the deletions are happening or just the lastest block height for mempool tx proof generation.
func (*FlatUtreexoProofIndex) GenerateUDataPartial ¶
func (idx *FlatUtreexoProofIndex) GenerateUDataPartial(dels []wire.LeafData, positions []uint64) (*wire.UData, error)
GenerateUDataPartial generates a utreexo data based on the current state of the accumulator. It leaves out the full proof hashes and only fetches the requested positions.
func (*FlatUtreexoProofIndex) GetLeafHashPositions ¶
func (idx *FlatUtreexoProofIndex) GetLeafHashPositions(delHashes []utreexo.Hash) []uint64
GetLeafHashPositions returns the positions of the passed in hashes.
func (*FlatUtreexoProofIndex) Init ¶
func (idx *FlatUtreexoProofIndex) Init(chain *blockchain.BlockChain, tipHash *chainhash.Hash, tipHeight int32) error
Init initializes the flat utreexo proof index. This is part of the Indexer interface.
func (*FlatUtreexoProofIndex) Key ¶
func (idx *FlatUtreexoProofIndex) Key() []byte
Key returns the database key to use for the index as a byte slice. This is part of the Indexer interface.
NOTE This key is NEVER used as we store everything in flat files for flat utreexo proof index. It is just here to abide by the indexer interface.
func (*FlatUtreexoProofIndex) MakeMultiBlockProof ¶
func (idx *FlatUtreexoProofIndex) MakeMultiBlockProof(currentHeight, proveHeight int32, block *btcutil.Block, currentUD *wire.UData, stxos []blockchain.SpentTxOut) error
MakeMultiBlockProof reverses the utreexo accumulator state to the multi-block proof generation height and makes a proof of all the stxos in the upcoming interval. The utreexo state is caught back up to the current height after the mulit-block proof is generated.
func (*FlatUtreexoProofIndex) Name ¶
func (idx *FlatUtreexoProofIndex) Name() string
Name returns the human-readable name of the index.
This is part of the Indexer interface.
func (*FlatUtreexoProofIndex) NeedsInputs ¶
func (idx *FlatUtreexoProofIndex) NeedsInputs() bool
NeedsInputs signals that the index requires the referenced inputs in order to properly create the index.
This implements the NeedsInputser interface.
func (*FlatUtreexoProofIndex) ProveUtxos ¶
func (idx *FlatUtreexoProofIndex) ProveUtxos(utxos []*blockchain.UtxoEntry, outpoints *[]wire.OutPoint) (*blockchain.ChainTipProof, error)
ProveUtxos returns an accumulator proof of the outpoints passed in with respect to the UTXO state at chaintip.
NOTE The accumulator state differs at every block height. The caller must take into consideration that an accumulator proof at block X will not be valid at block height X+1.
This function is safe for concurrent access.
func (*FlatUtreexoProofIndex) PruneBlock ¶
func (idx *FlatUtreexoProofIndex) PruneBlock(_ database.Tx, _ *chainhash.Hash, lastKeptHeight int32) error
PruneBlock is invoked when an older block is deleted after it's been processed.
This is part of the Indexer interface.
func (*FlatUtreexoProofIndex) VerifyAccProof ¶
func (idx *FlatUtreexoProofIndex) VerifyAccProof(toProve []utreexo.Hash, proof *utreexo.Proof) error
VerifyAccProof verifies the given accumulator proof. Returns an error if the verification failed.
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(*blockchain.BlockChain, *chainhash.Hash, int32) error // ConnectBlock is invoked when a new block has been connected to the // main chain. The set of output spent within a block is also passed in // so indexers can access the pevious output scripts input spent if // required. ConnectBlock(database.Tx, *btcutil.Block, []blockchain.SpentTxOut) error // DisconnectBlock is invoked when a block has been disconnected from // the main chain. The set of outputs scripts that were spent within // this block is also returned so indexers can clean up the prior index // state for this block DisconnectBlock(database.Tx, *btcutil.Block, []blockchain.SpentTxOut) error // PruneBlock is invoked when an older block is deleted after it's been // processed. PruneBlock(dbTx database.Tx, deletedBlock *chainhash.Hash, lastKeptHeight int32) error // Flush flushes the index. Flush(*chainhash.Hash, blockchain.FlushMode, bool) 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 ¶
func (m *Manager) ConnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) 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 *btcutil.Block, stxo []blockchain.SpentTxOut) 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) Flush ¶ added in v0.4.0
Flush flushes the enabled indexes. For the indexers that do not need to be flushed, it's a no-op.
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.
func (*Manager) PruneBlocks ¶
func (m *Manager) PruneBlocks(dbTx database.Tx, lastKeptHeight int32, fetchHashFunc func(blockHeight int32) (*chainhash.Hash, error)) error
PruneBlock is invoked when an older block is deleted after it's been processed.
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 TTLIndex ¶
type TTLIndex struct {
// contains filtered or unexported fields
}
TTLIndex implements a time to live index for all the STXOs.
func NewTTLIndex ¶
NewTTLIndex returns a new instance of an indexer that is used to create a mapping of all STXOs to their time to live value.
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 (*TTLIndex) ConnectBlock ¶
func (idx *TTLIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) error
ConnectBlock is invoked by the index manager when a new block has been connected to the main chain. This indexer stores ttl value for every stxo in the block.
This is part of the Indexer interface.
func (*TTLIndex) Create ¶
Create is invoked when the indexer manager determines the index needs to be created for the first time. It creates the bucket for the ttl index.
This is part of the Indexer interface.
func (*TTLIndex) DisconnectBlock ¶
func (idx *TTLIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) error
DisconnectBlock is invoked by the index manager when a new block has been disconnected to the main chain. This indexer removes the ttl value for every stxo in the block.
This is part of the Indexer interface.
func (*TTLIndex) Flush ¶ added in v0.4.0
For TTLIndex, flush is a no-op.
This is part of the Indexer interface.
func (*TTLIndex) GetTTL ¶
GetTTL returns a pointer to the ttl value of a transaction outpout. Returns nil for a UTXO.
This function is safe for concurrent access.
func (*TTLIndex) Init ¶
func (idx *TTLIndex) Init(_ *blockchain.BlockChain, _ *chainhash.Hash, _ int32) error
Init initializes the time to live index. This is part of the Indexer interface.
func (*TTLIndex) Key ¶
Key returns the database key to use for the index as a byte slice. This is part of the Indexer interface.
func (*TTLIndex) Name ¶
Name returns the human-readable name of the index.
This is part of the Indexer interface.
func (*TTLIndex) NeedsInputs ¶
NeedsInputs signals that the index requires the referenced inputs in order to properly create the index.
This implements the NeedsInputser interface.
func (*TTLIndex) PruneBlock ¶
PruneBlock is invoked when an older block is deleted after it's been processed. NOTE: For TTLIndex, it's a no-op as TTLIndex isn't allowed to be enabled with pruning. This may be visited at a later date so that TTLIndex is supported with pruning.
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 ¶
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 ¶
func (idx *TxIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) 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 ¶
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 *btcutil.Block, stxos []blockchain.SpentTxOut) 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) Flush ¶ added in v0.4.0
NOTE: For TxIndex, flush is a no-op.
This is part of the Indexer interface.
func (*TxIndex) Init ¶
func (idx *TxIndex) Init(_ *blockchain.BlockChain, _ *chainhash.Hash, _ int32) 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 ¶
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) PruneBlock ¶
PruneBlock is invoked when an older block is deleted after it's been processed. NOTE: For TxIndex, it's a no-op as TxIndex isn't allowed to be enabled with pruning. This may be visited at a later date so that TxIndex is supported with pruning.
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 UtreexoConfig ¶
type UtreexoConfig struct { // MaxMemoryUsage is the desired memory usage for the utreexo state cache. MaxMemoryUsage int64 // Params are the Bitcoin network parameters. This is used to separately store // different accumulators. Params *chaincfg.Params // If the node is a pruned node or not. Pruned bool // DataDir is the base path of where all the data for this node will be stored. // Utreexo has custom storage method and that data will be stored under this // directory. DataDir string // Name is what the type of utreexo proof indexer this utreexo state is related // to. Name string // FlushMainDB flushes the main database where all the data is stored. FlushMainDB func() error }
UtreexoConfig is a descriptor which specifies the Utreexo state instance configuration.
type UtreexoProofIndex ¶
type UtreexoProofIndex struct {
// contains filtered or unexported fields
}
UtreexoProofIndex implements a utreexo accumulator proof index for all the blocks.
func NewUtreexoProofIndex ¶
func NewUtreexoProofIndex(db database.DB, pruned bool, maxMemoryUsage int64, chainParams *chaincfg.Params, dataDir string, flush func() error) (*UtreexoProofIndex, error)
NewUtreexoProofIndex returns a new instance of an indexer that is used to create a utreexo proof index using the database passed in. The passed in maxMemoryUsage should be in bytes and it determines how much memory the proof index will use up. A maxMemoryUsage of 0 will keep all the elements on disk and a negative maxMemoryUsage will keep all the elements in memory.
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 (*UtreexoProofIndex) CloseUtreexoState ¶ added in v0.4.0
func (idx *UtreexoProofIndex) CloseUtreexoState() error
CloseUtreexoState flushes and closes the utreexo database state.
func (*UtreexoProofIndex) ConnectBlock ¶
func (idx *UtreexoProofIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) error
ConnectBlock is invoked by the index manager when a new block has been connected to the main chain.
This is part of the Indexer interface.
func (*UtreexoProofIndex) Create ¶
func (idx *UtreexoProofIndex) 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 utreexo proof index.
This is part of the Indexer interface.
func (*UtreexoProofIndex) DisconnectBlock ¶
func (idx *UtreexoProofIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, stxos []blockchain.SpentTxOut) error
DisconnectBlock is invoked by the index manager when a new block has been disconnected to the main chain.
This is part of the Indexer interface.
func (*UtreexoProofIndex) FetchCurrentUtreexoState ¶
func (idx *UtreexoProofIndex) FetchCurrentUtreexoState() ([]*chainhash.Hash, uint64)
FetchCurrentUtreexoState returns the current utreexo state.
func (*UtreexoProofIndex) FetchUtreexoProof ¶
FetchUtreexoProof returns the Utreexo proof data for the given block hash.
func (*UtreexoProofIndex) FetchUtreexoState ¶
func (idx *UtreexoProofIndex) FetchUtreexoState(dbTx database.Tx, blockHash *chainhash.Hash) ([]*chainhash.Hash, uint64, error)
FetchUtreexoState returns the utreexo state at the desired block.
func (*UtreexoProofIndex) Flush ¶ added in v0.4.0
func (idx *UtreexoProofIndex) Flush(bestHash *chainhash.Hash, mode blockchain.FlushMode, onConnect bool) error
Flush flushes the utreexo state. The different modes pass in as an argument determine if the utreexo state will be flushed or not.
The onConnect bool is if the Flush is called on a block connect or a disconnect. It's important as it determines if we flush the main node db before attempting to flush the utreexo state. For the utreexo state to be recoverable, it has to be behind whatever tip the main database is at. On block connects, we always want to flush first but on disconnects, we want to flush first before the data necessary undo data is removed.
func (*UtreexoProofIndex) GenerateUData ¶
GenerateUData generates utreexo data for the dels passed in. Height passed in should either be of block height of where the deletions are happening or just the lastest block height for mempool tx proof generation.
func (*UtreexoProofIndex) GenerateUDataPartial ¶
func (idx *UtreexoProofIndex) GenerateUDataPartial(dels []wire.LeafData, positions []uint64) (*wire.UData, error)
GenerateUDataPartial generates a utreexo data based on the current state of the accumulator. It leaves out the full proof hashes and only fetches the requested positions.
func (*UtreexoProofIndex) GetLeafHashPositions ¶
func (idx *UtreexoProofIndex) GetLeafHashPositions(delHashes []utreexo.Hash) []uint64
GetLeafHashPositions returns the positions of the passed in hashes.
func (*UtreexoProofIndex) Init ¶
func (idx *UtreexoProofIndex) Init(chain *blockchain.BlockChain, tipHash *chainhash.Hash, tipHeight int32) error
Init initializes the utreexo proof index. This is part of the Indexer interface.
func (*UtreexoProofIndex) Key ¶
func (idx *UtreexoProofIndex) Key() []byte
Key returns the database key to use for the index as a byte slice. This is part of the Indexer interface.
func (*UtreexoProofIndex) Name ¶
func (idx *UtreexoProofIndex) Name() string
Name returns the human-readable name of the index.
This is part of the Indexer interface.
func (*UtreexoProofIndex) NeedsInputs ¶
func (idx *UtreexoProofIndex) NeedsInputs() bool
NeedsInputs signals that the index requires the referenced inputs in order to properly create the index.
This implements the NeedsInputser interface.
func (*UtreexoProofIndex) ProveUtxos ¶
func (idx *UtreexoProofIndex) ProveUtxos(utxos []*blockchain.UtxoEntry, outpoints *[]wire.OutPoint) (*blockchain.ChainTipProof, error)
ProveUtxos returns an accumulator proof of the outpoints passed in with respect to the UTXO state at chaintip.
NOTE The accumulator state differs at every block height. The caller must take into consideration that an accumulator proof at block X will not be valid at block height X+1.
This function is safe for concurrent access.
func (*UtreexoProofIndex) PruneBlock ¶
func (idx *UtreexoProofIndex) PruneBlock(_ database.Tx, _ *chainhash.Hash, lastKeptHeight int32) error
PruneBlock is invoked when an older block is deleted after it's been processed.
This is part of the Indexer interface.
func (*UtreexoProofIndex) VerifyAccProof ¶
VerifyAccProof verifies the given accumulator proof. Returns an error if the verification failed.
type UtreexoState ¶
type UtreexoState struct {
// contains filtered or unexported fields
}
UtreexoState is a wrapper around the raw accumulator with configuration information. It contains the entire, non-pruned accumulator.
func InitUtreexoState ¶
func InitUtreexoState(cfg *UtreexoConfig, chain *blockchain.BlockChain, tipHash *chainhash.Hash, tipHeight int32) (*UtreexoState, error)
InitUtreexoState returns an initialized utreexo state. If there isn't an existing state on disk, it creates one and returns it. maxMemoryUsage of 0 will keep every element on disk. A negaive maxMemoryUsage will load every element to the memory.