leveldb

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// LevelDB database path.
	Path string `default:"db"`

	// DefaultNextBlockNumber is the block number to write next block if database is empty.
	DefaultNextBlockNumber uint64
}

Config holds the configurations for LevelDB database.

func DefaultConfig

func DefaultConfig() (config Config)

type KeyPool

type KeyPool struct {
	sync.Pool
	// contains filtered or unexported fields
}

KeyPool is used to pool LevelDB database key for memory saving.

func NewKeyPool

func NewKeyPool(prefix string, size int) *KeyPool

NewKeyPool creats a new key pool with given prefix and key size.

func (*KeyPool) Get

func (pool *KeyPool) Get(key []byte) *[]byte

Get returns a pooled or new created database key with given key.

Note, the returned database key is of pointer type and requires to call Put method to return the database key to pool.

type Metrics

type Metrics struct{}

func (*Metrics) Latest

func (m *Metrics) Latest() metrics.Gauge

func (*Metrics) Write

func (m *Metrics) Write() metrics.Timer

type ShardingConfig

type ShardingConfig struct {
	Config `mapstructure:",squash"`

	ShardingBlocks uint64 // number of blocks in a shard
}

type ShardingMetadata

type ShardingMetadata struct {
	BlocksPerShard uint64
	EarlistShard   uint64 // inclusive, starts from 1, 0 indicates unavailable
	LatestShard    uint64 // inclusive, starts from 1, 0 indicates unavailable
}

func (*ShardingMetadata) Validate

func (metadata *ShardingMetadata) Validate(shardingBlocks uint64) error

type ShardingStore

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

ShardingStore stores blockchain data in a sharding manner based on block number range.

func NewShardingStore

func NewShardingStore(config ShardingConfig) (*ShardingStore, error)

NewShardingStore open or create a sharding store for the given path.

func (*ShardingStore) Close

func (store *ShardingStore) Close() error

Close closes the underlying LevelDB databases.

func (*ShardingStore) EarlistBlockNumber

func (store *ShardingStore) EarlistBlockNumber() (uint64, bool)

EarlistBlockNumber returns the earlist block number in database if any.

func (*ShardingStore) GetBlock

func (store *ShardingStore) GetBlock(bhon types.BlockHashOrNumber, isFull bool) (types.Lazy[*ethTypes.Block], error)

func (*ShardingStore) GetBlockNumber

func (store *ShardingStore) GetBlockNumber(bhon types.BlockHashOrNumber) (uint64, bool, error)

func (*ShardingStore) GetBlockReceipts

func (store *ShardingStore) GetBlockReceipts(bhon types.BlockHashOrNumber) (types.Lazy[[]ethTypes.Receipt], error)

func (*ShardingStore) GetBlockTraces

func (store *ShardingStore) GetBlockTraces(bhon types.BlockHashOrNumber) (types.Lazy[[]ethTypes.LocalizedTrace], error)

func (*ShardingStore) GetBlockTransactionCount

func (store *ShardingStore) GetBlockTransactionCount(bhon types.BlockHashOrNumber) (int64, error)

func (*ShardingStore) GetTrace

func (store *ShardingStore) GetTrace(txHash common.Hash, index uint) (*ethTypes.LocalizedTrace, error)

func (*ShardingStore) GetTransactionByHash

func (store *ShardingStore) GetTransactionByHash(txHash common.Hash) (*ethTypes.TransactionDetail, error)

func (*ShardingStore) GetTransactionByIndex

func (store *ShardingStore) GetTransactionByIndex(bhon types.BlockHashOrNumber, txIndex uint32) (*ethTypes.TransactionDetail, error)

func (*ShardingStore) GetTransactionReceipt

func (store *ShardingStore) GetTransactionReceipt(txHash common.Hash) (*ethTypes.Receipt, error)

func (*ShardingStore) GetTransactionTraces

func (store *ShardingStore) GetTransactionTraces(txHash common.Hash) ([]ethTypes.LocalizedTrace, error)

