Documentation ¶
Index ¶
- Constants
- Variables
- func GetSerializationPrefix(node Node) byte
- func Hash(text string) string
- func HashStringToBytes(hash string) []byte
- func IncludesNodeType(nodeTypes byte, nodeType byte) bool
- func IsMPTValid(mpt MerklePatriciaTrieI) error
- func MHash(h1 string, h2 string) string
- func MergeState(ctx context.Context, fndb NodeDB, tndb NodeDB) error
- func PrintChanges(w io.Writer, changes []*NodeChange)
- func ToHex(buf []byte) string
- func ToUpperHex(buf []byte) string
- func VerifyMerklePath(hash string, path *MTPath, root string) bool
- func WithPruneStats(ctx context.Context) context.Context
- type ChangeCollector
- func (cc *ChangeCollector) AddChange(oldNode Node, newNode Node)
- func (cc *ChangeCollector) Clone() ChangeCollectorI
- func (cc *ChangeCollector) DeleteChange(oldNode Node)
- func (cc *ChangeCollector) GetChanges() []*NodeChange
- func (cc *ChangeCollector) GetDeletes() []Node
- func (cc *ChangeCollector) GetStartRoot() Key
- func (cc *ChangeCollector) UpdateChanges(ndb NodeDB, origin Sequence, includeDeletes bool) error
- func (cc *ChangeCollector) Validate() error
- type ChangeCollectorI
- type ContextKey
- type ExtensionNode
- func (en *ExtensionNode) Clone() statecache.Value
- func (en *ExtensionNode) CloneNode() Node
- func (en *ExtensionNode) CopyFrom(v interface{}) bool
- func (en *ExtensionNode) Decode(buf []byte) error
- func (en *ExtensionNode) Encode() []byte
- func (en *ExtensionNode) GetHash() string
- func (en *ExtensionNode) GetHashBytes() []byte
- func (en *ExtensionNode) GetNodeType() byte
- type FullNode
- func (fn *FullNode) Clone() statecache.Value
- func (fn *FullNode) CloneNode() Node
- func (fn *FullNode) CopyFrom(v interface{}) bool
- func (fn *FullNode) Decode(buf []byte) error
- func (fn *FullNode) Encode() []byte
- func (fn *FullNode) GetChild(hex byte) []byte
- func (fn *FullNode) GetHash() string
- func (fn *FullNode) GetHashBytes() []byte
- func (fn *FullNode) GetNodeType() byte
- func (fn *FullNode) GetNumChildren() byte
- func (fn *FullNode) GetValue() MPTSerializable
- func (fn *FullNode) GetValueBytes() []byte
- func (fn *FullNode) HasValue() bool
- func (fn *FullNode) PutChild(hex byte, child []byte)
- func (fn *FullNode) SetValue(value MPTSerializable)
- type Hashable
- type Key
- type LeafNode
- func (ln *LeafNode) Clone() statecache.Value
- func (ln *LeafNode) CloneNode() Node
- func (ln *LeafNode) CopyFrom(v interface{}) bool
- func (ln *LeafNode) Decode(buf []byte) error
- func (ln *LeafNode) Encode() []byte
- func (ln *LeafNode) GetHash() string
- func (ln *LeafNode) GetHashBytes() []byte
- func (ln *LeafNode) GetNodeType() byte
- func (ln *LeafNode) GetValue() MPTSerializable
- func (ln *LeafNode) GetValueBytes() []byte
- func (ln *LeafNode) HasValue() bool
- func (ln *LeafNode) SetValue(value MPTSerializable)
- type LevelNodeDB
- func (lndb *LevelNodeDB) DeleteNode(key Key) error
- func (lndb *LevelNodeDB) GetCurrent() NodeDB
- func (lndb *LevelNodeDB) GetDBVersion() int64
- func (lndb *LevelNodeDB) GetNode(key Key) (Node, error)
- func (lndb *LevelNodeDB) GetPrev() NodeDB
- func (lndb *LevelNodeDB) Iterate(ctx context.Context, handler NodeDBIteratorHandler) error
- func (lndb *LevelNodeDB) MultiDeleteNode(keys []Key) error
- func (lndb *LevelNodeDB) MultiGetNode(keys []Key) (nodes []Node, err error)
- func (lndb *LevelNodeDB) MultiPutNode(keys []Key, nodes []Node) error
- func (lndb *LevelNodeDB) PruneBelowVersion(ctx context.Context, version int64) error
- func (lndb *LevelNodeDB) PutNode(key Key, node Node) error
- func (lndb *LevelNodeDB) RebaseCurrentDB(ndb NodeDB)
- func (lndb *LevelNodeDB) RecordDeadNodes([]Node, int64) error
- func (lndb *LevelNodeDB) SetPrev(prevDB NodeDB)
- func (lndb *LevelNodeDB) Size(ctx context.Context) int64
- type MPTIteratorHandler
- type MPTMissingNodeHandler
- type MPTSerializable
- type MPTSerializableSize
- type MTPath
- type MemoryNodeDB
- func (mndb *MemoryNodeDB) ComputeRoot() (root Node, err error)
- func (mndb *MemoryNodeDB) DeleteNode(key Key) error
- func (mndb *MemoryNodeDB) GetDBVersions() []int64
- func (mndb *MemoryNodeDB) GetNode(key Key) (Node, error)
- func (mndb *MemoryNodeDB) Iterate(ctx context.Context, handler NodeDBIteratorHandler) error
- func (mndb *MemoryNodeDB) MultiDeleteNode(keys []Key) error
- func (mndb *MemoryNodeDB) MultiGetNode(keys []Key) (nodes []Node, err error)
- func (mndb *MemoryNodeDB) MultiPutNode(keys []Key, nodes []Node) error
- func (mndb *MemoryNodeDB) PruneBelowVersion(ctx context.Context, version int64) error
- func (mndb *MemoryNodeDB) PutNode(key Key, node Node) error
- func (mndb *MemoryNodeDB) Reachable(from, to Node) (ok bool)
- func (mndb *MemoryNodeDB) RecordDeadNodes([]Node, int64) error
- func (mndb *MemoryNodeDB) Size(_ context.Context) int64
- func (mndb *MemoryNodeDB) Validate(root Node) error
- type MerklePatriciaTrie
- func (mpt *MerklePatriciaTrie) Cache() *statecache.TransactionCache
- func (mpt *MerklePatriciaTrie) Delete(path Path) (Key, error)
- func (mpt *MerklePatriciaTrie) GetAllMissingNodes() ([]Key, error)
- func (mpt *MerklePatriciaTrie) GetChangeCount() int
- func (mpt *MerklePatriciaTrie) GetChanges() (Key, []*NodeChange, []Node, Key)
- func (mpt *MerklePatriciaTrie) GetDeletes() []Node
- func (mpt *MerklePatriciaTrie) GetMissingNodeKeys() []Key
- func (mpt *MerklePatriciaTrie) GetNodeDB() NodeDB
- func (mpt *MerklePatriciaTrie) GetNodeValue(path Path, v MPTSerializable) error
- func (mpt *MerklePatriciaTrie) GetNodeValueRaw(path Path) ([]byte, error)
- func (mpt *MerklePatriciaTrie) GetRoot() Key
- func (mpt *MerklePatriciaTrie) GetVersion() Sequence
- func (mpt *MerklePatriciaTrie) HasMissingNodes(ctx context.Context) (bool, error)
- func (mpt *MerklePatriciaTrie) Insert(path Path, value MPTSerializable) (Key, error)
- func (mpt *MerklePatriciaTrie) Iterate(ctx context.Context, handler MPTIteratorHandler, visitNodeTypes byte) error
- func (mpt *MerklePatriciaTrie) IterateFrom(ctx context.Context, node Key, handler MPTIteratorHandler, visitNodeTypes byte) error
- func (mpt *MerklePatriciaTrie) MergeChanges(newRoot Key, changes []*NodeChange, deletes []Node, startRoot Key) error
- func (mpt *MerklePatriciaTrie) MergeDB(ndb NodeDB, root Key) error
- func (mpt *MerklePatriciaTrie) MergeMPTChanges(mpt2 MerklePatriciaTrieI) error
- func (mpt *MerklePatriciaTrie) PrettyPrint(w io.Writer) error
- func (mpt *MerklePatriciaTrie) SaveChanges(ctx context.Context, ndb NodeDB, includeDeletes bool) error
- func (mpt *MerklePatriciaTrie) SetNodeDB(ndb NodeDB)
- func (mpt *MerklePatriciaTrie) SetVersion(version Sequence)
- func (mpt *MerklePatriciaTrie) Validate() error
- type MerklePatriciaTrieI
- type MerkleTree
- func (mt *MerkleTree) ComputeTree(hashes []Hashable)
- func (mt *MerkleTree) GetLeafIndex(hash Hashable) int
- func (mt *MerkleTree) GetPath(hash Hashable) *MTPath
- func (mt *MerkleTree) GetPathByIndex(idx int) *MTPath
- func (mt *MerkleTree) GetRoot() string
- func (mt *MerkleTree) GetTree() []string
- func (mt *MerkleTree) SetTree(leavesCount int, tree []string) error
- func (mt *MerkleTree) VerifyPath(hash Hashable, path *MTPath) bool
- type MerkleTreeI
- type Node
- type NodeChange
- type NodeDB
- type NodeDBIteratorHandler
- type OriginTracker
- type OriginTrackerI
- type OriginTrackerNode
- func (otn *OriginTrackerNode) Clone() *OriginTrackerNode
- func (otn *OriginTrackerNode) GetOrigin() Sequence
- func (otn *OriginTrackerNode) GetOriginTracker() OriginTrackerI
- func (otn *OriginTrackerNode) GetVersion() Sequence
- func (otn *OriginTrackerNode) Read(r io.Reader) error
- func (otn *OriginTrackerNode) SetOrigin(origin Sequence)
- func (otn *OriginTrackerNode) SetOriginTracker(ot OriginTrackerI)
- func (otn *OriginTrackerNode) SetVersion(version Sequence)
- func (otn *OriginTrackerNode) Write(w io.Writer) error
- type PNodeDB
- func (pndb *PNodeDB) Close()
- func (pndb *PNodeDB) DeleteNode(key Key) error
- func (pndb *PNodeDB) EstimateSize() (string, string)
- func (pndb *PNodeDB) Flush()
- func (pndb *PNodeDB) GetNode(key Key) (Node, error)
- func (pndb *PNodeDB) Iterate(ctx context.Context, handler NodeDBIteratorHandler) error
- func (pndb *PNodeDB) MultiDeleteNode(keys []Key) error
- func (pndb *PNodeDB) MultiGetNode(keys []Key) ([]Node, error)
- func (pndb *PNodeDB) MultiPutNode(keys []Key, nodes []Node) error
- func (pndb *PNodeDB) PruneBelowVersion(ctx context.Context, version int64) error
- func (pndb *PNodeDB) PutNode(key Key, node Node) error
- func (pndb *PNodeDB) RecordDeadNodes(nodes []Node, version int64) error
- func (pndb *PNodeDB) Size(ctx context.Context) int64
- type Path
- type PruneStats
- type SecureSerializableValue
- type SecureSerializableValueI
- type Sequence
- type Serializable
- type StrKey
- type ValueNode
- func (vn *ValueNode) Clone() statecache.Value
- func (vn *ValueNode) CloneNode() Node
- func (vn *ValueNode) CopyFrom(v interface{}) bool
- func (vn *ValueNode) Decode(buf []byte) error
- func (vn *ValueNode) Encode() []byte
- func (vn *ValueNode) GetHash() string
- func (vn *ValueNode) GetHashBytes() []byte
- func (vn *ValueNode) GetNodeType() byte
- func (vn *ValueNode) GetValue() MPTSerializable
- func (vn *ValueNode) GetValueBytes() []byte
- func (vn *ValueNode) SetValue(value MPTSerializable)
Constants ¶
const ( PruneStateStart = "started" PruneStateUpdate = "updating" PruneStateSynch = "synching" PruneStateDelete = "deleting" PruneStateCommplete = "completed" PruneStateAbandoned = "abandoned" )
const ( NodeTypeValueNode = 1 NodeTypeLeafNode = 2 NodeTypeFullNode = 4 NodeTypeExtensionNode = 8 NodeTypesAll = NodeTypeValueNode | NodeTypeLeafNode | NodeTypeFullNode | NodeTypeExtensionNode )
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
const ( SSTTypeBlockBasedTable = 0 SSTTypePlainTable = 1 )
const (
MPTMaxAllowableNodeSize = 1024 * 1024 // 1 MB
)
MPTMaxAllowableNodeSize - Maximum allowable size of MPT node
const Separator = ':'
Separator - used to separate fields when creating data array to hash
Variables ¶
var ( ErrIteratingChildNodes = errors.New("Error iterating child nodes") ErrMissingNodes = errors.New("missing nodes") )
ErrIteratingChildNodes - indicates an error iterting the child nodes
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
var DebugMPTNode = false
DebugMPTNode - for detailed debugging
var ErrInvalidEncoding = errors.New("invalid node encoding")
ErrInvalidEncoding - error to indicate invalid encoding
var (
PNodeDBCompression = grocksdb.LZ4Compression
)
var PathElements = []byte("0123456789abcdef")
PathElements - all the bytes that can be used as path elements as ascii characters
Functions ¶
func GetSerializationPrefix ¶
GetSerializationPrefix - get the serialization prefix
func HashStringToBytes ¶
HashStringToBytes - convert a hex hash string to bytes
func IncludesNodeType ¶
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 MergeState ¶
MergeState - merge the state from another node db.
func PrintChanges ¶
func PrintChanges(w io.Writer, changes []*NodeChange)
func ToUpperHex ¶
ToUpperHex - converts a byte array to hex encoding with upper case
func VerifyMerklePath ¶
VerifyMerklePath - verify the given merkle path
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) GetHashBytes ¶
GetHashBytes - implement interface
func (*FullNode) GetNodeType ¶
GetNodeType - implement interface
func (*FullNode) GetNumChildren ¶
GetNumChildren - get the number of children in this node
func (*FullNode) GetValue ¶
func (fn *FullNode) GetValue() MPTSerializable
GetValue - implement interface
func (*FullNode) GetValueBytes ¶
func (*FullNode) SetValue ¶
func (fn *FullNode) SetValue(value MPTSerializable)
SetValue - implement interface
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) GetHashBytes ¶
GetHashBytes - implement interface
func (*LeafNode) GetNodeType ¶
GetNodeType - implement interface
func (*LeafNode) GetValue ¶
func (ln *LeafNode) GetValue() MPTSerializable
GetValue - implement interface
func (*LeafNode) GetValueBytes ¶
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
type MPTIteratorHandler ¶
MPTIteratorHandler is a collection iteration handler function type
type MPTMissingNodeHandler ¶
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 MemoryNodeDB ¶
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 ¶
func CloneMPT(mpt MerklePatriciaTrieI) *MerklePatriciaTrie
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 (mpt *MerklePatriciaTrie) Cache() *statecache.TransactionCache
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
type NodeChange ¶
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 ¶
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) SetOrigin ¶
func (o *OriginTracker) SetOrigin(origin Sequence)
SetOrigin - set the origin
func (*OriginTracker) SetVersion ¶
func (o *OriginTracker) SetVersion(version Sequence)
SetVersion - implement interface
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
type PNodeDB ¶
type PNodeDB struct {
// contains filtered or unexported fields
}
PNodeDB - a node db that is persisted
func NewPNodeDB ¶
NewPNodeDB - create a new PNodeDB
func (*PNodeDB) DeleteNode ¶
DeleteNode - implement interface
func (*PNodeDB) EstimateSize ¶ added in v1.13.0
func (*PNodeDB) Iterate ¶
func (pndb *PNodeDB) Iterate(ctx context.Context, handler NodeDBIteratorHandler) error
Iterate - implement interface
func (*PNodeDB) MultiDeleteNode ¶
MultiDeleteNode - implement interface
func (*PNodeDB) MultiGetNode ¶
MultiGetNode - get multiple nodes
func (*PNodeDB) MultiPutNode ¶
MultiPutNode - implement interface
func (*PNodeDB) PruneBelowVersion ¶
func (*PNodeDB) RecordDeadNodes ¶
RecordDeadNodes records dead nodes with version
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 ¶
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 ¶
GetValueNode - get the value node associated with this node
func (*ValueNode) Clone ¶
func (vn *ValueNode) Clone() statecache.Value
func (*ValueNode) GetHashBytes ¶
GetHashBytes - implement SecureSerializableValue interface
func (*ValueNode) GetNodeType ¶
GetNodeType - implement interface
func (*ValueNode) GetValue ¶
func (vn *ValueNode) GetValue() MPTSerializable
GetValue - get the value store in this node
func (*ValueNode) GetValueBytes ¶
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