util

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PruneStateStart     = "started"
	PruneStateUpdate    = "updating"
	PruneStateSynch     = "synching"
	PruneStateDelete    = "deleting"
	PruneStateCommplete = "completed"
	PruneStateAbandoned = "abandoned"
)
View Source
const (
	NodeTypeValueNode     = 1
	NodeTypeLeafNode      = 2
	NodeTypeFullNode      = 4
	NodeTypeExtensionNode = 8
	NodeTypesAll          = NodeTypeValueNode | NodeTypeLeafNode | NodeTypeFullNode | NodeTypeExtensionNode
)
View Source
const (
	// BatchSize - for batching multiple db operations.
	BatchSize = 256
	// FmtIntermediateNodeExists - error format indicating deleted intermediate
	// node still exists.
	FmtIntermediateNodeExists = "removed intermediate node still present" +
		" (%T) %v - new (%T) %v"
)

common constant

View Source
const (
	SSTTypeBlockBasedTable = 0
	SSTTypePlainTable      = 1
)
View Source
const (
	MPTMaxAllowableNodeSize = 1024 * 1024 // 1 MB
)

MPTMaxAllowableNodeSize - Maximum allowable size of MPT node

View Source
const Separator = ':'

Separator - used to separate fields when creating data array to hash

Variables

View Source
var (
	ErrIteratingChildNodes = errors.New("Error iterating child nodes")
	ErrMissingNodes        = errors.New("missing nodes")
)

ErrIteratingChildNodes - indicates an error iterting the child nodes

View Source
var (
	// ErrNodeNotFound - error indicating that the node is not found.
	ErrNodeNotFound = errors.New("node not found")
	// ErrValueNotPresent - error indicating given path is not present in the
	// db.
	ErrValueNotPresent = errors.New("value not present")
	// ErrNilPartialStateRoot is returned when partialState.ComputeRoot() gets nil root
	ErrNilPartialStateRoot = errors.New("partial state root is nil")
)

common errors

View Source
var DebugMPTNode = false

DebugMPTNode - for detailed debugging

View Source
var ErrInvalidEncoding = errors.New("invalid node encoding")

ErrInvalidEncoding - error to indicate invalid encoding

View Source
var (
	PNodeDBCompression = grocksdb.LZ4Compression
)
View Source
var PathElements = []byte("0123456789abcdef")

PathElements - all the bytes that can be used as path elements as ascii characters

Functions

func GetSerializationPrefix

func GetSerializationPrefix(node Node) byte

GetSerializationPrefix - get the serialization prefix

func Hash

func Hash(text string) string

Hash - the hashing used for the merkle tree construction

func HashStringToBytes

func HashStringToBytes(hash string) []byte

HashStringToBytes - convert a hex hash string to bytes

func IncludesNodeType

func IncludesNodeType(nodeTypes byte, nodeType byte) bool

IncludesNodeType - checks if the given node type is one of the node types in the mask

func IsMPTValid

func IsMPTValid(mpt MerklePatriciaTrieI) error

IsMPTValid - checks if the merkle tree is in valid state or not

func MHash

func MHash(h1 string, h2 string) string

MHash - merkle hashing of a pair of child hashes

func MergeState

func MergeState(ctx context.Context, fndb NodeDB, tndb NodeDB) error

MergeState - merge the state from another node db.

func PrintChanges

func PrintChanges(w io.Writer, changes []*NodeChange)

func ToHex

func ToHex(buf []byte) string

ToHex - converts a byte array to hex encoding

func ToUpperHex

func ToUpperHex(buf []byte) string

ToUpperHex - converts a byte array to hex encoding with upper case

func VerifyMerklePath

func VerifyMerklePath(hash string, path *MTPath, root string) bool

VerifyMerklePath - verify the given merkle path

func WithPruneStats

func WithPruneStats(ctx context.Context) context.Context

WithPruneStats - return a context with a prune stats object

Types

type ChangeCollector

type ChangeCollector struct {
	Changes map[string]*NodeChange
	Deletes map[string]Node
	// contains filtered or unexported fields
}

ChangeCollector - node change collector interface implementation

func (*ChangeCollector) AddChange

func (cc *ChangeCollector) AddChange(oldNode Node, newNode Node)

AddChange - implement interface

func (*ChangeCollector) Clone

func (cc *ChangeCollector) Clone() ChangeCollectorI

Clone returns a copy of the change collector

func (*ChangeCollector) DeleteChange

func (cc *ChangeCollector) DeleteChange(oldNode Node)

DeleteChange - implement interface

func (*ChangeCollector) GetChanges

func (cc *ChangeCollector) GetChanges() []*NodeChange

GetChanges - implement interface

func (*ChangeCollector) GetDeletes

