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 ¶
- type HandleTrieLeafFunc
- type MuxDB
- func (db *MuxDB) Close() error
- func (db *MuxDB) IsNotFound(err error) bool
- func (db *MuxDB) LowStore() kv.Store
- func (db *MuxDB) NewSecureTrie(name string, root thor.Bytes32) *Trie
- func (db *MuxDB) NewStore(name string) kv.Store
- func (db *MuxDB) NewTrie(name string, root thor.Bytes32) *Trie
- func (db *MuxDB) NewTriePruner() *TriePruner
- type Options
- type Trie
- func (t *Trie) Commit() (thor.Bytes32, error)
- func (t *Trie) CommitPermanently() (thor.Bytes32, error)
- func (t *Trie) Get(key []byte) ([]byte, error)
- func (t *Trie) GetKeyPreimage(hash thor.Bytes32) []byte
- func (t *Trie) Hash() thor.Bytes32
- func (t *Trie) Name() string
- func (t *Trie) NodeIterator(start []byte) trie.NodeIterator
- func (t *Trie) Update(key, val []byte) error
- type TriePruner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HandleTrieLeafFunc ¶
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 (*MuxDB) IsNotFound ¶
IsNotFound returns if the error indicates key not found.
func (*MuxDB) NewSecureTrie ¶
NewSecureTrie creates secure trie. In a secure trie, keys are hashed using blake2b. It prevents depth attack.
func (*MuxDB) NewTrie ¶
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) CommitPermanently ¶
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 ¶
Get returns the value for key stored in the trie. The value bytes must not be modified by the caller.
func (*Trie) GetKeyPreimage ¶
GetKeyPreimage returns the blake2b preimage of a hashed key that was previously used to store a value.
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 ¶
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.