Documentation ¶
Index ¶
- Constants
- Variables
- type CacheDB
- type DataArray
- type DbTx
- type Hash
- type Trie
- func (s *Trie) AtomicUpdate(keys, values [][]byte) ([]byte, error)
- func (s *Trie) Commit() error
- func (s *Trie) Get(key []byte) ([]byte, error)
- func (s *Trie) LoadCache(root []byte) error
- func (s *Trie) MerkleProof(key []byte) ([][]byte, bool, []byte, []byte, error)
- func (s *Trie) MerkleProofCompressed(key []byte) ([]byte, [][]byte, int, bool, []byte, []byte, error)
- func (s *Trie) MerkleProofCompressedR(key, root []byte) ([]byte, [][]byte, int, bool, []byte, []byte, error)
- func (s *Trie) MerkleProofR(key, root []byte) ([][]byte, bool, []byte, []byte, error)
- func (s *Trie) Revert(toOldRoot []byte) error
- func (s *Trie) StageUpdates(txn DbTx)
- func (s *Trie) Stash(rollbackCache bool) error
- func (s *Trie) TrieRootExists(root []byte) bool
- func (s *Trie) Update(keys, values [][]byte) ([]byte, error)
- func (s *Trie) VerifyInclusion(ap [][]byte, key, value []byte) bool
- func (s *Trie) VerifyInclusionC(bitmap, key, value []byte, ap [][]byte, length int) bool
- func (s *Trie) VerifyNonInclusion(ap [][]byte, key, value, proofKey []byte) bool
- func (s *Trie) VerifyNonInclusionC(ap [][]byte, length int, bitmap, key, value, proofKey []byte) bool
Constants ¶
const (
HashLength = 32
)
Variables ¶
var ( // Trie default value : [byte(0)] DefaultLeaf = []byte{0} )
Functions ¶
This section is empty.
Types ¶
type Hash ¶
type Hash [HashLength]byte
type Trie ¶
type Trie struct { // Root is the current root of the smt. Root []byte // TrieHeight is the number if bits in a key TrieHeight int // LoadDbCounter counts the nb of db reads in on update LoadDbCounter int // LoadCacheCounter counts the nb of cache reads in on update LoadCacheCounter int // CacheHeightLimit is the number of tree levels we want to store in cache CacheHeightLimit int // contains filtered or unexported fields }
Trie is a modified sparse Merkle tree. Instead of storing values at the leaves of the tree, the values are stored at the highest subtree root that contains only that value. If the tree is sparse, this requires fewer hashing operations.
func (*Trie) AtomicUpdate ¶
AtomicUpdate can be called multiple times and all the updated nodes will be commited and roots will be stored in past tries. Can be used for updating several blocks before committing to DB.
func (*Trie) Commit ¶
Commit stores the updated nodes to disk. Commit should be called for every block otherwise past tries are not recorded and it is not possible to revert to them (except if AtomicUpdate is used, which records every state).
func (*Trie) LoadCache ¶
LoadCache loads the first layers of the merkle tree given a root This is called after a node restarts so that it doesnt become slow with db reads LoadCache also updates the Root with the given root.
func (*Trie) MerkleProof ¶
MerkleProof generates a Merke proof of inclusion or non-inclusion for the current trie root returns the audit path, bool (key included), key, value, error (key,value) can be 1- (nil, value), value of the included key, 2- the kv of a LeafNode on the path of the non-included key, 3- (nil, nil) for a non-included key with a DefaultLeaf on the path
func (*Trie) MerkleProofCompressed ¶
func (s *Trie) MerkleProofCompressed(key []byte) ([]byte, [][]byte, int, bool, []byte, []byte, error)
MerkleProofCompressed returns a compressed merkle proof
func (*Trie) MerkleProofCompressedR ¶
func (s *Trie) MerkleProofCompressedR(key, root []byte) ([]byte, [][]byte, int, bool, []byte, []byte, error)
MerkleProofCompressed returns a compressed merkle proof in the given trie
func (*Trie) MerkleProofR ¶
MerkleProofPast generates a Merke proof of inclusion or non-inclusion for a given past trie root returns the audit path, bool (key included), key, value, error (key,value) can be 1- (nil, value), value of the included key, 2- the kv of a LeafNode on the path of the non-included key, 3- (nil, nil) for a non-included key with a DefaultLeaf on the path
func (*Trie) Revert ¶
Revert rewinds the state tree to a previous version All the nodes (subtree roots and values) reverted are deleted from the database.
func (*Trie) StageUpdates ¶
StageUpdates requires a database transaction as input Unlike Commit(), it doesnt commit the transaction the database transaction MUST be commited otherwise the state ROOT will not exist.
func (*Trie) Stash ¶
Stash rolls back the changes made by previous updates and loads the cache from before the rollback.
func (*Trie) TrieRootExists ¶
TrieRootExists returns true if the root exists in Database.
func (*Trie) Update ¶
Update adds and deletes a sorted list of keys and their values to the trie Adding and deleting can be simultaneous. To delete, set the value to DefaultLeaf. If Update is called multiple times, only the state after the last update is commited.
func (*Trie) VerifyInclusion ¶
VerifyInclusion verifies that key/value is included in the trie with latest root
func (*Trie) VerifyInclusionC ¶
VerifyInclusionC verifies that key/value is included in the trie with latest root
func (*Trie) VerifyNonInclusion ¶
VerifyNonInclusion verifies a proof of non inclusion, Returns true if the non-inclusion is verified