trie

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2022 License: Apache-2.0, GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagHashNode        = 0
	TagValueNode       = 1
	TagShortNode       = 2
	TagFullNode        = 17
	LenOfChildrenNodes = 17
)

Variables

This section is empty.

Functions

func CopyBytes

func CopyBytes(b []byte) (copiedBytes []byte)

func Deserialize

func Deserialize(hash []byte, r io.Reader, needFlags bool) (node, error)

func Sha256Key

func Sha256Key(bs []byte) []byte

Types

type Database

type Database interface {
	Get(key []byte) ([]byte, error)
	Has(key []byte) (bool, error)
	Delete(key []byte) error
	Compact() error
	NewBatch() error
	BatchPut(key, value []byte) error
	BatchDelete(key []byte) error
	BatchCommit() error
	NewIterator(prefix []byte) db.IIterator
}

type Iterator

type Iterator struct {
	Key   []byte
	Value []byte
	Err   error
	// contains filtered or unexported fields
}

func NewIterator

func NewIterator(it NodeIterator) *Iterator

func (*Iterator) Next

func (it *Iterator) Next() bool

type MemDatabase

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

func NewMemDatabase

func NewMemDatabase() *MemDatabase

func (*MemDatabase) BatchPut

func (db *MemDatabase) BatchPut(key []byte, value []byte) error

func (*MemDatabase) Delete

func (db *MemDatabase) Delete(key []byte) error

func (*MemDatabase) Get

func (db *MemDatabase) Get(key []byte) ([]byte, error)

func (*MemDatabase) Has

func (db *MemDatabase) Has(key []byte) (bool, error)

func (*MemDatabase) ViewDB

func (db *MemDatabase) ViewDB()

type NodeIterator

type NodeIterator interface {
	Next(bool) bool
	Error() error
	Hash() common.Uint256
	Parent() common.Uint256
	Path() []byte
	Leaf() bool
	LeafKey() []byte
	LeafBlob() []byte
}

type RefCounts

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

func NewRefCounts

func NewRefCounts(t *Trie, refCountTargetHeight, pruningTargetHeight uint32) (*RefCounts, error)

func (*RefCounts) ClearNeedReset

func (ref *RefCounts) ClearNeedReset() error

func (*RefCounts) Commit

func (ref *RefCounts) Commit() error

func (*RefCounts) Compact

func (ref *RefCounts) Compact() error

func (*RefCounts) CreateRefCounts

func (ref *RefCounts) CreateRefCounts(hash common.Uint256, inMemory, persistIntermediate bool) error

func (*RefCounts) LengthOfCounts

func (ref *RefCounts) LengthOfCounts() int

func (*RefCounts) NeedReset

func (ref *RefCounts) NeedReset() (bool, error)

func (*RefCounts) NewBatch

func (ref *RefCounts) NewBatch() error

func (*RefCounts) PersistNeedReset

func (ref *RefCounts) PersistNeedReset() error

func (*RefCounts) PersistPrunedHeights

func (ref *RefCounts) PersistPrunedHeights() error

func (*RefCounts) PersistRefCountHeights

func (ref *RefCounts) PersistRefCountHeights() error

func (*RefCounts) PersistRefCounts

func (ref *RefCounts) PersistRefCounts() error

func (*RefCounts) Prune

func (ref *RefCounts) Prune(hash common.Uint256, inMemory bool) error

func (*RefCounts) RebuildRefCount

func (ref *RefCounts) RebuildRefCount() error

func (*RefCounts) RemoveAllRefCount

func (ref *RefCounts) RemoveAllRefCount() error

func (*RefCounts) SequentialPrune

func (ref *RefCounts) SequentialPrune() error

func (*RefCounts) Verify

func (ref *RefCounts) Verify(hash common.Uint256) error

type Sync

type Sync struct {
	sync.RWMutex

	DataAvailable chan struct{} // Notify when new states arrived
	// contains filtered or unexported fields
}

Sync is the main state trie synchronisation scheduler, which provides yet unknown trie hashes to retrieve, accepts node data associated with said hashes and reconstructs the trie step by step until all is done.

func NewSync

func NewSync(root common.Uint256) *Sync

func (*Sync) AddSubTrie

func (s *Sync) AddSubTrie(root common.Uint256, path []byte)

AddSubTrie registers a new trie to the sync code, rooted at the designated parent.

func (*Sync) Commit

func (s *Sync) Commit(sdb db.IStore) error

Commit flushes the data stored in the internal membatch out to persistent storage, returning any occurred error.

func (*Sync) Pending

func (s *Sync) Pending() int

Pending returns the number of state entries currently pending for download.

func (*Sync) Pop

func (s *Sync) Pop(max int) ([]common.Uint256, []int64)

Pop return the specific number of hash jobs from heap

func (*Sync) Process

func (s *Sync) Process(result SyncResult) error

Process injects the received data for requested item.

func (*Sync) Push

func (s *Sync) Push(hashes []common.Uint256, prio int64)

type SyncPath

type SyncPath []byte

type SyncResult

type SyncResult struct {
	Hash common.Uint256 // Hash of the originally unknown trie node
	Data []byte         // Data content of the retrieved node
}

SyncResult is a response with requested data along with it's hash.

type Trie

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

func New

func New(hash common.Uint256, db Database) (*Trie, error)

func (*Trie) Commit

func (t *Trie) Commit() (common.Uint256, error)

func (*Trie) CommitTo

func (t *Trie) CommitTo(db Database) (common.Uint256, error)

func (*Trie) Copy

func (t *Trie) Copy() *Trie

func (*Trie) Delete

func (t *Trie) Delete(key []byte)

func (*Trie) Get

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

func (*Trie) Hash

func (t *Trie) Hash() common.Uint256

func (*Trie) NewRefCounts

func (t *Trie) NewRefCounts(targetRefCountHeight, targetPruningHeight uint32) (*RefCounts, error)

func (*Trie) NodeIterator

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

func (*Trie) Reset

func (t *Trie) Reset()

Reset drops the referenced root node and cleans all internal state.

func (*Trie) TryDelete

func (t *Trie) TryDelete(key []byte) error

func (*Trie) TryGet

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

func (*Trie) TryTraverse

func (t *Trie) TryTraverse(needPrint bool) error

func (*Trie) TryUpdate

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

func (*Trie) Update

func (t *Trie) Update(key, value []byte)

Jump to

Keyboard shortcuts

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