func (cc *ChangeCollector) GetDeletes() []Node

GetDeletes - implement interface

func (*ChangeCollector) GetStartRoot

func (cc *ChangeCollector) GetStartRoot() Key

func (*ChangeCollector) UpdateChanges

func (cc *ChangeCollector) UpdateChanges(ndb NodeDB, origin Sequence, includeDeletes bool) error

UpdateChanges - update all the changes collected to a database

func (*ChangeCollector) Validate

func (cc *ChangeCollector) Validate() error

Validate - validate if this change collector is valid

type ChangeCollectorI

type ChangeCollectorI interface {
	AddChange(oldNode Node, newNode Node)
	DeleteChange(oldNode Node)
	GetChanges() []*NodeChange
	GetDeletes() []Node
	GetStartRoot() Key

	UpdateChanges(ndb NodeDB, origin Sequence, includeDeletes bool) error

	Validate() error
	Clone() ChangeCollectorI
}

ChangeCollectorI - an interface to collect node changes

func NewChangeCollector

func NewChangeCollector(startRoot Key) ChangeCollectorI

NewChangeCollector - a constructor to create a change collector

type ContextKey

type ContextKey string

ContextKey - a type for context key

const PruneStatsKey ContextKey = "prunestatskey"

PruneStatsKey - key used to get the prune stats object from the context

type ExtensionNode

type ExtensionNode struct {
	Path               Path `json:"p"`
	NodeKey            Key  `json:"k"`
	*OriginTrackerNode `json:"o,omitempty"`
}

ExtensionNode - a multi-char length path along which there are no branches, at the end of this path there should be full node

func NewExtensionNode

func NewExtensionNode(path Path, key Key) *ExtensionNode

NewExtensionNode - create a new extension node

func (*ExtensionNode) Clone

func (en *ExtensionNode) Clone() statecache.Value

func (*ExtensionNode) CloneNode added in v1.13.0

func (en *ExtensionNode) CloneNode() Node

Clone - implement interface

func (*ExtensionNode) CopyFrom added in v1.13.0

func (en *ExtensionNode) CopyFrom(v interface{}) bool

func (*ExtensionNode) Decode

func (en *ExtensionNode) Decode(buf []byte) error

Decode - implement interface

func (*ExtensionNode) Encode

func (en *ExtensionNode) Encode() []byte

Encode - implement interface

func (*ExtensionNode) GetHash

func (en *ExtensionNode) GetHash() string

GetHash - implements SecureSerializableValue interface

func (*ExtensionNode) GetHashBytes

func (en *ExtensionNode) GetHashBytes() []byte

GetHashBytes - implement interface

func (*ExtensionNode) GetNodeType

func (en *ExtensionNode) GetNodeType() byte

GetNodeType - implement interface

type FullNode

type FullNode struct {
	Children           [16][]byte `json:"c"`
	Value              *ValueNode `json:"v,omitempty"` // This may not be needed as our path is fixed in size
	*OriginTrackerNode `json:"o,omitempty"`
}

FullNode - a branch node that can contain 16 children and a value

func NewFullNode

func NewFullNode(value MPTSerializable) *FullNode

NewFullNode - create a new full node

func (*FullNode) Clone

func (fn *FullNode) Clone() statecache.Value

func (*FullNode) CloneNode added in v1.13.0

func (fn *FullNode) CloneNode() Node

Clone - implement interface

func (*FullNode) CopyFrom added in v1.13.0

func (fn *FullNode) CopyFrom(v interface{}) bool

func (*FullNode) Decode

func (fn *FullNode) Decode(buf []byte) error

Decode - implement interface

func (*FullNode) Encode

func (fn *FullNode) Encode() []byte

Encode - implement interface

func (*FullNode) GetChild

func (fn *FullNode) GetChild(hex byte) []byte

GetChild - get the child at the given hex index

func (*FullNode) GetHash

func (fn *FullNode) GetHash() string

GetHash - implements SecureSerializableValue interface

func (*FullNode) GetHashBytes

func (fn *FullNode) GetHashBytes() []byte

GetHashBytes - implement interface

func (*FullNode) GetNodeType

func (fn *FullNode) GetNodeType() byte

GetNodeType - implement interface

func (*FullNode) GetNumChildren

func (fn *FullNode) GetNumChildren() byte

GetNumChildren - get the number of children in this node

func (*FullNode) GetValue

func (fn *FullNode) GetValue() MPTSerializable

GetValue - implement interface

func (*FullNode) GetValueBytes

func (fn *FullNode) GetValueBytes() []byte

func (*FullNode) HasValue

func (fn *FullNode) HasValue() bool

HasValue - implement interface

func (*FullNode) PutChild

func (fn *FullNode) PutChild(hex byte, child []byte)

