blockindex

package
v2.1.0-rc17 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BlockBloomFilterNamespace indicated the kvstore namespace to store block BloomFilters
	BlockBloomFilterNamespace = "BlockBloomFilters"
	// RangeBloomFilterNamespace indicates the kvstore namespace to store range BloomFilters
	RangeBloomFilterNamespace = "RangeBloomFilters"
	// CurrentHeightKey indicates the key of current bf indexer height in underlying DB
	CurrentHeightKey = "CurrentHeight"
)

Variables

View Source
var DefaultConfig = Config{
	RangeBloomFilterNumElements: 100000,
	RangeBloomFilterSize:        1200000,
	RangeBloomFilterNumHash:     8,
}

DefaultConfig is the default config of indexer

View Source
var (

	// ErrActionIndexNA indicates action index is not supported
	ErrActionIndexNA = errors.New("action index not supported")
)
View Source
var (
	// TotalBloomFilterNamespace indicates the kvstore namespace to store total ranges
	TotalBloomFilterNamespace = []byte("TotalBloomFilters")
)

Functions

This section is empty.

Types

type ActionIndex

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

ActionIndex change private to public for mock Indexer

func (*ActionIndex) BlockHeight

func (a *ActionIndex) BlockHeight() uint64

Height returns the block height of action

func (*ActionIndex) Deserialize

func (a *ActionIndex) Deserialize(buf []byte) error

Deserialize from byte stream

func (*ActionIndex) Serialize

func (a *ActionIndex) Serialize() []byte

Serialize into byte stream

func (*ActionIndex) TxNumber added in v2.0.6

func (a *ActionIndex) TxNumber() uint32

TxNumber returns the transaction number of action

type BlockIndex

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

BlockIndex change private to public for mock Indexer

func (*BlockIndex) Deserialize

func (b *BlockIndex) Deserialize(buf []byte) error

Deserialize from byte stream

func (*BlockIndex) Hash

func (b *BlockIndex) Hash() []byte

Hash returns the hash

func (*BlockIndex) NumAction

func (b *BlockIndex) NumAction() uint32

NumAction returns number of actions

func (*BlockIndex) Serialize

func (b *BlockIndex) Serialize() []byte

Serialize into byte stream

func (*BlockIndex) TsfAmount

func (b *BlockIndex) TsfAmount() *big.Int

TsfAmount returns transfer amount

type BloomFilterIndexer

type BloomFilterIndexer interface {
	blockdao.BlockIndexer
	// RangeBloomFilterNumElements returns the number of elements that each rangeBloomfilter indexes
	RangeBloomFilterNumElements() uint64
	// BlockFilterByHeight returns the block-level bloomfilter which includes not only topic but also address of logs info by given block height
	BlockFilterByHeight(uint64) (bloom.BloomFilter, error)
	// FilterBlocksInRange returns the block numbers by given logFilter in range from start to end
	FilterBlocksInRange(*filter.LogFilter, uint64, uint64, uint64) ([]uint64, error)
}

BloomFilterIndexer is the interface for bloomfilter indexer

func NewBloomfilterIndexer

func NewBloomfilterIndexer(kv db.KVStore, cfg Config) (BloomFilterIndexer, error)

NewBloomfilterIndexer creates a new bloomfilterindexer struct by given kvstore and rangebloomfilter size

type Config

type Config struct {
	// RangeBloomFilterNumElements is the number of elements each rangeBloomfilter will store in bloomfilterIndexer
	RangeBloomFilterNumElements uint64 `yaml:"rangeBloomFilterNumElements"`
	// RangeBloomFilterSize is the size (in bits) of rangeBloomfilter
	RangeBloomFilterSize uint64 `yaml:"rangeBloomFilterSize"`
	// RangeBloomFilterNumHash is the number of hash functions of rangeBloomfilter
	RangeBloomFilterNumHash uint64 `yaml:"rangeBloomFilterNumHash"`
}

Config is the config for indexer

type IndexBuilder

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

IndexBuilder defines the index builder

func NewIndexBuilder

func NewIndexBuilder(chainID uint32, g genesis.Genesis, dao blockdao.BlockStore, indexer Indexer) (*IndexBuilder, error)

NewIndexBuilder instantiates an index builder

func (*IndexBuilder) Indexer

func (ib *IndexBuilder) Indexer() Indexer

Indexer returns the indexer

func (*IndexBuilder) ReceiveBlock

func (ib *IndexBuilder) ReceiveBlock(blk *block.Block) error

ReceiveBlock handles the block and create the indices for the actions and receipts in it

func (*IndexBuilder) Start

func (ib *IndexBuilder) Start(ctx context.Context) error

Start starts the index builder

func (*IndexBuilder) Stop

func (ib *IndexBuilder) Stop(ctx context.Context) error

Stop stops the index builder

type Indexer

type Indexer interface {
	Start(context.Context) error
	Stop(context.Context) error
	PutBlock(context.Context, *block.Block) error
	PutBlocks(context.Context, []*block.Block) error
	DeleteTipBlock(context.Context, *block.Block) error
	Height() (uint64, error)
	GetBlockHash(height uint64) (hash.Hash256, error)
	GetBlockHeight(hash hash.Hash256) (uint64, error)
	GetBlockIndex(uint64) (*BlockIndex, error)
	GetActionIndex([]byte) (*ActionIndex, error)
	GetTotalActions() (uint64, error)
	GetActionHashFromIndex(uint64, uint64) ([][]byte, error)
	GetActionCountByAddress(hash.Hash160) (uint64, error)
	GetActionsByAddress(hash.Hash160, uint64, uint64) ([][]byte, error)
}

Indexer is the interface for block indexer

func NewIndexer

func NewIndexer(kv db.KVStore, genesisHash hash.Hash256) (Indexer, error)

NewIndexer creates a new indexer

type SyncIndexers

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

SyncIndexers is a special index that includes multiple indexes, which stay in sync when blocks are added.

func NewSyncIndexers

func NewSyncIndexers(indexers ...blockdao.BlockIndexer) *SyncIndexers

NewSyncIndexers creates a new SyncIndexers each indexer will PutBlock one by one in the order of the indexers

func (*SyncIndexers) DeleteTipBlock

func (ig *SyncIndexers) DeleteTipBlock(ctx context.Context, blk *block.Block) error

DeleteTipBlock deletes the tip block from the indexers in the group

func (*SyncIndexers) Height

func (ig *SyncIndexers) Height() (uint64, error)

Height returns the minimum height of the indexers in the group

func (*SyncIndexers) PutBlock

func (ig *SyncIndexers) PutBlock(ctx context.Context, blk *block.Block) error

PutBlock puts a block into the indexers in the group

func (*SyncIndexers) Start

func (ig *SyncIndexers) Start(ctx context.Context) error

Start starts the indexer group

func (*SyncIndexers) StartHeight

func (ig *SyncIndexers) StartHeight() uint64

StartHeight returns the minimum start height of the indexers in the group

func (*SyncIndexers) Stop

func (ig *SyncIndexers) Stop(ctx context.Context) error

Stop stops the indexer group

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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