func (*ShardingStore) NextBlockNumber

func (store *ShardingStore) NextBlockNumber() uint64

NextBlockNumber returns the next block number to write in sequence.

func (*ShardingStore) Write

func (store *ShardingStore) Write(data ...evm.BlockData) error

Write writes the given block data in batch. It will return error if block data not written in sequence.

Note, this method is not thread safe!

type Store

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

Store provides operations on a LevelDB database.

func NewStore

func NewStore(config Config, options ...opt.Options) (*Store, error)

NewStore opens or creates a DB for the given path.

If corruption detected for an existing DB, it will try to recover the DB.

If the DB of specified path is empty and defaultNextBlockNumber specified, store will write data from defaultNextBlockNumber.

func (*Store) Close

func (store *Store) Close() error

Close closes the underlying LevelDB database.

func (*Store) EarlistBlockNumber

func (store *Store) EarlistBlockNumber() (uint64, bool)

EarlistBlockNumber returns the earlist block number in database if any.

func (*Store) GetBlock

func (store *Store) GetBlock(bhon types.BlockHashOrNumber, isFull bool) (types.Lazy[*ethTypes.Block], error)

GetBlock returns block for the given block hash or number. If not found, returns nil.

func (*Store) GetBlockNumber

func (store *Store) GetBlockNumber(bhon types.BlockHashOrNumber) (uint64, bool, error)

GetBlockNumber returns block number for the given block hash or number if any.

func (*Store) GetBlockReceipts

func (store *Store) GetBlockReceipts(bhon types.BlockHashOrNumber) (types.Lazy[[]ethTypes.Receipt], error)

GetBlockReceipts returns all block receipts for the given block hash or number. If not found, returns nil.

func (*Store) GetBlockTraces

func (store *Store) GetBlockTraces(bhon types.BlockHashOrNumber) (types.Lazy[[]ethTypes.LocalizedTrace], error)

GetBlockTraces returns all block traces for the given block hash or number. If not found, returns nil.

func (*Store) GetBlockTransactionCount

func (store *Store) GetBlockTransactionCount(bhon types.BlockHashOrNumber) (int64, error)

GetBlockTransactionCount returns the transaction count for the given block hash or number. Returns -1 if the given block hash not found.

func (*Store) GetTrace

func (store *Store) GetTrace(txHash common.Hash, index uint) (*ethTypes.LocalizedTrace, error)

GetTrace returns single trace for the given transaction hash at specified index. If not found, returns nil.

func (*Store) GetTransactionByHash

func (store *Store) GetTransactionByHash(txHash common.Hash) (*ethTypes.TransactionDetail, error)

GetTransactionByHash returns transaction for the given transaction hash. If not found, returns nil.

func (*Store) GetTransactionByIndex

func (store *Store) GetTransactionByIndex(bhon types.BlockHashOrNumber, txIndex uint32) (*ethTypes.TransactionDetail, error)

GetTransactionByIndex returns transaction for the given block hash or number along with transaction index. If not found, returns nil.

func (*Store) GetTransactionReceipt

func (store *Store) GetTransactionReceipt(txHash common.Hash) (*ethTypes.Receipt, error)

GetTransactionReceipt returns receipt for the given transaction hash. If not found, returns nil.

func (*Store) GetTransactionTraces

func (store *Store) GetTransactionTraces(txHash common.Hash) ([]ethTypes.LocalizedTrace, error)

GetTransactionTraces returns all transaction traces for the given transaction hash. If not found, returns nil.

func (*Store) NextBlockNumber

func (store *Store) NextBlockNumber() uint64

NextBlockNumber returns the next block number to write in sequence.

func (*Store) Write

func (store *Store) Write(data ...evm.BlockData) error

Write writes the given block data in batch. It will return error if block data not written in sequence.

Note, this method is not thread safe!

Jump to

Keyboard shortcuts

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