PutChild - put the child at the given hex index

func (*FullNode) SetValue

func (fn *FullNode) SetValue(value MPTSerializable)

SetValue - implement interface

type Hashable

type Hashable interface {
	GetHash() string
	GetHashBytes() []byte
}

Hashable - anything that can provide it's hash

type Key

type Key []byte

Key - a type for the merkle patricia trie node key

type LeafNode

type LeafNode struct {
	Path               Path       `json:"p,omitempty"`
	Prefix             Path       `json:"pp,omitempty"`
	Value              *ValueNode `json:"v"`
	*OriginTrackerNode `json:"o"`
}

LeafNode - a node that represents the leaf that contains a value and an optional path

func NewLeafNode

func NewLeafNode(prefix, path Path, origin Sequence, value MPTSerializable) *LeafNode

NewLeafNode - create a new leaf node

func (*LeafNode) Clone

func (ln *LeafNode) Clone() statecache.Value

func (*LeafNode) CloneNode added in v1.13.0

func (ln *LeafNode) CloneNode() Node

Clone - implement interface

func (*LeafNode) CopyFrom added in v1.13.0

func (ln *LeafNode) CopyFrom(v interface{}) bool

func (*LeafNode) Decode

func (ln *LeafNode) Decode(buf []byte) error

Decode - implement interface

func (*LeafNode) Encode

func (ln *LeafNode) Encode() []byte

Encode - implement interface

func (*LeafNode) GetHash

func (ln *LeafNode) GetHash() string

GetHash - implements SecureSerializableValue interface

func (*LeafNode) GetHashBytes

func (ln *LeafNode) GetHashBytes() []byte

GetHashBytes - implement interface

func (*LeafNode) GetNodeType

func (ln *LeafNode) GetNodeType() byte

GetNodeType - implement interface

func (*LeafNode) GetValue

func (ln *LeafNode) GetValue() MPTSerializable

GetValue - implement interface

func (*LeafNode) GetValueBytes

func (ln *LeafNode) GetValueBytes() []byte

func (*LeafNode) HasValue

func (ln *LeafNode) HasValue() bool

HasValue - implement interface

func (*LeafNode) SetValue

func (ln *LeafNode) SetValue(value MPTSerializable)

SetValue - implement interface

type LevelNodeDB

type LevelNodeDB struct {
	PropagateDeletes bool // Setting this to false (default) will not propagate delete to lower level db
	DeletedNodes     map[StrKey]bool
	// contains filtered or unexported fields
}

LevelNodeDB - a multi-level node db. It has a current node db and a previous node db. This is useful to update without changing the previous db.

func NewLevelNodeDB

func NewLevelNodeDB(curNDB NodeDB, prevNDB NodeDB, propagateDeletes bool) *LevelNodeDB

NewLevelNodeDB - create a level node db

func (*LevelNodeDB) DeleteNode

func (lndb *LevelNodeDB) DeleteNode(key Key) error

DeleteNode - implement interface

func (*LevelNodeDB) GetCurrent

func (lndb *LevelNodeDB) GetCurrent() NodeDB

GetCurrent returns current node db

func (*LevelNodeDB) GetDBVersion

func (lndb *LevelNodeDB) GetDBVersion() int64

GetDBVersion get the current level node db version

func (*LevelNodeDB) GetNode

func (lndb *LevelNodeDB) GetNode(key Key) (Node, error)

GetNode - implement interface

func (*LevelNodeDB) GetPrev

func (lndb *LevelNodeDB) GetPrev() NodeDB

GetPrev returns previous node db

func (*LevelNodeDB) Iterate

func (lndb *LevelNodeDB) Iterate(ctx context.Context, handler NodeDBIteratorHandler) error

Iterate - implement interface

func (*LevelNodeDB) MultiDeleteNode

func (lndb *LevelNodeDB) MultiDeleteNode(keys []Key) error

MultiDeleteNode - implement interface

func (*LevelNodeDB) MultiGetNode

func (lndb *LevelNodeDB) MultiGetNode(keys []Key) (nodes []Node, err error)

MultiGetNode - get multiple nodes

func (*LevelNodeDB) MultiPutNode

func (lndb *LevelNodeDB) MultiPutNode(keys []Key, nodes []Node) error

MultiPutNode - implement interface

func (*LevelNodeDB) PruneBelowVersion

func (lndb *LevelNodeDB) PruneBelowVersion(ctx context.Context, version int64) error

PruneBelowVersion - implement interface.

func (*LevelNodeDB) PutNode

func (lndb *LevelNodeDB) PutNode(key Key, node Node) error

PutNode - implement interface

func (*LevelNodeDB) RebaseCurrentDB

func (lndb *LevelNodeDB) RebaseCurrentDB(ndb NodeDB)

