jmt

package
v0.0.3-0...-aa4f25e Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: LGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorTimeout     = errors.New("wait too long when iterating trie")
	ErrorInterrupted = errors.New("interrupt iterating trie")
	ErrorNoMoreData  = errors.New("no more trie data")
)
View Source
var (
	ErrorBadProof    = errors.New("proof is invalid")    // proof content or struct is illegal
	ErrorInvalidPath = errors.New("invalid merkle path") // addressing merkle path error whe generate proof
	ErrorNodeMissing = errors.New("node is missing")     // miss node in merkle path
)
View Source
var (
	ErrorNotFound = errors.New("not found in DB")
)

Functions

func VerifyProof

func VerifyProof(rootHash common.Hash, proof *ProofResult) (bool, error)

VerifyProof support key existence proof

func VerifyTrie

func VerifyTrie(rootHash common.Hash, backend kv.Storage, cache PruneCache) (bool, error)

VerifyTrie verifies a whole trie

Types

type Iterator

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

Iterator traverse whole jmt trie

func NewIterator

func NewIterator(rootHash common.Hash, backend kv.Storage, cache PruneCache, bufSize int, timeout time.Duration) *Iterator

func (*Iterator) Iterate

func (it *Iterator) Iterate()

func (*Iterator) IterateLeaf

func (it *Iterator) IterateLeaf()

func (*Iterator) Next

func (it *Iterator) Next() (*RawNode, error)

func (*Iterator) Stop

func (it *Iterator) Stop()

type JMT

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

func New

func New(rootHash common.Hash, backend kv.Storage, trieCache TrieCache, pruneCache PruneCache, logger logrus.FieldLogger) (*JMT, error)

New load and init jmt from kv. Before New, there must be a mapping <rootHash, rootNodeKey> in kv.

func (*JMT) Commit

func (jmt *JMT) Commit(pruneArgs *PruneArgs) (rootHash common.Hash)

Commit flush dirty nodes in current tree, clear pruneCache, return root hash

func (*JMT) Get

func (jmt *JMT) Get(key []byte) ([]byte, error)

Get finds the value according to key in tree. If key isn't exist in tree, return nil with no error.

func (*JMT) PreloadTrieNodes

func (jmt *JMT) PreloadTrieNodes(nodeKeys [][]byte)

todo: batch preload

func (*JMT) Prove

func (jmt *JMT) Prove(key []byte) (*ProofResult, error)

func (*JMT) Root

func (jmt *JMT) Root() types.Node

func (*JMT) Update

func (jmt *JMT) Update(version uint64, key, value []byte) error

type ProofResult

type ProofResult struct {
	Key   []byte
	Value []byte
	Proof [][]byte // merkle path from top to bottom, the first element is root
}

func (*ProofResult) String

func (proof *ProofResult) String() string

just for debug

type PruneArgs

type PruneArgs struct {
	Enable  bool               // whether enable pruning or not
	Journal *types.TrieJournal // if Enable is true, jmt.Commit will set Journal
}

type PruneCache

type PruneCache interface {
	Get(version uint64, key []byte) (types.Node, bool)

	Enable() bool
}

type RawNode

type RawNode struct {
	RawKey    []byte // physical key of trie node in KV storage
	RawValue  []byte // physical value of trie node in KV storage
	LeafKey   []byte // non-empty iff current node is a leaf node, represents logical key of leaf
	LeafValue []byte // non-empty iff current node is a leaf node, represents logical value of leaf
}

func (*RawNode) String

func (n *RawNode) String() string

just for debug

type TrieCache

type TrieCache interface {
	Get(k []byte) ([]byte, bool)

	Has(k []byte) bool

	Enable() bool
}

Jump to

Keyboard shortcuts

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