muxdb

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: LGPL-3.0 Imports: 15 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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HandleTrieLeafFunc

type HandleTrieLeafFunc func(key, blob1, blob2 []byte) error

HandleTrieLeafFunc callback function to handle trie leaf.

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) IsNotFound

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

IsNotFound returns if the error indicates key not found.

func (*MuxDB) LowStore

func (db *MuxDB) LowStore() kv.Store

LowStore returns underlying kv-store. It's for test purpose only.

func (*MuxDB) NewSecureTrie

func (db *MuxDB) NewSecureTrie(name string, root thor.Bytes32) *Trie

NewSecureTrie creates secure trie. In a secure trie, keys are hashed using blake2b. It prevents depth attack.

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 thor.Bytes32) *Trie

NewTrie creates trie either with existing root node.

If root is zero or blake2b hash of an empty string, the trie is initially empty.

func (*MuxDB) NewTriePruner

func (db *MuxDB) NewTriePruner() *TriePruner

NewTriePruner creates trie pruner.

type Options

type Options struct {
	// EncodedTrieNodeCacheSizeMB is the size of encoded trie node cache.
	EncodedTrieNodeCacheSizeMB int
	// DecodedTrieNodeCacheCapacity is max count of cached decoded trie nodes.
	DecodedTrieNodeCacheCapacity int
	// 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
	// PermanentTrie if set to true, tries always commit nodes into permanent space, so pruner
	// will have no effect.
	PermanentTrie bool
	// DisablePageCache Disable page cache for database file.
	// It's for test purpose only.
	DisablePageCache bool
}

Options optional parameters for MuxDB.

type Trie

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

Trie is the managed trie.

func (*Trie) Commit

func (t *Trie) Commit() (thor.Bytes32, error)

Commit writes all nodes to the trie's database.

func (*Trie) CommitPermanently

func (t *Trie) CommitPermanently() (thor.Bytes32, error)

CommitPermanently writes all nodes directly into permanent space. All nodes committed in this way can not be pruned. It's for test purpose only.

func (*Trie) Get

func (t *Trie) Get(key []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) GetKeyPreimage

func (t *Trie) GetKeyPreimage(hash thor.Bytes32) []byte

GetKeyPreimage returns the blake2b preimage of a hashed key that was previously used to store a value.

func (*Trie) Hash

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

Hash returns the root hash of the trie.

func (*Trie) Name

func (t *Trie) Name() string

Name returns trie name. Tries with different names have different key spaces.

func (*Trie) NodeIterator

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

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

func (*Trie) Update

func (t *Trie) Update(key, val []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.

type TriePruner

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

TriePruner is the trie pruner.

func (*TriePruner) ArchiveNodes

func (p *TriePruner) ArchiveNodes(
	ctx context.Context,
	name string,
	root1, root2 thor.Bytes32,
	handleLeaf HandleTrieLeafFunc,
) (nodeCount int, entryCount int, err error)

ArchiveNodes save differential nodes of two tries into permanent space. handleLeaf can be nil if not interested.

func (*TriePruner) DropStaleNodes

func (p *TriePruner) DropStaleNodes(ctx context.Context) (count int, err error)

DropStaleNodes delete stale trie nodes.

func (*TriePruner) SwitchLiveSpace

func (p *TriePruner) SwitchLiveSpace() error

SwitchLiveSpace switch trie live space.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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