RebaseCurrentDB - set the current database.

func (*LevelNodeDB) RecordDeadNodes

func (lndb *LevelNodeDB) RecordDeadNodes([]Node, int64) error

func (*LevelNodeDB) SetPrev

func (lndb *LevelNodeDB) SetPrev(prevDB NodeDB)

SetPrev sets previous node db

func (*LevelNodeDB) Size

func (lndb *LevelNodeDB) Size(ctx context.Context) int64

Size - implement interface

type MPTIteratorHandler

type MPTIteratorHandler func(ctx context.Context, path Path, key Key, node Node) error

MPTIteratorHandler is a collection iteration handler function type

type MPTMissingNodeHandler

type MPTMissingNodeHandler func(ctx context.Context, path Path, key Key) error

MPTMissingNodeHandler - a handler for missing keys during iteration

type MPTSerializable

type MPTSerializable interface {
	msgp.Marshaler
	msgp.Unmarshaler
}

MPTSerializable represents the interface for encoding/decoding data that stores in MPT

type MPTSerializableSize

type MPTSerializableSize interface {
	MPTSerializable
	msgp.Sizer
}

MPTSerializableSize wraps the MPTSerializable and msgp.Sizer interfaces

type MTPath

type MTPath struct {
	Nodes     []string `json:"nodes"`
	LeafIndex int      `json:"leaf_index"`
}

MTPath - The merkle tree path

type MemoryNodeDB

type MemoryNodeDB struct {
	Nodes map[StrKey]Node
	// contains filtered or unexported fields
}

MemoryNodeDB - an inmemory node db.

func NewMemoryNodeDB

func NewMemoryNodeDB() *MemoryNodeDB

NewMemoryNodeDB - create a memory node db.

func (*MemoryNodeDB) ComputeRoot

func (mndb *MemoryNodeDB) ComputeRoot() (root Node, err error)

ComputeRoot - compute root from partial set of nodes in this db */

func (*MemoryNodeDB) DeleteNode

func (mndb *MemoryNodeDB) DeleteNode(key Key) error

DeleteNode - implement interface

func (*MemoryNodeDB) GetDBVersions

func (mndb *MemoryNodeDB) GetDBVersions() []int64

GetDBVersions, not implemented

func (*MemoryNodeDB) GetNode

func (mndb *MemoryNodeDB) GetNode(key Key) (Node, error)

GetNode - implement interface

func (*MemoryNodeDB) Iterate

func (mndb *MemoryNodeDB) Iterate(ctx context.Context, handler NodeDBIteratorHandler) error

Iterate - implement interface

func (*MemoryNodeDB) MultiDeleteNode

func (mndb *MemoryNodeDB) MultiDeleteNode(keys []Key) error

MultiDeleteNode - implement interface

func (*MemoryNodeDB) MultiGetNode

func (mndb *MemoryNodeDB) MultiGetNode(keys []Key) (nodes []Node, err error)

MultiGetNode - get multiple nodes

func (*MemoryNodeDB) MultiPutNode

func (mndb *MemoryNodeDB) MultiPutNode(keys []Key, nodes []Node) error

MultiPutNode - implement interface

func (*MemoryNodeDB) PruneBelowVersion

func (mndb *MemoryNodeDB) PruneBelowVersion(ctx context.Context, version int64) error

PruneBelowVersion - implement interface

func (*MemoryNodeDB) PutNode

func (mndb *MemoryNodeDB) PutNode(key Key, node Node) error

PutNode - implement interface

func (*MemoryNodeDB) Reachable

func (mndb *MemoryNodeDB) Reachable(from, to Node) (ok bool)

Reachable - checks if Node "to" reachable from Node "from" only using nodes stored on this db

func (*MemoryNodeDB) RecordDeadNodes

func (mndb *MemoryNodeDB) RecordDeadNodes([]Node, int64) error

func (*MemoryNodeDB) Size

func (mndb *MemoryNodeDB) Size(_ context.Context) int64

Size - implement interface

func (*MemoryNodeDB) Validate

func (mndb *MemoryNodeDB) Validate(root Node) error

Validate validates the nodes

type MerklePatriciaTrie

type MerklePatriciaTrie struct {
	ChangeCollector ChangeCollectorI
	Version         Sequence
	// contains filtered or unexported fields
}

MerklePatriciaTrie - it's a merkle tree and a patricia trie

func CloneMPT

CloneMPT - clone an existing MPT so it can go off of a different root

func NewMerklePatriciaTrie

func NewMerklePatriciaTrie(db NodeDB, version Sequence, root Key, cache *statecache.TransactionCache) *MerklePatriciaTrie

NewMerklePatriciaTrie - create a new patricia merkle trie

