Dash Core Group Introduces: GroveDB
Tags: webdev, programming, web3, opensource
Published: 2023-06-28 14:23:50

We're happy to introduce you one of the most powerful tools for building web3 infrastructure, GroveDB. 
GroveDB stands as the pioneering database that empowers cryptographic proofs for intricate queries.

Originally designed for Dash Platform, GroveDB boasts seamless integration capabilities with other applications seeking similar functionality.

So, how can Grove DB be helpful?
This is a list of Grove DB features:

**Query proofs** - GroveDB holds the distinction of being the first-ever database to offer support for proofs encompassing queries of greater complexity beyond simple single-key retrievals.

**Secondary indexes** - With GroveDB, you have the power to effortlessly create indexes on any field, including unique indexes and compound indexes. This flexible feature allows for efficient data organization and retrieval within the database.

**Mutable and immutable data storage** - GroveDB comes equipped with built-in functionality that seamlessly supports both types of indexes within a single database. This integrated capability ensures a comprehensive and versatile solution for efficient data management and retrieval.

**Inclusion and absence proofs** - 
GroveDB revolutionizes data verification by introducing Merkle proofs, enabling the capability to verify the presence or absence of items with utmost accuracy. This feature enhances data integrity and security within the database environment.

**Operation costs** - Gain valuable insights into operation costs with GroveDB, allowing you to accurately assess and estimate costs before executing them. This invaluable feature empowers users to make informed decisions and optimize resource allocation within their database operations.

**ACID compliancy** - Experience the benefits of ACID (Atomicity, Consistency, Isolation, Durability) compliance with GroveDB. This robust database ensures data integrity, reliability, and transactional consistency, providing a solid foundation for reliable and secure data management.

In general, GroveDB offers even greater functionality compared to other databases.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/94o08xxveb4t7qph7go1.png)

### Architecture 
Insertion and deletion operations function as expected in GroveDB, updating the relevant subtrees and providing appropriate proofs of membership or non-membership.

#### Tree Structures
Instead of using separate authenticated data structures, GroveDB adopts a unified hierarchical authenticated data structure based on the concept of Database Outsourcing with Hierarchical Authenticated Data Structures. Elements within the structure represent the most fundamental units and can be represented in various forms, such as items, item references, trees, trees with items, or trees with item references. An element encompasses an item, a reference to an object, or a subtree.

The tree implementation in GroveDB is based on our modified version of Merk, with custom patches for enhanced compatibility with GroveDB. Merk stands out for its AVL tree structure, where intermediate nodes contain key/value pairs. Each node includes a third hash, called kv_hash, in addition to the hashes of its left and right children. The _kv_hash_ is calculated as _kv_hash=H(key,value)_, and the node hash is computed as _H(kv_hash, left_child_hash, right_child_hash)_. Merk utilizes Blake2B hashing, while rs-merkle employs SHA256.

#### Storage
RocksDB, a key-value store originally derived from LevelDB and further developed by Facebook, serves as the underlying storage engine for GroveDB. We selected RocksDB due to its exceptional performance, maturity, and compatibility with our technology stack. Merk itself is built on top of RocksDB.

GroveDB incorporates three types of storage: auxiliary storage, metadata storage, and tree root storage. Auxiliary storage stores plain key-value data that is not utilized in the consensus process. Metadata storage holds information beyond the scope of GroveDB usage and does not have any prefixes or association with subtrees; it exists at a higher level. Tree root storage, on the other hand, is responsible for storing subtrees.

A database transaction in GroveDB wraps around the OptimisticTransactionDB primitive provided by RocksDB. An optimistic transaction operates under the assumption that conflicts will be infrequent, which are detected during the commit phase. This differs from the pessimistic model that relies on locks.

### Setting up

- Install [rustup](https://www.rust-lang.org/tools/install) using your preferred method.

- Rust nightly is required to build, so make you are using the correct version.


`rustup install nightly`
                    
- Clone the repo and navigate to the main directory:


`git clone https://github.com/dashevo/grovedb.git && cd grovedb`
                    
- From here we can build


`cargo build`