mptrie

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Copyright IBM Corp. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

Copyright IBM Corp. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BranchNode

type BranchNode struct {
	Children             [][]byte `protobuf:"bytes,1,rep,name=children,proto3" json:"children,omitempty"`
	ValuePtr             []byte   `protobuf:"bytes,2,opt,name=valuePtr,proto3" json:"valuePtr,omitempty"`
	Deleted              bool     `protobuf:"varint,3,opt,name=deleted,proto3" json:"deleted,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*BranchNode) Descriptor

func (*BranchNode) Descriptor() ([]byte, []int)

func (*BranchNode) GetChildren

func (m *BranchNode) GetChildren() [][]byte

func (*BranchNode) GetDeleted

func (m *BranchNode) GetDeleted() bool

func (*BranchNode) GetValuePtr

func (m *BranchNode) GetValuePtr() []byte

func (*BranchNode) ProtoMessage

func (*BranchNode) ProtoMessage()

func (*BranchNode) Reset

func (m *BranchNode) Reset()

func (*BranchNode) String

func (m *BranchNode) String() string

func (*BranchNode) XXX_DiscardUnknown

func (m *BranchNode) XXX_DiscardUnknown()

func (*BranchNode) XXX_Marshal

func (m *BranchNode) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*BranchNode) XXX_Merge

func (m *BranchNode) XXX_Merge(src proto.Message)

func (*BranchNode) XXX_Size

func (m *BranchNode) XXX_Size() int

func (*BranchNode) XXX_Unmarshal

func (m *BranchNode) XXX_Unmarshal(b []byte) error

type EmptyNode

type EmptyNode struct {
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*EmptyNode) Descriptor

func (*EmptyNode) Descriptor() ([]byte, []int)

func (*EmptyNode) ProtoMessage

func (*EmptyNode) ProtoMessage()

func (*EmptyNode) Reset

func (m *EmptyNode) Reset()

func (*EmptyNode) String

func (m *EmptyNode) String() string

func (*EmptyNode) XXX_DiscardUnknown

func (m *EmptyNode) XXX_DiscardUnknown()

func (*EmptyNode) XXX_Marshal

func (m *EmptyNode) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*EmptyNode) XXX_Merge

func (m *EmptyNode) XXX_Merge(src proto.Message)

func (*EmptyNode) XXX_Size

func (m *EmptyNode) XXX_Size() int

func (*EmptyNode) XXX_Unmarshal

func (m *EmptyNode) XXX_Unmarshal(b []byte) error

type ExtensionNode

type ExtensionNode struct {
	Key                  []byte   `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	Child                []byte   `protobuf:"bytes,2,opt,name=child,proto3" json:"child,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*ExtensionNode) Descriptor

func (*ExtensionNode) Descriptor() ([]byte, []int)

func (*ExtensionNode) GetChild

func (m *ExtensionNode) GetChild() []byte

func (*ExtensionNode) GetKey

func (m *ExtensionNode) GetKey() []byte

func (*ExtensionNode) ProtoMessage

func (*ExtensionNode) ProtoMessage()

func (*ExtensionNode) Reset

func (m *ExtensionNode) Reset()

func (*ExtensionNode) String

func (m *ExtensionNode) String() string

func (*ExtensionNode) XXX_DiscardUnknown

func (m *ExtensionNode) XXX_DiscardUnknown()

func (*ExtensionNode) XXX_Marshal

func (m *ExtensionNode) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*ExtensionNode) XXX_Merge

func (m *ExtensionNode) XXX_Merge(src proto.Message)

func (*ExtensionNode) XXX_Size

func (m *ExtensionNode) XXX_Size() int

func (*ExtensionNode) XXX_Unmarshal

func (m *ExtensionNode) XXX_Unmarshal(b []byte) error

type MPTrie

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

Merkle-Patricia Trie implementation. No node/value data stored inside trie, but in associated TrieStore

func NewTrie

func NewTrie(rootHash []byte, store Store) (*MPTrie, error)

NewTrie creates new Merkle-Patricia Trie, with backend store. If root node Hash is not nil, root node loaded from store, otherwise, empty trie is created

func (*MPTrie) Commit

func (t *MPTrie) Commit(blockNum uint64) error

func (*MPTrie) Delete

func (t *MPTrie) Delete(key []byte) ([]byte, error)

func (*MPTrie) Get

func (t *MPTrie) Get(key []byte) ([]byte, error)

func (*MPTrie) GetProof

func (t *MPTrie) GetProof(key []byte, isDeleted bool) (*state.Proof, error)

GetProof calculates proof (path) from node contains value to root node in trie for given key and delete flag, i.e. if value was deleted, but delete flag id false, no proof will be calculated

func (*MPTrie) Hash

func (t *MPTrie) Hash() ([]byte, error)

func (*MPTrie) Update

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

type Store

type Store interface {
	// GetNode returns TrieNode associated with key/ptr. It may be temporal node
	// created by PutNode, node market to persist after PersistNode or after executing
	// CommitPersistChanges actually stored in backend storage node
	GetNode(nodePtr []byte) (TrieNode, error)
	// GetValue return value bytes associated with value ptr. Same logic as in GetNode applies.
	GetValue(valuePtr []byte) ([]byte, error)
	// PutNode store node data it temporal way - it my be accessed by GetNode, but will not stored in backend store.
	PutNode(nodePtr []byte, node TrieNode) error
	// PutValue do the same as PutNode, but for value
	PutValue(valuePtr, value []byte) error
	// PersistNode mark temporal node to be persisted to backend storage in next call to CommitPersistChanges
	PersistNode(nodePtr []byte) (bool, error)
	// PersistValue do same as PersistNode, but for value
	PersistValue(valuePtr []byte) (bool, error)
	// Height returns number of last block trie was persist for
	Height() (uint64, error)
	// CommitChanges frees all inMemory nodes and actually stores nodes and value marked to be persist by
	// PersistNode and PersistValue in single backend store update - usually used with block number
	CommitChanges(blockNum uint64) error
	// RollbackChanges free all in memory nodes and nodes marked to be persist, without storing anything in
	// underlying database. Operation can cause to current MPTrie become invalid, so always reload trie
	// after the call
	RollbackChanges() error
}

Store stores Trie nodes and values in way Hash(node)->node bytes Hash(value)->value bytes

type TrieNode

type TrieNode interface {
	// contains filtered or unexported methods
}

type TrieNodeWithValue

type TrieNodeWithValue interface {
	TrieNode
	// contains filtered or unexported methods
}

type ValueNode

type ValueNode struct {
	Key                  []byte   `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	ValuePtr             []byte   `protobuf:"bytes,2,opt,name=valuePtr,proto3" json:"valuePtr,omitempty"`
	Deleted              bool     `protobuf:"varint,3,opt,name=deleted,proto3" json:"deleted,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*ValueNode) Descriptor

func (*ValueNode) Descriptor() ([]byte, []int)

func (*ValueNode) GetDeleted

func (m *ValueNode) GetDeleted() bool

func (*ValueNode) GetKey

func (m *ValueNode) GetKey() []byte

func (*ValueNode) GetValuePtr

func (m *ValueNode) GetValuePtr() []byte

func (*ValueNode) ProtoMessage

func (*ValueNode) ProtoMessage()

func (*ValueNode) Reset

func (m *ValueNode) Reset()

func (*ValueNode) String

func (m *ValueNode) String() string

func (*ValueNode) XXX_DiscardUnknown

func (m *ValueNode) XXX_DiscardUnknown()

func (*ValueNode) XXX_Marshal

func (m *ValueNode) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*ValueNode) XXX_Merge

func (m *ValueNode) XXX_Merge(src proto.Message)

func (*ValueNode) XXX_Size

func (m *ValueNode) XXX_Size() int

func (*ValueNode) XXX_Unmarshal

func (m *ValueNode) XXX_Unmarshal(b []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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