func (*MerklePatriciaTrie) Cache added in v1.13.0

func (*MerklePatriciaTrie) Delete

func (mpt *MerklePatriciaTrie) Delete(path Path) (Key, error)

Delete - delete a value from the trie

func (*MerklePatriciaTrie) GetAllMissingNodes added in v1.13.0

func (mpt *MerklePatriciaTrie) GetAllMissingNodes() ([]Key, error)

func (*MerklePatriciaTrie) GetChangeCount

func (mpt *MerklePatriciaTrie) GetChangeCount() int

GetChangeCount - implement interface

func (*MerklePatriciaTrie) GetChanges

func (mpt *MerklePatriciaTrie) GetChanges() (Key, []*NodeChange, []Node, Key)

GetChanges - implement interface

func (*MerklePatriciaTrie) GetDeletes

func (mpt *MerklePatriciaTrie) GetDeletes() []Node

func (*MerklePatriciaTrie) GetMissingNodeKeys added in v0.0.6

func (mpt *MerklePatriciaTrie) GetMissingNodeKeys() []Key

func (*MerklePatriciaTrie) GetNodeDB

func (mpt *MerklePatriciaTrie) GetNodeDB() NodeDB

GetNodeDB - implement interface

func (*MerklePatriciaTrie) GetNodeValue

func (mpt *MerklePatriciaTrie) GetNodeValue(path Path, v MPTSerializable) error

GetNodeValue - get the value for a given path

func (*MerklePatriciaTrie) GetNodeValueRaw

func (mpt *MerklePatriciaTrie) GetNodeValueRaw(path Path) ([]byte, error)

GetNodeValueRaw gets the raw data slice for a given path without decodding

func (*MerklePatriciaTrie) GetRoot

func (mpt *MerklePatriciaTrie) GetRoot() Key

GetRoot - implement interface

func (*MerklePatriciaTrie) GetVersion

func (mpt *MerklePatriciaTrie) GetVersion() Sequence

GetVersion - implement interface

func (*MerklePatriciaTrie) HasMissingNodes

func (mpt *MerklePatriciaTrie) HasMissingNodes(ctx context.Context) (bool, error)

HasMissingNodes returns immediately when a missing node is detected

func (*MerklePatriciaTrie) Insert

func (mpt *MerklePatriciaTrie) Insert(path Path, value MPTSerializable) (Key, error)

Insert - inserts (updates) a value into this trie and updates the trie all the way up and produces a new root

func (*MerklePatriciaTrie) Iterate

func (mpt *MerklePatriciaTrie) Iterate(ctx context.Context, handler MPTIteratorHandler, visitNodeTypes byte) error

Iterate - iterate the entire trie

func (*MerklePatriciaTrie) IterateFrom

func (mpt *MerklePatriciaTrie) IterateFrom(ctx context.Context, node Key, handler MPTIteratorHandler, visitNodeTypes byte) error

IterateFrom - iterate the trie from a given node

func (*MerklePatriciaTrie) MergeChanges

func (mpt *MerklePatriciaTrie) MergeChanges(newRoot Key, changes []*NodeChange, deletes []Node, startRoot Key) error

MergeChanges - implement interface.

func (*MerklePatriciaTrie) MergeDB

func (mpt *MerklePatriciaTrie) MergeDB(ndb NodeDB, root Key) error

MergeDB - merges the state changes from the node db directly

func (*MerklePatriciaTrie) MergeMPTChanges

func (mpt *MerklePatriciaTrie) MergeMPTChanges(mpt2 MerklePatriciaTrieI) error

MergeMPTChanges - implement interface.

func (*MerklePatriciaTrie) PrettyPrint

func (mpt *MerklePatriciaTrie) PrettyPrint(w io.Writer) error

PrettyPrint - print this trie

func (*MerklePatriciaTrie) SaveChanges

func (mpt *MerklePatriciaTrie) SaveChanges(ctx context.Context, ndb NodeDB, includeDeletes bool) error

SaveChanges - implement interface

func (*MerklePatriciaTrie) SetNodeDB

func (mpt *MerklePatriciaTrie) SetNodeDB(ndb NodeDB)

SetNodeDB - implement interface

func (*MerklePatriciaTrie) SetVersion

func (mpt *MerklePatriciaTrie) SetVersion(version Sequence)

SetVersion - implement interface

func (*MerklePatriciaTrie) Validate

func (mpt *MerklePatriciaTrie) Validate() error

Validate - implement interface - any sort of validations that can tell if the MPT is in a sane state

type MerklePatriciaTrieI

