[−][src]Crate exonum_merkledb
A module that provides interfaces to work with persisted blockchain data.
See also the documentation page on storage.
Database
A Database
is a container for data persistence. Internally, a Database
is
a collection of named key-value stores (aka column families)
with reading isolation and atomic writes. The database is assumed to be embedded,
that is, the Exonum process has exclusive access to the DB during blockchain operation.
You can interact with the Database
from multiple threads by cloning its instance.
Exonum provides two database types: RocksDB
and TemporaryDB
.
Snapshot and Fork
Snapshots and forks facilitate access to the database.
If you need to read the data, you can create a Snapshot
using the snapshot
method
of the Database
instance. Snapshots provide read isolation, so you are guaranteed to work
with consistent values even if the data in the database changes between reads. Snapshot
provides all the necessary methods for reading data from the database, so &Snapshot
is used as a storage view for creating a read-only representation of the indices.
If you need to make changes to the database, you need to create a Fork
using
the fork
method of the Database
. Like Snapshot
, Fork
provides read isolation,
but also allows creating a sequence of changes to the database that are specified
as a Patch
. A patch can be atomically merge
d into a database. Different threads
may call merge
concurrently.
BinaryKey
and BinaryValue
traits
If you need to use your own data types as keys or values in the storage, you need to implement
the BinaryKey
or BinaryValue
traits respectively. These traits have already been
implemented for most standard types.
Indices
Indices are structures representing data collections stored in the database. This concept is similar to tables in relational databases. The interfaces of the indices are similar to ordinary collections (like arrays, maps and sets).
Each index occupies a certain set of keys in a single column family of the Database
.
On the other hand, multiple indices can be stored in the same column family, provided
that their key spaces do not intersect. Isolation is commonly achieved with the help
of Group
s or keyed IndexAddress
es.
Merkelized indices can generate cryptographic proofs about inclusion of entries. Having such a proof, an external client may verify locally that the received data was authorized by the blockchain validators, without having to replicate the entire blockchain contents.
Exonum provides the following index types:
Entry
is a specific index that stores only one value. Useful for global values, such as configuration. Similar to a combination ofBox
andOption
.ListIndex
is a list of items stored in a sequential order. Similar toVec
.SparseListIndex
is a list of items stored in a sequential order. Similar toListIndex
, but may contain indices without elements.MapIndex
is a map of keys and values. Similar toBTreeMap
.ProofListIndex
is a Merkelized version ofListIndex
that supports cryptographic proofs of existence and is implemented as a Merkle tree.ProofMapIndex
is a Merkelized version ofMapIndex
that supports cryptographic proofs of existence and is implemented as a binary Merkle Patricia tree.KeySetIndex
andValueSetIndex
are sets of items, similar toBTreeSet
andHashSet
accordingly.
Re-exports
pub use self::key_set_index::KeySetIndex; |
pub use self::list_index::ListIndex; |
pub use self::map_index::MapIndex; |
pub use self::sparse_list_index::SparseListIndex; |
pub use self::value_set_index::ValueSetIndex; |
pub use self::proof_list_index::ListProof; |
pub use self::proof_list_index::ProofListIndex; |
pub use self::proof_map_index::MapProof; |
pub use self::proof_map_index::ProofMapIndex; |
pub use self::proof_map_index::RawProofMapIndex; |
Modules
access | High-level access to database. |
key_set_index | An implementation of a set for items that utilize the |
list_index | An implementation of an array list of items. |
macros | Macros useful for work with types that implement |
map_index | An implementation of a key-value map. |
proof_list_index | An implementation of a Merkelized version of an array list (Merkle tree). |
proof_map_index | An implementation of a Merkelized version of a map (Merkle Patricia tree). |
proto | Module of the rust-protobuf generated files. |
sparse_list_index | An implementation of an array list of items with spaces. |
validation | Validation helpers for index names. |
value_set_index | An implementation of a set of items that utilize the |
Macros
impl_binary_key_for_binary_value | Implements |
impl_object_hash_for_binary_value | Implement |
Structs
Changes | Map containing changes with a corresponding key. |
ChangesIterator | Iterator over the |
DbOptions | Options for the database. |
Entry | An index that may only contain one element. |
Error | The error type for I/O operations with storage. |
Fork | A combination of a database snapshot and a sequence of changes on top of it. |
Group | Group of indexes distinguished by a prefix. |
IndexAddress | Represents address of the index in the database. |
Lazy | Lazily initialized object in the database. |
Patch | A set of serial changes that should be applied to a storage atomically. |
PatchIterator | Iterator over the |
ReadonlyFork | Readonly wrapper for a |
RocksDB | Database implementation on top of |
TemporaryDB | Wrapper over the |
View | Represents current view of the database by specified |
Enums
Change | An enum that represents a type of change made to some key in the storage. |
HashTag |
|
IndexType | Type of an index supported by Exonum. |
ValidationError | Errors that can occur while validating a |
Traits
AsReadonly | Converts index access to a readonly presentation. The conversion operation is cheap. |
BinaryKey | A type that can be (de)serialized as a key in the blockchain storage. |
BinaryValue | A type that can be (de)serialized as a value in the blockchain storage. |
Database | Low-level storage backend implementing a collection of named key-value stores (aka column families). |
Iterator | A trait that defines a streaming iterator over storage view entries. Unlike
the standard |
ObjectHash | A common trait for the ability to compute a unique hash. |
Snapshot | A read-only snapshot of a storage backend. |
Functions
root_hash | Computes a Merkle root hash for a the given list of hashes. |
Type Definitions
Iter | A generalized iterator over the storage views. |
Result | A specialized |