Documentation
¶
Index ¶
- Variables
- type Database
- func (db *Database) Commit(node utils.Hash, report bool) error
- func (db *Database) Dereference(child utils.Hash, parent utils.Hash)
- func (db *Database) DiskDB() DatabaseReader
- func (db *Database) Insert(hash utils.Hash, blob []byte)
- func (db *Database) Node(hash utils.Hash) ([]byte, error)
- func (db *Database) Nodes() []utils.Hash
- func (db *Database) Reference(child utils.Hash, parent utils.Hash)
- func (db *Database) Size() utils.StorageSize
- type DatabaseReader
- type DatabaseWriter
- type Iterator
- type LeafCallback
- type MissingNodeError
- type NodeIterator
- type Sync
- func (s *Sync) AddRawEntry(hash utils.Hash, depth int, parent utils.Hash)
- func (s *Sync) AddSubTrie(root utils.Hash, depth int, parent utils.Hash, callback LeafCallback)
- func (s *Sync) Commit(dbw ldb.Writer) (int, error)
- func (s *Sync) Missing(max int) []utils.Hash
- func (s *Sync) Pending() int
- func (s *Sync) Process(results []SyncResult) (bool, int, error)
- type SyncResult
- type Trie
- func (t *Trie) Commit(onleaf LeafCallback) (root utils.Hash, err error)
- func (t *Trie) CommitTo(db *Database) (root utils.Hash, err error)
- func (t *Trie) Delete(key []byte)
- func (t *Trie) Get(key []byte) []byte
- func (t *Trie) Hash() utils.Hash
- func (t *Trie) NodeIterator(start []byte) NodeIterator
- func (t *Trie) PrefixIterator(prefix []byte) NodeIterator
- func (t *Trie) Prove(key []byte, fromLevel uint, proofDb db.Writer) error
- func (t *Trie) Root() []byte
- func (t *Trie) SetCacheLimit(l uint16)
- func (t *Trie) TryDelete(key []byte) error
- func (t *Trie) TryGet(key []byte) ([]byte, error)
- func (t *Trie) TryUpdate(key, value []byte) error
- func (t *Trie) Update(key, value []byte)
- type TrieWarp
- func (t *TrieWarp) Commit(onleaf LeafCallback) (root utils.Hash, err error)
- func (t *TrieWarp) Copy() *TrieWarp
- func (t *TrieWarp) Delete(key []byte)
- func (t *TrieWarp) Get(key []byte) []byte
- func (t *TrieWarp) GetKey(shaKey []byte) []byte
- func (t *TrieWarp) Hash() utils.Hash
- func (t *TrieWarp) NodeIterator(start []byte) NodeIterator
- func (t *TrieWarp) Prove(key []byte, fromLevel uint, proofDb db.Writer) error
- func (t *TrieWarp) Root() []byte
- func (t *TrieWarp) TryDelete(key []byte) error
- func (t *TrieWarp) TryGet(key []byte) ([]byte, error)
- func (t *TrieWarp) TryUpdate(key, value []byte) error
- func (t *TrieWarp) Update(key, value []byte)
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyProcessed = errors.New("already processed")
ErrAlreadyProcessed is returned by the trie sync when it's requested to process a node it already processed previously.
var ErrNotRequested = errors.New("not requested")
ErrNotRequested is returned by the trie sync when it's requested to process a node it did not request.
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database is an intermediate write layer between the trie data structures and the disk database. The aim is to accumulate trie writes in-memory and only periodically flush a couple tries to disk, garbage collecting the remainder.
func NewDatabase ¶
NewDatabase creates a new trie database to store ephemeral trie content before its written out to disk or garbage collected.
func (*Database) Commit ¶
Commit iterates over all the children of a particular node, writes them out to disk, forcefully tearing down all references in both directions.
As a side effect, all pre-images accumulated up to this point are also written.
func (*Database) Dereference ¶
Dereference removes an existing reference from a parent node to a child node.
func (*Database) DiskDB ¶
func (db *Database) DiskDB() DatabaseReader
DiskDB retrieves the persistent storage backing the trie database.
func (*Database) Insert ¶
Insert writes a new trie node to the memory database if it's yet unknown. The method will make a copy of the slice.
func (*Database) Node ¶
Node retrieves a cached trie node from memory. If it cannot be found cached, the method queries the persistent database for the content.
func (*Database) Nodes ¶
Nodes retrieves the hashes of all the nodes cached within the memory database. This method is extremely expensive and should only be used to validate internal states in test code.
func (*Database) Size ¶
func (db *Database) Size() utils.StorageSize
Size returns the current storage size of the memory cache in front of the persistent database layer.
type DatabaseReader ¶
type DatabaseReader interface { // Get retrieves the value associated with key form the database. Get(key []byte) (value []byte, err error) // Has retrieves whether a key is present in the database. Has(key []byte) (bool, error) }
DatabaseReader wraps the Get and Has method of a backing store for the trie.
type DatabaseWriter ¶
type DatabaseWriter interface { // Put stores the mapping key->value in the database. // Implementations must not hold onto the value bytes, the trie // will reuse the slice across calls to Put. Put(key, value []byte) error }
DatabaseWriter wraps the Put method of a backing store for the trie.
type Iterator ¶
type Iterator struct { Key []byte // Current data key on which the iterator is positioned on Value []byte // Current data value on which the iterator is positioned on Err error // contains filtered or unexported fields }
Iterator is a key-value trie iterator that traverses a Trie.
func NewIterator ¶
func NewIterator(it NodeIterator) *Iterator
NewIterator creates a new key-value iterator from a node iterator
type LeafCallback ¶
LeafCallback is a callback type invoked when a trie operation reaches a leaf node. It's used by state sync and commit to allow handling external references between account and storage tries.
type MissingNodeError ¶
type MissingNodeError struct { NodeHash utils.Hash // hash of the missing node Path []byte // hex-encoded path to the missing node }
MissingNodeError miss node err
func (*MissingNodeError) Error ¶
func (err *MissingNodeError) Error() string
type NodeIterator ¶
type NodeIterator interface { // Next moves the iterator to the next node. If the parameter is false, any child // nodes will be skipped. Next(bool) bool // Error returns the error status of the iterator. Error() error // Hash returns the hash of the current node. Hash() utils.Hash // Parent returns the hash of the parent of the current node. The hash may be the one // grandparent if the immediate parent is an internal node with no hash. Parent() utils.Hash // Path returns the hex-encoded path to the current node. // Callers must not retain references to the return value after calling Next. // For leaf nodes, the last element of the path is the 'terminator symbol' 0x10. Path() []byte // Leaf returns true iff the current node is a leaf node. Leaf() bool // LeafKey returns the key of the leaf. The method panics if the iterator is not // positioned at a leaf. Callers must not retain references to the value after // calling Next. LeafKey() []byte // LeafBlob returns the content of the leaf. The method panics if the iterator // is not positioned at a leaf. Callers must not retain references to the value // after calling Next. LeafBlob() []byte // LeafProof returns the Merkle proof of the leaf. The method panics if the // iterator is not positioned at a leaf. Callers must not retain references // to the value after calling Next. LeafProof() [][]byte }
NodeIterator is an iterator to traverse the trie pre-order.
func NewDifferenceIterator ¶
func NewDifferenceIterator(a, b NodeIterator) (NodeIterator, *int)
NewDifferenceIterator constructs a NodeIterator that iterates over elements in b that are not in a. Returns the iterator, and a pointer to an integer recording the number of nodes seen.
type Sync ¶
type Sync struct {
// contains filtered or unexported fields
}
Sync is the main state trie synchronisation scheduler, which provides yet unknown trie hashes to retrieve, accepts node data associated with said hashes and reconstructs the trie step by step until all is done.
func NewSync ¶
func NewSync(root utils.Hash, database DatabaseReader, callback LeafCallback) *Sync
NewSync creates a new trie data download scheduler.
func (*Sync) AddRawEntry ¶
AddRawEntry schedules the direct retrieval of a state entry that should not be interpreted as a trie node, but rather accepted and stored into the database as is. This method's goal is to support misc state metadata retrievals (e.g. contract code).
func (*Sync) AddSubTrie ¶
AddSubTrie registers a new trie to the sync code, rooted at the designated parent.
func (*Sync) Commit ¶
Commit flushes the data stored in the internal membatch out to persistent storage, returning the number of items written and any occurred error.
type SyncResult ¶
type SyncResult struct { Hash utils.Hash // Hash of the originally unknown trie node Data []byte // Data content of the retrieved node }
SyncResult is a simple list to return missing nodes along with their request hashes.
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
Trie is a Merkle Patricia Trie. The zero value is an empty trie with no database. Use New to create a trie that sits on top of a database.
Trie is not safe for concurrent use.
func New ¶
New creates a trie with an existing root node from db.
If root is the zero hash or the sha3 hash of an empty string, the trie is initially empty and does not require a database. Otherwise, New will panic if db is nil and returns a MissingNodeError if root does not exist in the database. Accessing the trie loads nodes from db on demand.
func NewWithPrefix ¶
func (*Trie) Commit ¶
func (t *Trie) Commit(onleaf LeafCallback) (root utils.Hash, err error)
Commit writes all nodes to the trie's memory database, tracking the internal and external (for account tries) references.
func (*Trie) CommitTo ¶
CommitTo writes all nodes to the given database. Nodes are stored with their sha3 hash as the key.
func (*Trie) Get ¶
Get returns the value for key stored in the trie. The value bytes must not be modified by the caller.
func (*Trie) Hash ¶
Hash returns the root hash of the trie. It does not write to the database and can be used even if the trie doesn't have one.
func (*Trie) NodeIterator ¶
func (t *Trie) NodeIterator(start []byte) NodeIterator
NodeIterator returns an iterator that returns nodes of the trie. Iteration starts at the key after the given start key.
func (*Trie) PrefixIterator ¶
func (t *Trie) PrefixIterator(prefix []byte) NodeIterator
PrefixIterator returns an iterator that returns nodes of the trie which has the prefix path specificed Iteration starts at the key after the given start key.
func (*Trie) SetCacheLimit ¶
SetCacheLimit sets the number of 'cache generations' to keep. A cache generation is created by a call to Commit.
func (*Trie) TryDelete ¶
TryDelete removes any existing value for key from the trie. If a node was not found in the database, a MissingNodeError is returned.
func (*Trie) TryGet ¶
TryGet returns the value for key stored in the trie. The value bytes must not be modified by the caller. If a node was not found in the database, a MissingNodeError is returned.
func (*Trie) TryUpdate ¶
TryUpdate associates key with value in the trie. Subsequent calls to Get will return value. If value has length zero, any existing value is deleted from the trie and calls to Get will return nil.
The value bytes must not be modified by the caller while they are stored in the trie.
If a node was not found in the database, a MissingNodeError is returned.
func (*Trie) Update ¶
Update associates key with value in the trie. Subsequent calls to Get will return value. If value has length zero, any existing value is deleted from the trie and calls to Get will return nil.
The value bytes must not be modified by the caller while they are stored in the trie.
type TrieWarp ¶
type TrieWarp struct {
// contains filtered or unexported fields
}
TrieWarp wraps a trie with key hashing.
func NewTrieWarp ¶
NewTrieWarp creates a trie with an existing root node from a backing database and optional intermediate in-memory node pool.
func (*TrieWarp) Commit ¶
func (t *TrieWarp) Commit(onleaf LeafCallback) (root utils.Hash, err error)
Commit writes all nodes and the secure hash pre-images to the trie's database.
func (*TrieWarp) Get ¶
Get returns the value for key stored in the trie. The value bytes must not be modified by the caller.
func (*TrieWarp) NodeIterator ¶
func (t *TrieWarp) NodeIterator(start []byte) NodeIterator
NodeIterator returns an iterator that returns nodes of the underlying trie.