Documentation
¶
Index ¶
- Variables
- func GetFromDB(db chaindb.Database, rootHash common.Hash, key []byte) (value []byte, err error)
- func PopulateNodeHashes(n *Node, nodeHashes map[string]struct{})
- type Database
- type Node
- type Trie
- func (t *Trie) ClearFromChild(keyToChild, key []byte) error
- func (t *Trie) ClearPrefix(prefixLE []byte)
- 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) Entries() map[string][]byte
- func (t *Trie) GenesisBlock() (genesisHeader types.Header, err error)
- func (t *Trie) Get(keyLE []byte) (value []byte)
- func (t *Trie) GetChangedNodeHashes() (inserted, deleted map[string]struct{}, err error)
- func (t *Trie) GetChild(keyToChild []byte) (*Trie, error)
- func (t *Trie) GetFromChild(keyToChild, key []byte) ([]byte, error)
- func (t *Trie) GetKeysWithPrefix(prefixLE []byte) (keysLE [][]byte)
- func (t *Trie) Hash() (rootHash common.Hash, err error)
- func (t *Trie) Load(db Database, rootHash common.Hash) error
- func (t *Trie) MustHash() common.Hash
- func (t *Trie) NextKey(keyLE []byte) (nextKeyLE []byte)
- func (t *Trie) Put(keyLE, value []byte)
- func (t *Trie) PutChild(keyToChild []byte, child *Trie) error
- func (t *Trie) PutIntoChild(keyToChild, key, value []byte) error
- func (t *Trie) RootNode() *Node
- func (t *Trie) Snapshot() (newTrie *Trie)
- func (t *Trie) String() string
- func (t *Trie) WriteDirty(db chaindb.Database) error
- type Version
Constants ¶
This section is empty.
Variables ¶
var ChildStorageKeyPrefix = []byte(":child_storage:default:")
ChildStorageKeyPrefix is the prefix for all child storage keys
var EmptyHash = common.MustBlake2bHash([]byte{0})
EmptyHash is the empty trie hash.
var ErrChildTrieDoesNotExist = errors.New("child trie does not exist")
var ErrParseVersion = errors.New("parsing version failed")
Functions ¶
func GetFromDB ¶ added in v0.3.0
GetFromDB retrieves a value at the given key from the trie using the database. It recursively descends into the trie using the database starting from the root node until it reaches the node with the given key. It then reads the value from the database.
func PopulateNodeHashes ¶ added in v0.7.0
PopulateNodeHashes writes the node hash values of the node given and of all its descendant nodes as keys to the nodeHashes map. It is assumed the node and its descendant nodes have their Merkle value already computed.
Types ¶
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
Trie is a base 16 modified Merkle Patricia trie.
func LoadFromMap ¶ added in v0.7.0
LoadFromMap loads the given data mapping of key to value into a new empty trie. The keys are in hexadecimal little Endian encoding and the values are hexadecimal encoded.
func (*Trie) ClearFromChild ¶ added in v0.2.0
ClearFromChild removes the child storage entry
func (*Trie) ClearPrefix ¶ added in v0.3.0
ClearPrefix deletes all nodes in the trie for which the key contains the prefix given in little Endian format.
func (*Trie) ClearPrefixLimit ¶ added in v0.7.0
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 ¶ added in v0.2.0
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 ¶ added in v0.3.1
DeleteChild deletes the child storage trie
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) GenesisBlock ¶ added in v0.7.0
GenesisBlock creates a genesis block from the trie.
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) GetChangedNodeHashes ¶ added in v0.7.0
GetChangedNodeHashes returns the two sets of hashes for all nodes inserted and deleted in the state trie since the last snapshot. Returned maps are safe for mutation.
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) GetKeysWithPrefix ¶ added in v0.2.0
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) MustHash ¶ added in v0.2.0
MustHash returns the hashed root of the trie. It panics if it fails to hash the root node.
func (*Trie) NextKey ¶ added in v0.2.0
NextKey returns the next key in the trie in lexicographic order. It returns nil if no next key is found.
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) PutIntoChild ¶
PutIntoChild puts a key-value pair into the child trie located in the main trie at key :child_storage:[keyToChild]
func (*Trie) Snapshot ¶ added in v0.3.0
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.
type Version ¶ added in v0.7.0
type Version uint8
Version is the state trie version which dictates how a Merkle root should be constructed. It is defined in https://spec.polkadot.network/#defn-state-version
const ( // V0 is the state trie version 0 where the values of the keys are // inserted into the trie directly. // TODO set to iota once CI passes V0 Version = 1 )
func ParseVersion ¶ added in v0.7.0
ParseVersion parses a state trie version string.