muxdb

package
v2.2.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2025 License: LGPL-3.0 Imports: 22 Imported by: 1

Documentation

Overview

Package muxdb implements the storage layer for block-chain. It manages instance of merkle-patricia-trie, and general purpose named kv-store.

Package muxdb implements the storage layer for block-chain. It manages instance of merkle-patricia-trie, and general purpose named kv-store.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache added in v2.2.0

type Cache interface {
	AddNodeBlob(keyBuf *[]byte, name string, path []byte, ver trie.Version, blob []byte, isCommitting bool)
	GetNodeBlob(keyBuf *[]byte, name string, path []byte, ver trie.Version, peek bool) []byte
	AddRootNode(name string, n trie.Node)
	GetRootNode(name string, ver trie.Version) trie.Node
}

type MuxDB

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

MuxDB is the database to efficiently store state trie and block-chain data.

func NewMem

func NewMem() *MuxDB

NewMem creates a memory-backed DB.

func Open

func Open(path string, options *Options) (*MuxDB, error)

Open opens or creates DB at the given path.

func (*MuxDB) Close

func (db *MuxDB) Close() error

Close closes the DB.

func (*MuxDB) DeleteTrieHistoryNodes added in v2.2.0

func (db *MuxDB) DeleteTrieHistoryNodes(ctx context.Context, startMajorVer, limitMajorVer uint32) error

DeleteTrieHistoryNodes deletes trie history nodes within partitions of [startMajorVer, limitMajorVer).

func (*MuxDB) EnableMetrics added in v2.2.0

func (db *MuxDB) EnableMetrics()

func (*MuxDB) IsNotFound

func (db *MuxDB) IsNotFound(err error) bool

IsNotFound returns if the error indicates key not found.

func (*MuxDB) NewStore

func (db *MuxDB) NewStore(name string) kv.Store

NewStore creates named kv-store.

func (*MuxDB) NewTrie

func (db *MuxDB) NewTrie(name string, root trie.Root) *Trie

NewTrie creates trie with existing root node. If root is zero value, the trie is initially empty.

type Options

type Options struct {
	// TrieNodeCacheSizeMB is the size of the cache for trie node blobs.
	TrieNodeCacheSizeMB int
	// TrieCachedNodeTTL defines the life time(times of commit) of cached trie nodes.
	TrieCachedNodeTTL uint16
	// TrieHistPartitionFactor is the partition factor for historical trie nodes.
	TrieHistPartitionFactor uint32
	// TrieDedupedPartitionFactor is the partition factor for deduped trie nodes.
	TrieDedupedPartitionFactor uint32
	// TrieWillCleanHistory is the hint to tell if historical nodes will be cleaned.
	TrieWillCleanHistory bool

	// OpenFilesCacheCapacity is the capacity of open files caching for underlying database.
	OpenFilesCacheCapacity int
	// ReadCacheMB is the size of read cache for underlying database.
	ReadCacheMB int
	// WriteBufferMB is the size of write buffer for underlying database.
	WriteBufferMB int
}

Options optional parameters for MuxDB.

type Trie

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

Trie is the managed trie.

func (*Trie) Checkpoint added in v2.2.0

func (t *Trie) Checkpoint(ctx context.Context, baseMajorVer uint32, handleLeaf func(*trie.Leaf)) error

Checkpoint transfers standalone nodes, whose major version within [baseMajorVer, thisMajorVer], into deduped space.

func (*Trie) Commit added in v2.2.0

func (t *Trie) Commit(newVer trie.Version, skipHash bool) error

Commit writes all nodes to the trie's database.

Committing flushes nodes from memory. Subsequent Get calls will load nodes from the database. If skipHash is true, less disk space is taken up but crypto features of merkle trie lost.

func (*Trie) Copy added in v2.2.0

func (t *Trie) Copy() *Trie

Copy make a copy of this trie.

func (*Trie) Get added in v2.2.0

func (t *Trie) Get(key []byte) ([]byte, []byte, error)

Get returns the value for key stored in the trie. The value bytes must not be modified by the caller.

func (*Trie) Hash added in v2.2.0

func (t *Trie) Hash() thor.Bytes32

Hash returns the root hash of the trie.

func (*Trie) NodeIterator added in v2.2.0

func (t *Trie) NodeIterator(start []byte, baseMajorVer uint32) trie.NodeIterator

NodeIterator returns an iterator that returns nodes of the trie. Iteration starts at the key after the given start key

func (*Trie) SetNoFillCache added in v2.2.0

func (t *Trie) SetNoFillCache(b bool)

SetNoFillCache enable or disable cache filling.

func (*Trie) Update added in v2.2.0

func (t *Trie) Update(key, val, meta []byte) error

Update associates key with value in the trie. Subsequent calls to Get will return value. If value has length zero, any existing value is deleted from the trie and calls to Get will return nil.

The value bytes must not be modified by the caller while they are stored in the trie.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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