type MerklePatriciaTrieI interface {
	SetNodeDB(ndb NodeDB)
	GetNodeDB() NodeDB
	SetVersion(version Sequence)
	GetVersion() Sequence

	GetRoot() Key

	GetNodeValue(path Path, v MPTSerializable) error
	// GetNodeValueRaw returns the raw data slice on the given path
	GetNodeValueRaw(path Path) ([]byte, error)
	Insert(path Path, value MPTSerializable) (Key, error)
	Delete(path Path) (Key, error)

	Iterate(ctx context.Context, handler MPTIteratorHandler, visitNodeTypes byte) error

	IterateFrom(ctx context.Context, node Key, handler MPTIteratorHandler, visitNodeTypes byte) error

	// get root, changes and deletes
	GetChanges() (Key, []*NodeChange, []Node, Key)
	GetDeletes() []Node
	GetChangeCount() int
	SaveChanges(ctx context.Context, ndb NodeDB, includeDeletes bool) error

	HasMissingNodes(ctx context.Context) (bool, error)
	GetMissingNodeKeys() []Key
	// only for testing and debugging
	PrettyPrint(w io.Writer) error
	GetAllMissingNodes() ([]Key, error)

	Validate() error

	MergeMPTChanges(mpt2 MerklePatriciaTrieI) error
	MergeChanges(newRoot Key, changes []*NodeChange, deletes []Node, startRoot Key) error
	MergeDB(ndb NodeDB, root Key) error

	Cache() *statecache.TransactionCache
}

MerklePatriciaTrieI - interface of the merkle patricia trie

type MerkleTree

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

MerkleTree - A data structure that implements MerkleTreeI interface

func (*MerkleTree) ComputeTree

func (mt *MerkleTree) ComputeTree(hashes []Hashable)

ComputeTree - given the leaf nodes, compute the merkle tree

func (*MerkleTree) GetLeafIndex

func (mt *MerkleTree) GetLeafIndex(hash Hashable) int

GetLeafIndex - Get the index of the leaf node in the tree

func (*MerkleTree) GetPath

func (mt *MerkleTree) GetPath(hash Hashable) *MTPath

GetPath - get the path that can be used to verify the merkle tree

func (*MerkleTree) GetPathByIndex

func (mt *MerkleTree) GetPathByIndex(idx int) *MTPath

GetPathByIndex - get the path of a leaf node at index i

func (*MerkleTree) GetRoot

func (mt *MerkleTree) GetRoot() string

GetRoot - get the root of the merkle tree

func (*MerkleTree) GetTree

func (mt *MerkleTree) GetTree() []string

GetTree - get the entire merkle tree

func (*MerkleTree) SetTree

func (mt *MerkleTree) SetTree(leavesCount int, tree []string) error

SetTree - set the entire merkle tree

func (*MerkleTree) VerifyPath

func (mt *MerkleTree) VerifyPath(hash Hashable, path *MTPath) bool

VerifyPath - given a leaf node and the path, verify that the node is part of the tree

type MerkleTreeI

type MerkleTreeI interface {
	//API to create a tree from leaf nodes
	ComputeTree(hashes []Hashable)
	GetRoot() string
	GetTree() []string

	//API to load an existing tree
	SetTree(leavesCount int, tree []string) error

	// API for verification when the leaf node is known
	GetPath(hash Hashable) *MTPath               // Server needs to provide this
	VerifyPath(hash Hashable, path *MTPath) bool //This is only required by a client but useful for testing

	/* API for random verification when the leaf node is uknown
	(verification of the data to hash used as leaf node is outside this API) */
	GetPathByIndex(idx int) *MTPath
}

MerkleTreeI - a merkle tree interface required for constructing and providing verification

type Node

type Node interface {
	Serializable
	Hashable
	OriginTrackerI
	statecache.Value
	CloneNode() Node
	GetNodeType() byte
	GetOriginTracker() OriginTrackerI
	SetOriginTracker(ot OriginTrackerI)
}

Node - a node interface

func CreateNode

func CreateNode(r io.Reader) (Node, error)

CreateNode - create a node based on the serialization prefix

type NodeChange

type NodeChange struct {
	Old Node
	New Node
}

NodeChange - track a change to the node

type NodeDB

type NodeDB interface {
	GetNode(key Key) (Node, error)
	PutNode(key Key, node Node) error
	DeleteNode(key Key) error
	Iterate(ctx context.Context, handler NodeDBIteratorHandler) error
	Size(ctx context.Context) int64

	MultiGetNode(keys []Key) ([]Node, error)
	MultiPutNode(keys []Key, nodes []Node) error
	MultiDeleteNode(keys []Key) error

	RecordDeadNodes([]Node, int64) error
	PruneBelowVersion(ctx context.Context, version int64) error
}

NodeDB - an interface that gets, puts and deletes nodes by their key

type NodeDBIteratorHandler

type NodeDBIteratorHandler func(ctx context.Context, key Key, node Node) error

