Skip to content

Commit

Permalink
Merge pull request #315 from dashpay/develop
Browse files Browse the repository at this point in the history
chore: fast forward merge develop into master
  • Loading branch information
QuantumExplorer authored Jul 12, 2024
2 parents 48e35dc + 8ada131 commit ad0dc84
Show file tree
Hide file tree
Showing 153 changed files with 26,130 additions and 16,902 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/grovedb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ jobs:
access_token: ${{ github.token }}

- uses: actions/checkout@v2
with:
submodules: recursive

- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-unknown-unknown

- name: Enable Rust cache
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: "false"

- name: Setup Trunk
uses: jetli/[email protected]

- run: cargo test --workspace --all-features

Expand All @@ -42,16 +50,24 @@ jobs:

- name: Check out repo
uses: actions/checkout@v2
with:
submodules: recursive

- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
default: true
components: clippy
target: wasm32-unknown-unknown

- name: Enable Rust cache
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: "false"

- name: Setup Trunk
uses: jetli/[email protected]

- uses: actions-rs/clippy-check@v1
with:
Expand All @@ -78,6 +94,8 @@ jobs:

- name: Enable Rust cache
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: "false"

- run: exit `cargo +nightly fmt --check | wc -l`

Expand All @@ -100,6 +118,8 @@ jobs:

- name: Enable Rust cache
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: "false"

- run: cargo check

