Documentation
¶
Index ¶
- Constants
- func ApplyWitness(uw primitives.UpdateWitness, oldStateRoot chainhash.Hash) (*chainhash.Hash, error)
- func CalculateRoot(key chainhash.Hash, value chainhash.Hash, witnessBitfield chainhash.Hash, ...) (*chainhash.Hash, error)
- func CalculateSubtreeHashWithOneLeaf(key *chainhash.Hash, value *chainhash.Hash, atLevel uint8) chainhash.Hash
- func CheckWitness(vw *primitives.VerificationWitness, oldStateRoot chainhash.Hash) bool
- func GenerateUpdateWitness(tree TreeDatabaseTransaction, key chainhash.Hash, value chainhash.Hash) (*primitives.UpdateWitness, error)
- func GenerateVerificationWitness(tree TreeDatabaseTransaction, key chainhash.Hash) (*primitives.VerificationWitness, error)
- type InMemoryTreeDB
- type InMemoryTreeTX
- func (i *InMemoryTreeTX) DeleteNode(h chainhash.Hash) error
- func (i *InMemoryTreeTX) Get(k chainhash.Hash) (*chainhash.Hash, error)
- func (i *InMemoryTreeTX) GetNode(nodeHash chainhash.Hash) (*Node, error)
- func (i *InMemoryTreeTX) Hash() (*chainhash.Hash, error)
- func (i *InMemoryTreeTX) NewNode(left *Node, right *Node, subtreeHash chainhash.Hash) (*Node, error)
- func (i *InMemoryTreeTX) NewSingleNode(key chainhash.Hash, value chainhash.Hash, subtreeHash chainhash.Hash) (*Node, error)
- func (i *InMemoryTreeTX) Root() (*Node, error)
- func (i *InMemoryTreeTX) Set(k chainhash.Hash, v chainhash.Hash) error
- func (i *InMemoryTreeTX) SetNode(n *Node) error
- func (i *InMemoryTreeTX) SetRoot(n *Node) error
- type Node
- func (i *Node) Empty() bool
- func (i *Node) GetHash() chainhash.Hash
- func (i *Node) GetSingleKey() chainhash.Hash
- func (i *Node) GetSingleValue() chainhash.Hash
- func (i *Node) IsSingle() bool
- func (i *Node) Left() *chainhash.Hash
- func (i *Node) Marshal() []byte
- func (i *Node) Right() *chainhash.Hash
- func (i *Node) Unmarshal(b []byte) error
- type Tree
- type TreeDatabase
- type TreeDatabaseTransaction
- type TreeMemoryCache
- func (t *TreeMemoryCache) Flush() error
- func (t *TreeMemoryCache) GetUnderlying() TreeDatabase
- func (t *TreeMemoryCache) Hash() (*chainhash.Hash, error)
- func (t *TreeMemoryCache) Update(cb func(TreeDatabaseTransaction) error) error
- func (t *TreeMemoryCache) UpdateUnderlying(cache TreeDatabase) error
- func (t *TreeMemoryCache) View(cb func(TreeDatabaseTransaction) error) error
- type TreeMemoryCacheTransaction
- func (t *TreeMemoryCacheTransaction) DeleteNode(c chainhash.Hash) error
- func (t *TreeMemoryCacheTransaction) Get(key chainhash.Hash) (*chainhash.Hash, error)
- func (t *TreeMemoryCacheTransaction) GetNode(c chainhash.Hash) (*Node, error)
- func (t *TreeMemoryCacheTransaction) Hash() (*chainhash.Hash, error)
- func (t *TreeMemoryCacheTransaction) NewNode(left *Node, right *Node, subtreeHash chainhash.Hash) (*Node, error)
- func (t *TreeMemoryCacheTransaction) NewSingleNode(key chainhash.Hash, value chainhash.Hash, subtreeHash chainhash.Hash) (*Node, error)
- func (t *TreeMemoryCacheTransaction) Root() (*Node, error)
- func (t *TreeMemoryCacheTransaction) Set(key chainhash.Hash, val chainhash.Hash) error
- func (t *TreeMemoryCacheTransaction) SetNode(n *Node) error
- func (t *TreeMemoryCacheTransaction) SetRoot(n *Node) error
- type TreeTransaction
- func (t *TreeTransaction) Get(key chainhash.Hash) (*chainhash.Hash, error)
- func (t *TreeTransaction) Hash() (*chainhash.Hash, error)
- func (t *TreeTransaction) Prove(key chainhash.Hash) (*primitives.VerificationWitness, error)
- func (t *TreeTransaction) Set(key chainhash.Hash, value chainhash.Hash) error
- func (t *TreeTransaction) SetWithWitness(key chainhash.Hash, value chainhash.Hash) (*primitives.UpdateWitness, error)
- type TreeTransactionAccess
Constants ¶
const ( // FlagSingle designates that this node is a single node. FlagSingle = iota // FlagLeft designates that this node has a left branch. FlagLeft // FlagRight designates that this node has a right branch. FlagRight // FlagBoth designates that this node has both a left and right branch. FlagBoth )
Variables ¶
This section is empty.
Functions ¶
func ApplyWitness ¶
func ApplyWitness(uw primitives.UpdateWitness, oldStateRoot chainhash.Hash) (*chainhash.Hash, error)
ApplyWitness applies a witness to an old state root to generate a new state root.
func CalculateRoot ¶
func CalculateRoot(key chainhash.Hash, value chainhash.Hash, witnessBitfield chainhash.Hash, witnesses []chainhash.Hash, lastLevel uint8) (*chainhash.Hash, error)
CalculateRoot calculates the root of the tree with the given witness information.
func CalculateSubtreeHashWithOneLeaf ¶
func CalculateSubtreeHashWithOneLeaf(key *chainhash.Hash, value *chainhash.Hash, atLevel uint8) chainhash.Hash
CalculateSubtreeHashWithOneLeaf calculates the hash of a subtree with only a single leaf at a certain height. atLevel is the height to calculate at.
func CheckWitness ¶
func CheckWitness(vw *primitives.VerificationWitness, oldStateRoot chainhash.Hash) bool
CheckWitness ensures the state root matches.
func GenerateUpdateWitness ¶
func GenerateUpdateWitness(tree TreeDatabaseTransaction, key chainhash.Hash, value chainhash.Hash) (*primitives.UpdateWitness, error)
GenerateUpdateWitness generates a witness that allows calculation of a new state root.
func GenerateVerificationWitness ¶
func GenerateVerificationWitness(tree TreeDatabaseTransaction, key chainhash.Hash) (*primitives.VerificationWitness, error)
GenerateVerificationWitness generates a witness that allows verification of a key in the tree.
Types ¶
type InMemoryTreeDB ¶
type InMemoryTreeDB struct {
// contains filtered or unexported fields
}
InMemoryTreeDB is a transaction based in memory.
func NewInMemoryTreeDB ¶
func NewInMemoryTreeDB() *InMemoryTreeDB
NewInMemoryTreeDB creates a new in-memory tree database.
func (*InMemoryTreeDB) Hash ¶
func (t *InMemoryTreeDB) Hash() (*chainhash.Hash, error)
Hash gets the root hash of the tree.
func (*InMemoryTreeDB) Update ¶
func (t *InMemoryTreeDB) Update(cb func(TreeDatabaseTransaction) error) error
Update runs cb with an update transaction.
func (*InMemoryTreeDB) View ¶
func (t *InMemoryTreeDB) View(cb func(TreeDatabaseTransaction) error) error
View runs cb with a view only transaction.
type InMemoryTreeTX ¶
type InMemoryTreeTX struct {
// contains filtered or unexported fields
}
InMemoryTreeTX is a tree stored in memory.
func (*InMemoryTreeTX) DeleteNode ¶
func (i *InMemoryTreeTX) DeleteNode(h chainhash.Hash) error
DeleteNode deletes a node if it exists.
func (*InMemoryTreeTX) GetNode ¶
func (i *InMemoryTreeTX) GetNode(nodeHash chainhash.Hash) (*Node, error)
GetNode gets a node from the tree database.
func (*InMemoryTreeTX) Hash ¶
func (i *InMemoryTreeTX) Hash() (*chainhash.Hash, error)
Hash gets the hash of the tree transaction.
func (*InMemoryTreeTX) NewNode ¶
func (i *InMemoryTreeTX) NewNode(left *Node, right *Node, subtreeHash chainhash.Hash) (*Node, error)
NewNode creates a new empty node.
func (*InMemoryTreeTX) NewSingleNode ¶
func (i *InMemoryTreeTX) NewSingleNode(key chainhash.Hash, value chainhash.Hash, subtreeHash chainhash.Hash) (*Node, error)
NewSingleNode creates a new node with only one key-value pair.
func (*InMemoryTreeTX) Root ¶
func (i *InMemoryTreeTX) Root() (*Node, error)
Root gets the root of the tree.
func (*InMemoryTreeTX) SetNode ¶
func (i *InMemoryTreeTX) SetNode(n *Node) error
SetNode sets a node in the database. The node passed MUST be an Node
func (*InMemoryTreeTX) SetRoot ¶
func (i *InMemoryTreeTX) SetRoot(n *Node) error
SetRoot sets the root of the tree.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is a node of the in-memory tree database.
func (*Node) GetSingleKey ¶
GetSingleKey gets the only key in the subtree.
func (*Node) GetSingleValue ¶
GetSingleValue gets the only value in the subtree.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree represents a state tree.
type TreeDatabase ¶
type TreeDatabase interface {
Update(func(TreeDatabaseTransaction) error) error
View(func(TreeDatabaseTransaction) error) error
Hash() (*chainhash.Hash, error)
}
TreeDatabase provides functions to update or view parts of the tree.
type TreeDatabaseTransaction ¶
type TreeDatabaseTransaction interface {
// Root gets the root node.
Root() (*Node, error)
// Hash gets the hash of the root node.
Hash() (*chainhash.Hash, error)
// SetRoot sets the root node.
SetRoot(*Node) error
// NewNode creates a new node, adds it to the tree database, and returns it.
NewNode(left *Node, right *Node, subtreeHash chainhash.Hash) (*Node, error)
// NewSingleNode creates a new node that represents a subtree with only a single key.
NewSingleNode(key chainhash.Hash, value chainhash.Hash, subtreeHash chainhash.Hash) (*Node, error)
// GetNode gets a node from the database.
GetNode(chainhash.Hash) (*Node, error)
// SetNode sets a node in the database.
SetNode(*Node) error
// DeleteNode deletes a node from the database.
DeleteNode(chainhash.Hash) error
// Get a value from the kv store.
Get(chainhash.Hash) (*chainhash.Hash, error)
// Set a value in the kv store.
Set(chainhash.Hash, chainhash.Hash) error
}
TreeDatabaseTransaction is a transaction interface to access or update the tree.
type TreeMemoryCache ¶
type TreeMemoryCache struct {
// contains filtered or unexported fields
}
TreeMemoryCache is a cache that allows
func NewTreeMemoryCache ¶
func NewTreeMemoryCache(underlyingDatabase TreeDatabase) (*TreeMemoryCache, error)
NewTreeMemoryCache constructs a tree memory cache that can be committed based on an underlying tree (probably on disk).
func (*TreeMemoryCache) Flush ¶
func (t *TreeMemoryCache) Flush() error
Flush flushes the transaction to the underlying tree.
func (*TreeMemoryCache) GetUnderlying ¶
func (t *TreeMemoryCache) GetUnderlying() TreeDatabase
GetUnderlying gets the underlying store.
func (*TreeMemoryCache) Hash ¶
func (t *TreeMemoryCache) Hash() (*chainhash.Hash, error)
Hash gets the hash of the current tree.
func (*TreeMemoryCache) Update ¶
func (t *TreeMemoryCache) Update(cb func(TreeDatabaseTransaction) error) error
Update creates an update transaction for the cache.
func (*TreeMemoryCache) UpdateUnderlying ¶
func (t *TreeMemoryCache) UpdateUnderlying(cache TreeDatabase) error
UpdateUnderlying updates the underlying store.
func (*TreeMemoryCache) View ¶
func (t *TreeMemoryCache) View(cb func(TreeDatabaseTransaction) error) error
View creates a view transaction for the cache.
type TreeMemoryCacheTransaction ¶
type TreeMemoryCacheTransaction struct {
// contains filtered or unexported fields
}
TreeMemoryCacheTransaction is a transaction wrapper on a CSMT that allows reading and writing from an underlying data store.
func (*TreeMemoryCacheTransaction) DeleteNode ¶
func (t *TreeMemoryCacheTransaction) DeleteNode(c chainhash.Hash) error
DeleteNode deletes a node from the transaction.
func (*TreeMemoryCacheTransaction) GetNode ¶
func (t *TreeMemoryCacheTransaction) GetNode(c chainhash.Hash) (*Node, error)
GetNode gets a node based on the subtree hash.
func (*TreeMemoryCacheTransaction) Hash ¶
func (t *TreeMemoryCacheTransaction) Hash() (*chainhash.Hash, error)
Hash gets the root hash of the tree transaction cache.
func (*TreeMemoryCacheTransaction) NewNode ¶
func (t *TreeMemoryCacheTransaction) NewNode(left *Node, right *Node, subtreeHash chainhash.Hash) (*Node, error)
NewNode creates a new node and adds it to the cache.
func (*TreeMemoryCacheTransaction) NewSingleNode ¶
func (t *TreeMemoryCacheTransaction) NewSingleNode(key chainhash.Hash, value chainhash.Hash, subtreeHash chainhash.Hash) (*Node, error)
NewSingleNode creates a new node with only a single KV-pair in the subtree.
func (*TreeMemoryCacheTransaction) Root ¶
func (t *TreeMemoryCacheTransaction) Root() (*Node, error)
Root gets the current root of the transaction.
func (*TreeMemoryCacheTransaction) SetNode ¶
func (t *TreeMemoryCacheTransaction) SetNode(n *Node) error
SetNode sets a node in the transaction.
func (*TreeMemoryCacheTransaction) SetRoot ¶
func (t *TreeMemoryCacheTransaction) SetRoot(n *Node) error
SetRoot sets the root for the current transaction. If it does not exist in the cache or the underlying data store, add it to the cache.
type TreeTransaction ¶
type TreeTransaction struct {
// contains filtered or unexported fields
}
TreeTransaction is a wr
func (*TreeTransaction) Hash ¶
func (t *TreeTransaction) Hash() (*chainhash.Hash, error)
Hash get the root hash
func (*TreeTransaction) Prove ¶
func (t *TreeTransaction) Prove(key chainhash.Hash) (*primitives.VerificationWitness, error)
Prove proves a key in the tree.
func (*TreeTransaction) SetWithWitness ¶
func (t *TreeTransaction) SetWithWitness(key chainhash.Hash, value chainhash.Hash) (*primitives.UpdateWitness, error)
SetWithWitness returns an update witness and sets the value in the tree.