mpt

package
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package trie implements Merkle Patricia Tries.

Index

Constants

View Source
const MptData = "mpt-data"

Variables

View Source
var (
	// emptyRoot is the known root hash of an empty trie.
	EmptyRoot = HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
)

Functions

func DecodeNode

func DecodeNode(hash, buf []byte) (node, error)

DecodeNode parses the RLP encoding of a trie node.

func DecodeNodeLazy

func DecodeNodeLazy(hash, buf []byte) (node, error)

Types

type LeafCallback

type LeafCallback func(leaf []byte, parent Hash) error

LeafCallback is a callback type invoked when a trie operation reaches a leaf node. It's used by state sync and commit to allow handling external references between account and storage tries.

type MissingNodeError

type MissingNodeError struct {
	NodeHash common.Hash // hash of the missing node
	Path     []byte      // hex-encoded path to the missing node
}

MissingNodeError is returned by the trie functions (TryGet, Trgithub.com/yu-org/yupdate, TryDelete) in the case where a trie node is not present in the local database. It contains information necessary for retrieving the missing node.

func (*MissingNodeError) Error

func (err *MissingNodeError) Error() string

type NodeBase

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

func NewNodeBase

func NewNodeBase(db kv.Kvdb) *NodeBase

func (*NodeBase) Begin

func (db *NodeBase) Begin() (err error)

func (*NodeBase) Close

func (db *NodeBase) Close() error

func (*NodeBase) Commit

func (db *NodeBase) Commit() error

func (*NodeBase) Get

func (db *NodeBase) Get(toGet []byte) ([]byte, error)

func (*NodeBase) Insert

func (db *NodeBase) Insert(hash common.Hash, blob []byte) error

type Trie

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

Trie is a Merkle Patricia Trie. The zero value is an empty trie with no database. Use New to create a trie that sits on top of a database.

Trie is not safe for concurrent use.

func NewTrie

func NewTrie(root Hash, db *NodeBase) (*Trie, error)

NewTrie creates a trie with an existing root node from db.

If root is the zero hash or the sha3 hash of an empty string, the trie is initially empty and does not require a database. Otherwise, New will panic if db is nil and returns a MissingNodeError if root does not exist in the database. Accessing the trie loads nodes from db on demand.

func (*Trie) Commit

func (t *Trie) Commit(onleaf LeafCallback) (root Hash, err error)

Commit writes all nodes to the trie's memory database, tracking the internal and external (for account tries) references.

func (*Trie) Delete

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

Delete removes any existing value for key from the trie.

func (*Trie) Get

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

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

func (*Trie) Hash

func (t *Trie) Hash() Hash

Hash returns the root hash of the trie. It does not write to the database and can be used even if the trie doesn't have one.

func (*Trie) Prove

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

func (*Trie) TryDelete

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

TryDelete removes any existing value for key from the trie. If a node was not found in the database, a MissingNodeError is returned.

func (*Trie) TryGet

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

TryGet returns the value for key stored in the trie. The value bytes must not be modified by the caller. If a node was not found in the database, a MissingNodeError is returned.

func (*Trie) TryProve

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

func (*Trie) TryUpdate

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

TryUpdate 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.

If a node was not found in the database, a MissingNodeError is returned.

func (*Trie) Update

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

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 TrieFullNode

type TrieFullNode struct {
	Children [17]node // Actual trie node data to encode/decode (needs custom encoder)
	// contains filtered or unexported fields
}

func (*TrieFullNode) EncodeRLP

func (n *TrieFullNode) EncodeRLP(w io.Writer) error

EncodeRLP encodes a full node into the consensus RLP format.

func (*TrieFullNode) String

func (n *TrieFullNode) String() string

Pretty printing.

type TrieHashNode

type TrieHashNode []byte

func (TrieHashNode) String

func (n TrieHashNode) String() string

type TrieShortNode

type TrieShortNode struct {
	Key []byte
	Val node
	// contains filtered or unexported fields
}

func (*TrieShortNode) String

func (n *TrieShortNode) String() string

type TrieValueNode

type TrieValueNode []byte

func (TrieValueNode) String

func (n TrieValueNode) String() string

Jump to

Keyboard shortcuts

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