Expand Down
64 changes: 0 additions & 64 deletions .github/workflows/nodejs.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "grovedb/grovedbg"]
path = grovedb/grovedbg
url = https://github.com/dashpay/grovedbg
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[workspace]
resolver = "2"
exclude = ["grovedb/grovedbg"]
members = [
"costs",
"grovedb",
Expand All @@ -7,4 +9,6 @@ members = [
"storage",
"visualize",
"path",
"grovedbg-types",
"grovedb-version"
]
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,24 @@ From here we can build:

```cargo build```

## grovedbg

There is a work in progress implementation of a debugger layer for GroveDB. To use this library with
these capabilities enabled one needs to set a dependency with `grovedbg` feature.

At build time this requires two environment dependencies:
1. `wasm32-unknown-unknown` Rust toolchain;
2. [trunk](https://trunkrs.dev/) utility.

Then, to launch visualizer tool to observe the database structure inside of your browser on a port,
let's say 10000, the following snippet should do:

```rust
let db = Arc::new(GroveDb::open("db").unwrap());
db.start_visualzier(10000);
```

Just remember to use Arc because the HTTP server might outlast the GroveDB instance.

## Performance

Expand Down
6 changes: 3 additions & 3 deletions costs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grovedb-costs"
version = "1.0.0-rc.1"
version = "1.0.0-rc.2"
edition = "2021"
license = "MIT"
description = "Costs extension crate for GroveDB"
Expand All @@ -10,6 +10,6 @@ repository = "https://github.com/dashpay/grovedb"


[dependencies]
thiserror = "1.0.30"
thiserror = "1.0.59"
intmap = "2.0.0"
integer-encoding = "3.0.3"
integer-encoding = "4.0.0"
5 changes: 5 additions & 0 deletions costs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ pub struct OperationCost {
}

impl OperationCost {
/// Is Nothing
pub fn is_nothing(&self) -> bool {
self == &Self::default()
}

/// Helper function to build default `OperationCost` with different
/// `seek_count`.
pub fn with_seek_count(seek_count: u16) -> Self {
Expand Down
9 changes: 2 additions & 7 deletions costs/src/storage_cost/removal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,17 @@ pub const UNKNOWN_EPOCH: u64 = u64::MAX;
pub type StorageRemovalPerEpochByIdentifier = BTreeMap<Identifier, IntMap<u32>>;

/// Removal bytes
#[derive(Debug, PartialEq, Clone, Eq)]
#[derive(Debug, PartialEq, Clone, Eq, Default)]
pub enum StorageRemovedBytes {
/// No storage removal
#[default]
NoStorageRemoval,
/// Basic storage removal
BasicStorageRemoval(u32),
/// Storage removal is given as sections
SectionedStorageRemoval(StorageRemovalPerEpochByIdentifier),
}

impl Default for StorageRemovedBytes {
fn default() -> Self {
NoStorageRemoval
}
}

impl Add for StorageRemovedBytes {
type Output = Self;

Expand Down
14 changes: 14 additions & 0 deletions grovedb-version/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "grovedb-version"
authors = ["Samuel Westrich <[email protected]>"]
description = "Versioning library for Platform"
version = "1.0.0-rc.2"
edition = "2021"
license = "MIT"

[dependencies]
thiserror = { version = "1.0.59" }
versioned-feature-core = { git = "https://github.com/dashpay/versioned-feature-core", version = "1.0.0" }

[features]
mock-versions = []
25 changes: 25 additions & 0 deletions grovedb-version/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use thiserror::Error;
use versioned_feature_core::FeatureVersion;

#[derive(Error, Debug)]
pub enum GroveVersionError {
/// Expected some specific versions
#[error("grove unknown version on {method}, received: {received}")]
UnknownVersionMismatch {
/// method
method: String,
/// the allowed versions for this method
known_versions: Vec<FeatureVersion>,
/// requested core height
received: FeatureVersion,
},

/// Expected some specific versions
#[error("{method} not active for grove version")]
VersionNotActive {
/// method
method: String,
/// the allowed versions for this method
known_versions: Vec<FeatureVersion>,
},
}
106 changes: 106 additions & 0 deletions grovedb-version/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
use crate::version::GroveVersion;

pub mod error;
pub mod version;

#[macro_export]
macro_rules! check_grovedb_v0_with_cost {
($method:expr, $version:expr) => {{
const EXPECTED_VERSION: u16 = 0;
if $version != EXPECTED_VERSION {
return Err(GroveVersionError::UnknownVersionMismatch {
method: $method.to_string(),
known_versions: vec![EXPECTED_VERSION],
received: $version,
}
.into())
.wrap_with_cost(OperationCost::default());
}
}};
}

#[macro_export]
macro_rules! check_grovedb_v0 {
($method:expr, $version:expr) => {{
const EXPECTED_VERSION: u16 = 0;
if $version != EXPECTED_VERSION {
return Err(GroveVersionError::UnknownVersionMismatch {
method: $method.to_string(),
known_versions: vec![EXPECTED_VERSION],
received: $version,
}
.into());
}
}};
}

#[macro_export]
macro_rules! check_merk_v0_with_cost {
($method:expr, $version:expr) => {{
const EXPECTED_VERSION: u16 = 0;
if $version != EXPECTED_VERSION {
return Err(GroveVersionError::UnknownVersionMismatch {
method: $method.to_string(),
known_versions: vec![EXPECTED_VERSION],
received: $version,
}
.into())
.wrap_with_cost(OperationCost::default());
}
}};
}

#[macro_export]
macro_rules! check_merk_v0 {
($method:expr, $version:expr) => {{
const EXPECTED_VERSION: u16 = 0;
if $version != EXPECTED_VERSION {
return Err(GroveVersionError::UnknownVersionMismatch {
method: $method.to_string(),
known_versions: vec![EXPECTED_VERSION],
received: $version,
}
.into());
}
}};
}

pub trait TryFromVersioned<T>: Sized {
/// The type returned in the event of a conversion error.
type Error;

/// Performs the conversion.
fn try_from_versioned(value: T, grove_version: &GroveVersion) -> Result<Self, Self::Error>;
}

pub trait TryIntoVersioned<T>: Sized {
/// The type returned in the event of a conversion error.
type Error;

/// Performs the conversion.
fn try_into_versioned(self, grove_version: &GroveVersion) -> Result<T, Self::Error>;
}

impl<T, U> TryIntoVersioned<U> for T
where
U: TryFromVersioned<T>,
{
type Error = U::Error;

#[inline]
fn try_into_versioned(self, grove_version: &GroveVersion) -> Result<U, U::Error> {
U::try_from_versioned(self, grove_version)
}
}

impl<T, U> TryFromVersioned<U> for T
where
T: TryFrom<U>,
{
type Error = T::Error;

#[inline]
fn try_from_versioned(value: U, _grove_version: &GroveVersion) -> Result<Self, Self::Error> {
T::try_from(value)
}
}
Loading

0 comments on commit ad0dc84

Please sign in to comment.