trie

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package trie implements a dense Merkle Patricia Trie. See the documentation on Trie for details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunOnTempTrie

func RunOnTempTrie(height uint, do func(*Trie) error) error

RunOnTempTrie creates an in-memory Trie of height `height` and runs `do` on that Trie

Types

type NewTrieFunc added in v0.2.1

type NewTrieFunc func(Storage, uint, *bitset.BitSet) (*Trie, error)

type Node

type Node struct {
	Value *felt.Felt
	Left  *bitset.BitSet
	Right *bitset.BitSet
}

A Node represents a node in the Trie

func (*Node) Hash

func (n *Node) Hash(path *bitset.BitSet, hashFunc hashFunc) *felt.Felt

Hash calculates the hash of a Node

type Storage

type Storage interface {
	Put(key *bitset.BitSet, value *Node) error
	Get(key *bitset.BitSet) (*Node, error)
	Delete(key *bitset.BitSet) error
}

Storage is the Persistent storage for the Trie

type TransactionStorage added in v0.3.0

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

TransactionStorage is a database transaction on a trie.

func NewTransactionStorage added in v0.3.0

func NewTransactionStorage(txn db.Transaction, prefix []byte) *TransactionStorage

func (*TransactionStorage) Delete added in v0.3.0

func (t *TransactionStorage) Delete(key *bitset.BitSet) error

func (*TransactionStorage) Get added in v0.3.0

func (t *TransactionStorage) Get(key *bitset.BitSet) (*Node, error)

func (*TransactionStorage) Put added in v0.3.0

func (t *TransactionStorage) Put(key *bitset.BitSet, value *Node) error

type Trie

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

Trie is a dense Merkle Patricia Trie (i.e., all internal nodes have two children).

This implementation allows for a "flat" storage by keying nodes on their path rather than their hash, resulting in O(1) accesses and O(log n) insertions.

The state trie specification describes a sparse Merkle Trie. Note that this dense implementation results in an equivalent commitment.

Terminology:

  • path: represents the path as defined in the specification. Together with len, represents a relative path from the current node to the node's nearest non-empty child.
  • len: represents the len as defined in the specification. The number of bits to take from the fixed-length path to reach the nearest non-empty child.
  • key: represents the storage key for trie [Node]s. It is the full path to the node from the root.

func NewTriePedersen added in v0.2.1

func NewTriePedersen(storage Storage, height uint, rootKey *bitset.BitSet) (*Trie, error)

func NewTriePoseidon added in v0.2.1

func NewTriePoseidon(storage Storage, height uint, rootKey *bitset.BitSet) (*Trie, error)

func (*Trie) Dump

func (t *Trie) Dump()

func (*Trie) Get

func (t *Trie) Get(key *felt.Felt) (*felt.Felt, error)

Get the corresponding `value` for a `key`

func (*Trie) Put

func (t *Trie) Put(key, value *felt.Felt) (*felt.Felt, error)

Put updates the corresponding `value` for a `key`

func (*Trie) Root

func (t *Trie) Root() (*felt.Felt, error)

Root returns the commitment of a Trie

func (*Trie) RootKey

func (t *Trie) RootKey() *bitset.BitSet

RootKey returns db key of the Trie root node

Jump to

Keyboard shortcuts

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