Documentation ¶
Index ¶
- Variables
- func GenerateProof(root []byte, keys [][]byte, db chaindb.Database) ([][]byte, error)
- func GetFromDB(db chaindb.Database, rootHash common.Hash, key []byte) (value []byte, err error)
- func VerifyProof(proof [][]byte, root []byte, items []Pair) (bool, error)
- type Node
- type Pair
- type Trie
- func (t *Trie) ClearFromChild(keyToChild, key []byte) error
- func (t *Trie) ClearPrefix(prefixLE []byte)
- func (t *Trie) ClearPrefixFromDB(db chaindb.Database, prefix []byte) error
- func (t *Trie) ClearPrefixLimit(prefixLE []byte, limit uint32) (deleted uint32, allDeleted bool)
- func (t *Trie) DeepCopy() (trieCopy *Trie)
- func (t *Trie) Delete(keyLE []byte)
- func (t *Trie) DeleteChild(keyToChild []byte)
- func (t *Trie) DeleteFromDB(db chaindb.Database, key []byte) error
- func (t *Trie) Entries() map[string][]byte
- func (t *Trie) Get(keyLE []byte) (value []byte)
- func (t *Trie) GetChild(keyToChild []byte) (*Trie, error)
- func (t *Trie) GetDeletedNodeHashes() (hashesSet map[common.Hash]struct{})
- func (t *Trie) GetFromChild(keyToChild, key []byte) ([]byte, error)
- func (t *Trie) GetInsertedNodeHashes() (hashesSet map[common.Hash]struct{}, err error)
- func (t *Trie) GetKeysWithPrefix(prefixLE []byte) (keysLE [][]byte)
- func (t *Trie) Hash() (rootHash common.Hash, err error)
- func (t *Trie) Load(db chaindb.Database, rootHash common.Hash) error
- func (t *Trie) LoadFromMap(data map[string]string) (err error)
- func (t *Trie) LoadFromProof(proofEncodedNodes [][]byte, rootHash []byte) error
- func (t *Trie) MustHash() common.Hash
- func (t *Trie) NextKey(keyLE []byte) (nextKeyLE []byte)
- func (t *Trie) PopulateNodeHashes(n *Node, hashesSet map[common.Hash]struct{})
- func (t *Trie) Put(keyLE, value []byte)
- func (t *Trie) PutChild(keyToChild []byte, child *Trie) error
- func (t *Trie) PutInDB(db chaindb.Database, key, value []byte) error
- func (t *Trie) PutIntoChild(keyToChild, key, value []byte) error
- func (t *Trie) RootNode() *Node
- func (t *Trie) Snapshot() (newTrie *Trie)
- func (t *Trie) Store(db chaindb.Database) error
- func (t *Trie) String() string
- func (t *Trie) WriteDirty(db chaindb.Database) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyProof = errors.New("proof slice empty") ErrDecodeNode = errors.New("cannot decode node") )
var ( // ErrEmptyTrieRoot ... ErrEmptyTrieRoot = errors.New("provided trie must have a root") // ErrValueNotFound ... ErrValueNotFound = errors.New("expected value not found in the trie") // ErrKeyNotFound ... ErrKeyNotFound = errors.New("expected key not found in the trie") // ErrDuplicateKeys ... ErrDuplicateKeys = errors.New("duplicate keys on verify proof") // ErrLoadFromProof ... ErrLoadFromProof = errors.New("failed to build the proof trie") )
var ChildStorageKeyPrefix = []byte(":child_storage:default:")
ChildStorageKeyPrefix is the prefix for all child storage keys
var EmptyHash, _ = NewEmptyTrie().Hash()
EmptyHash is the empty trie hash.
var ErrChildTrieDoesNotExist = errors.New("child trie does not exist")
Functions ¶
func GenerateProof ¶
GenerateProof receive the keys to proof, the trie root and a reference to database
Types ¶
type Pair ¶
type Pair struct{ Key, Value []byte }
Pair holds the key and value to check while verifying the proof
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
Trie is a base 16 modified Merkle Patricia trie.
func (*Trie) ClearFromChild ¶
ClearFromChild removes the child storage entry
func (*Trie) ClearPrefix ¶
ClearPrefix deletes all nodes in the trie for which the key contains the prefix given in little Endian format.
func (*Trie) ClearPrefixFromDB ¶
ClearPrefixFromDB deletes all nodes with keys starting the given prefix from the trie. It writes the updated nodes from the changed node up to the root node to the database in a batch operation. in a batch operation.
func (*Trie) ClearPrefixLimit ¶
ClearPrefixLimit deletes the keys having the prefix given in little Endian format for up to `limit` keys. It returns the number of deleted keys and a boolean indicating if all keys with the prefix were deleted within the limit.
func (*Trie) DeepCopy ¶
DeepCopy deep copies the trie and returns the copy. Note this method is meant to be used in tests and should not be used in production since it's rather inefficient compared to the copy on write mechanism achieved through snapshots.
func (*Trie) Delete ¶
Delete removes the node of the trie with the key matching the key given in little Endian format. If no node is found at this key, nothing is deleted.
func (*Trie) DeleteChild ¶
DeleteChild deletes the child storage trie
func (*Trie) DeleteFromDB ¶
DeleteFromDB deletes a value from the trie at the key given. It writes the updated nodes from the changed node up to the root node to the database in a batch operation.
func (*Trie) Entries ¶
Entries returns all the key-value pairs in the trie as a map of keys to values where the keys are encoded in Little Endian.
func (*Trie) Get ¶
Get returns the value in the node of the trie which matches its key with the key given. Note the key argument is given in little Endian format.
func (*Trie) GetDeletedNodeHashes ¶
GetDeletedNodeHashes returns a set of all the hashes of nodes that were deleted from the trie since the last snapshot was made. The returned set is a copy of the internal set to prevent data races.
func (*Trie) GetFromChild ¶
GetFromChild retrieves a key-value pair from the child trie located in the main trie at key :child_storage:[keyToChild]
func (*Trie) GetInsertedNodeHashes ¶
GetInsertedNodeHashes returns a set of hashes with all the hashes of all nodes that were inserted in the state trie since the last snapshot. We need to compute the hash values of each newly inserted node.
func (*Trie) GetKeysWithPrefix ¶
GetKeysWithPrefix returns all keys in little Endian format from nodes in the trie that have the given little Endian formatted prefix in their key.
func (*Trie) Load ¶
Load reconstructs the trie from the database from the given root hash. It is used when restarting the node to load the current state trie.
func (*Trie) LoadFromMap ¶
LoadFromMap loads the given data mapping of key to value into the trie. The keys are in hexadecimal little Endian encoding and the values are hexadecimal encoded.
func (*Trie) LoadFromProof ¶
LoadFromProof sets a partial trie based on the proof slice of encoded nodes. Note this is exported because it is imported is used by: https://github.com/ComposableFi/ibc-go/blob/6d62edaa1a3cb0768c430dab81bb195e0b0c72db/modules/light-clients/11-beefy/types/client_state.go#L78
func (*Trie) MustHash ¶
MustHash returns the hashed root of the trie. It panics if it fails to hash the root node.
func (*Trie) NextKey ¶
NextKey returns the next key in the trie in lexicographic order. It returns nil if no next key is found.
func (*Trie) PopulateNodeHashes ¶
PopulateNodeHashes writes hashes of each children of the node given as keys to the map hashesSet.
func (*Trie) PutChild ¶
PutChild inserts a child trie into the main trie at key :child_storage:[keyToChild] A child trie is added as a node (K, V) in the main trie. K is the child storage key associated to the child trie, and V is the root hash of the child trie.
func (*Trie) PutInDB ¶
PutInDB inserts a value in the trie at the key given. It writes the updated nodes from the changed node up to the root node to the database in a batch operation.
func (*Trie) PutIntoChild ¶
PutIntoChild puts a key-value pair into the child trie located in the main trie at key :child_storage:[keyToChild]
func (*Trie) Snapshot ¶
Snapshot creates a copy of the trie. Note it does not deep copy the trie, but will copy on write as modifications are done on this new trie. It does a snapshot of all child tries as well, and resets the set of deleted hashes.
func (*Trie) Store ¶
Store stores each trie node in the database, where the key is the hash of the encoded node and the value is the encoded node. Generally, this will only be used for the genesis trie.