NodeDBIteratorHandler is a nodedb iteration handler function type

type OriginTracker

type OriginTracker struct {
	Origin  Sequence `json:"origin" msgpack:"o"`
	Version Sequence `json:"version" msgpack:"v"`
}

OriginTracker - implements the OriginTrackerI interface

func (*OriginTracker) GetOrigin

func (o *OriginTracker) GetOrigin() Sequence

GetOrigin - get the origin

func (*OriginTracker) GetVersion

func (o *OriginTracker) GetVersion() Sequence

GetVersion - implement interface

func (*OriginTracker) Read

func (o *OriginTracker) Read(r io.Reader) error

func (*OriginTracker) SetOrigin

func (o *OriginTracker) SetOrigin(origin Sequence)

SetOrigin - set the origin

func (*OriginTracker) SetVersion

func (o *OriginTracker) SetVersion(version Sequence)

SetVersion - implement interface

func (*OriginTracker) Write

func (o *OriginTracker) Write(w io.Writer) error

type OriginTrackerI

type OriginTrackerI interface {
	SetOrigin(origin Sequence)
	GetOrigin() Sequence

	SetVersion(version Sequence)
	GetVersion() Sequence

	Write(w io.Writer) error
	Read(r io.Reader) error
}

OriginTrackerI - tracks the origin * This is required to do pruning of nodes. When a new node is introduced in a given block generation round due to associated state changes, the node's origin and * version is the corresponding block's round. When we want to do pruning, we start with the state root of a given round's block, sweep through all nodes accessible * with that round and mark the version to that round number. Then, we iterate through the entire db and for any node that has the origin smaller than this value, * it can be safely deleted.

type OriginTrackerNode

type OriginTrackerNode struct {
	OriginTracker OriginTrackerI `json:"o,omitempty"`
}

OriginTrackerNode - a node that implements origin tracking

func NewOriginTrackerNode

func NewOriginTrackerNode() *OriginTrackerNode

NewOriginTrackerNode - create a new origin tracker node

func (*OriginTrackerNode) Clone

func (otn *OriginTrackerNode) Clone() *OriginTrackerNode

Clone - clone the given origin tracker node

func (*OriginTrackerNode) GetOrigin

func (otn *OriginTrackerNode) GetOrigin() Sequence

GetOrigin - implement interface

func (*OriginTrackerNode) GetOriginTracker

func (otn *OriginTrackerNode) GetOriginTracker() OriginTrackerI

GetOriginTracker - implement interface

func (*OriginTrackerNode) GetVersion

func (otn *OriginTrackerNode) GetVersion() Sequence

GetVersion - implement interface

func (*OriginTrackerNode) Read

func (otn *OriginTrackerNode) Read(r io.Reader) error

Read - implement interface

func (*OriginTrackerNode) SetOrigin

func (otn *OriginTrackerNode) SetOrigin(origin Sequence)

SetOrigin - implement interface

func (*OriginTrackerNode) SetOriginTracker

func (otn *OriginTrackerNode) SetOriginTracker(ot OriginTrackerI)

SetOriginTracker - implement interface

func (*OriginTrackerNode) SetVersion

func (otn *OriginTrackerNode) SetVersion(version Sequence)

SetVersion - implement interface

func (*OriginTrackerNode) Write

func (otn *OriginTrackerNode) Write(w io.Writer) error

Write - implement interface

type PNodeDB

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

PNodeDB - a node db that is persisted

func NewPNodeDB

func NewPNodeDB(stateDir, logDir string) (*PNodeDB, error)

NewPNodeDB - create a new PNodeDB

func (*PNodeDB) Close

func (pndb *PNodeDB) Close()

Close closes the rocksdb

func (*PNodeDB) DeleteNode

func (pndb *PNodeDB) DeleteNode(key Key) error

DeleteNode - implement interface

func (*PNodeDB) EstimateSize added in v1.13.0

func (pndb *PNodeDB) EstimateSize() (string, string)

func (*PNodeDB) Flush

func (pndb *PNodeDB) Flush()

Flush - flush the db

func (*PNodeDB) GetNode

func (pndb *PNodeDB) GetNode(key Key) (Node, error)

GetNode - implement interface

func (*PNodeDB) Iterate

func (pndb *PNodeDB) Iterate(ctx context.Context, handler NodeDBIteratorHandler) error

Iterate - implement interface

func (*PNodeDB) MultiDeleteNode

func (pndb *PNodeDB) MultiDeleteNode(keys []Key) error

MultiDeleteNode - implement interface

func (*PNodeDB) MultiGetNode

func (pndb *PNodeDB) MultiGetNode(keys []Key) ([]Node, error)

MultiGetNode - get multiple nodes

func (*PNodeDB) MultiPutNode

func (pndb *PNodeDB) MultiPutNode(keys []Key, nodes []Node) error

MultiPutNode - implement interface

func (*PNodeDB) PruneBelowVersion

func (pndb *PNodeDB) PruneBelowVersion(ctx context.Context, version int64) error

func (*PNodeDB) PutNode

func (pndb *PNodeDB) PutNode(key Key, node Node) error

PutNode - implement interface

func (*PNodeDB) RecordDeadNodes

func (pndb *PNodeDB) RecordDeadNodes(nodes []Node, version int64) error

RecordDeadNodes records dead nodes with version

func (*PNodeDB) Size

func (pndb *PNodeDB) Size(ctx context.Context) int64

Size - count number of keys in the db

type Path

type Path []byte

Path - a type for the path of the merkle patricia trie

type PruneStats

type PruneStats struct {
	Stage        string        `json:"stg"`
	Version      Sequence      `json:"v"`
	Total        int64         `json:"t"`
	Leaves       int64         `json:"l"`
	BelowVersion int64         `json:"bv"`
	Deleted      int64         `json:"d"`
	MissingNodes int64         `json:"mn"`
	UpdateTime   time.Duration `json:"ut"`
	DeleteTime   time.Duration `json:"dt"`
}

PruneStats - gathers statistics while pruning

func GetPruneStats

func GetPruneStats(ctx context.Context) *PruneStats

GetPruneStats - returns a prune stats object from the context

type SecureSerializableValue

type SecureSerializableValue struct {
	Buffer []byte
}

SecureSerializableValue - a proxy persisted value that just tracks the encoded bytes of a persisted value

func (*SecureSerializableValue) GetHash

func (spv *SecureSerializableValue) GetHash() string

GetHash - implement interface

func (*SecureSerializableValue) GetHashBytes

func (spv *SecureSerializableValue) GetHashBytes() []byte

GetHashBytes - implement interface

func (*SecureSerializableValue) MarshalMsg

func (spv *SecureSerializableValue) MarshalMsg([]byte) ([]byte, error)

MarshalMsg encodes node and implement msg.Marshaler interface

func (*SecureSerializableValue) UnmarshalMsg

func (spv *SecureSerializableValue) UnmarshalMsg(buf []byte) ([]byte, error)

UnmarshalMsg decodes node and implement msgp.Unmarshaler interface

type SecureSerializableValueI

type SecureSerializableValueI interface {
	MPTSerializable
	Hashable
}

SecureSerializableValueI an interface that makes a serializable value secure with hashing

type Sequence

type Sequence int64

Sequence - a data type that can be used to track the origin, latest version and sync version of a node

type Serializable

type Serializable interface {
	Encode() []byte
	Decode([]byte) error
}

Serializable interface

type StrKey

type StrKey string

StrKey - data type for the key used to store the node into some storage (this is needed as hashmap keys can't be []byte.

type ValueNode

type ValueNode struct {
	Value              MPTSerializable `json:"v"`
	*OriginTrackerNode `json:"o,omitempty"`
}

ValueNode - any node that holds a value should implement this

func GetValueNode

func GetValueNode(node Node) *ValueNode

GetValueNode - get the value node associated with this node

func NewValueNode

func NewValueNode() *ValueNode

NewValueNode - create a new value node

func (*ValueNode) Clone

func (vn *ValueNode) Clone() statecache.Value

func (*ValueNode) CloneNode added in v1.13.0

func (vn *ValueNode) CloneNode() Node

Clone - implement interface

func (*ValueNode) CopyFrom added in v1.13.0

func (vn *ValueNode) CopyFrom(v interface{}) bool

func (*ValueNode) Decode

func (vn *ValueNode) Decode(buf []byte) error

Decode - overwrite interface method

func (*ValueNode) Encode

func (vn *ValueNode) Encode() []byte

Encode - overwrite interface method

func (*ValueNode) GetHash

func (vn *ValueNode) GetHash() string

GetHash - implements SecureSerializableValue interface

func (*ValueNode) GetHashBytes

func (vn *ValueNode) GetHashBytes() []byte

GetHashBytes - implement SecureSerializableValue interface

func (*ValueNode) GetNodeType

func (vn *ValueNode) GetNodeType() byte

GetNodeType - implement interface

func (*ValueNode) GetValue

func (vn *ValueNode) GetValue() MPTSerializable

GetValue - get the value store in this node

func (*ValueNode) GetValueBytes

func (vn *ValueNode) GetValueBytes() []byte

GetValueBytes returns the value bytes store in this node

func (*ValueNode) SetValue

func (vn *ValueNode) SetValue(value MPTSerializable)

SetValue - set the value stored in this node

Jump to

Keyboard shortcuts

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