Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions grovedb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ grovedb-version = { version = "3.0.0", path = "../grovedb-version" }
grovedb-visualize = { version = "3.0.0", path = "../visualize", optional = true }

axum = { version = "=0.7.5", features = ["macros"], optional = true }
bincode = { version = "2.0.0-rc.3" }
bincode = "=2.0.0-rc.3"
blake3 = "1.5.5"
hex = "0.4.3"
indexmap = "2.7.0"
Expand Down Expand Up @@ -88,7 +88,8 @@ grovedbg = [
"axum",
"tower-http",
"zip-extensions",
"tempfile"
"tempfile",
"bincode/serde"
]

[build-dependencies]
Expand Down
207 changes: 88 additions & 119 deletions grovedb/src/debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,24 @@ async fn fetch_with_path_query(
)?))
}

pub(crate) fn dump_proof_grovedbg_stdout(proof: GroveDBProof) {
let grovedbg_proof = proof_to_grovedbg(proof).map_err(|e| e.to_string());
let encoded = grovedbg_proof.and_then(|p| {
bincode::serde::encode_to_vec(p, bincode::config::standard()).map_err(|e| e.to_string())
});

match encoded {
Ok(p) => {
println!("==========GroveDBG proof dump starts after this line==========");
println!("{}", hex::encode(p));
println!("==========GroveDBG proof dump ends before this line===========");
}
Err(e) => {
eprintln!("Unable to dump proof to grovedbg: {e}");
}
}
}

fn query_result_to_grovedbg(
db: &GroveDb,
tx: &Transaction,
Expand Down Expand Up @@ -536,137 +554,51 @@ fn query_item_to_grovedb(item: QueryItem) -> crate::QueryItem {

fn element_to_grovedbg(element: crate::Element) -> grovedbg_types::Element {
match element {
crate::Element::Item(value, element_flags)
| crate::Element::ItemWithBackwardsReferences(value, element_flags) => {
grovedbg_types::Element::Item {
crate::Element::Item(value, element_flags) => grovedbg_types::Element::Item {
value,
element_flags,
},
crate::Element::ItemWithBackwardsReferences(value, element_flags) => {
grovedbg_types::Element::ItemWithBackwardReferences {
value,
element_flags,
}
}
crate::Element::Tree(root_key, element_flags) => grovedbg_types::Element::Subtree {
root_key,

crate::Element::SumItem(value, element_flags) => grovedbg_types::Element::SumItem {
value,
element_flags,
},
crate::Element::Reference(
ReferencePathType::AbsolutePathReference(path),
_,
element_flags,
)
| crate::Element::BidirectionalReference(BidirectionalReference {
forward_reference_path: ReferencePathType::AbsolutePathReference(path),
flags: element_flags,
..
}) => {
grovedbg_types::Element::Reference(grovedbg_types::Reference::AbsolutePathReference {
path,
crate::Element::SumItemWithBackwardsReferences(value, element_flags) => {
grovedbg_types::Element::SumItemWithBackwardReferences {
value,
element_flags,
})
}
}
crate::Element::Reference(
ReferencePathType::UpstreamRootHeightReference(n_keep, path_append),
_,
element_flags,
)
| crate::Element::BidirectionalReference(BidirectionalReference {
forward_reference_path:
ReferencePathType::UpstreamRootHeightReference(n_keep, path_append),
flags: element_flags,
..
}) => grovedbg_types::Element::Reference(
grovedbg_types::Reference::UpstreamRootHeightReference {
n_keep: n_keep.into(),
path_append,
element_flags,
},
),
crate::Element::Reference(
ReferencePathType::UpstreamRootHeightWithParentPathAdditionReference(
n_keep,
path_append,
),
_,
element_flags,
)
| crate::Element::BidirectionalReference(BidirectionalReference {
forward_reference_path:
ReferencePathType::UpstreamRootHeightWithParentPathAdditionReference(
n_keep,
path_append,
),
flags: element_flags,
..
}) => grovedbg_types::Element::Reference(
grovedbg_types::Reference::UpstreamRootHeightWithParentPathAdditionReference {
n_keep: n_keep.into(),
path_append,
element_flags,
},
),
crate::Element::Reference(
ReferencePathType::UpstreamFromElementHeightReference(n_remove, path_append),
_,
element_flags,
)
| crate::Element::BidirectionalReference(BidirectionalReference {
forward_reference_path:
ReferencePathType::UpstreamFromElementHeightReference(n_remove, path_append),
flags: element_flags,
..
}) => grovedbg_types::Element::Reference(
grovedbg_types::Reference::UpstreamFromElementHeightReference {
n_remove: n_remove.into(),
path_append,
element_flags,
},
),
crate::Element::Reference(
ReferencePathType::CousinReference(swap_parent),
_,
element_flags,
)
| crate::Element::BidirectionalReference(BidirectionalReference {
forward_reference_path: ReferencePathType::CousinReference(swap_parent),
flags: element_flags,
..
}) => grovedbg_types::Element::Reference(grovedbg_types::Reference::CousinReference {
swap_parent,
element_flags,
}),
crate::Element::Reference(
ReferencePathType::RemovedCousinReference(swap_parent),
_,
element_flags,
)
| crate::Element::BidirectionalReference(BidirectionalReference {
forward_reference_path: ReferencePathType::RemovedCousinReference(swap_parent),
flags: element_flags,
..
}) => {
grovedbg_types::Element::Reference(grovedbg_types::Reference::RemovedCousinReference {
swap_parent,

crate::Element::Reference(reference, _, element_flags) => {
grovedbg_types::Element::Reference {
reference_path: reference_path_to_grovedbg(reference),
element_flags,
})
}
}
crate::Element::Reference(
ReferencePathType::SiblingReference(sibling_key),
_,
element_flags,
)
| crate::Element::BidirectionalReference(BidirectionalReference {
forward_reference_path: ReferencePathType::SiblingReference(sibling_key),
flags: element_flags,
crate::Element::BidirectionalReference(BidirectionalReference {
forward_reference_path,
flags,
backward_reference_slot,
cascade_on_update,
..
}) => grovedbg_types::Element::Reference(grovedbg_types::Reference::SiblingReference {
sibling_key,
}) => grovedbg_types::Element::BidirectionalReference {
reference_path: reference_path_to_grovedbg(forward_reference_path),
element_flags: flags,
slot_idx: backward_reference_slot as u8,
cascade_on_update,
},

crate::Element::Tree(root_key, element_flags) => grovedbg_types::Element::Subtree {
root_key,
element_flags,
}),
crate::Element::SumItem(value, element_flags)
| crate::Element::SumItemWithBackwardsReferences(value, element_flags) => {
grovedbg_types::Element::SumItem {
value,
element_flags,
}
}
},
crate::Element::SumTree(root_key, sum, element_flags) => grovedbg_types::Element::Sumtree {
root_key,
sum,
Expand Down Expand Up @@ -697,6 +629,43 @@ fn element_to_grovedbg(element: crate::Element) -> grovedbg_types::Element {
}
}

fn reference_path_to_grovedbg(reference: ReferencePathType) -> grovedbg_types::ReferencePath {
match reference {
ReferencePathType::AbsolutePathReference(path) => {
grovedbg_types::ReferencePath::AbsolutePathReference { path }
}

ReferencePathType::UpstreamRootHeightReference(n_keep, path_append) => {
grovedbg_types::ReferencePath::UpstreamRootHeightReference {
n_keep: n_keep.into(),
path_append,
}
}
ReferencePathType::UpstreamRootHeightWithParentPathAdditionReference(
n_keep,
path_append,
) => grovedbg_types::ReferencePath::UpstreamRootHeightWithParentPathAdditionReference {
n_keep: n_keep.into(),
path_append,
},
ReferencePathType::UpstreamFromElementHeightReference(n_remove, path_append) => {
grovedbg_types::ReferencePath::UpstreamFromElementHeightReference {
n_remove: n_remove.into(),
path_append,
}
}
ReferencePathType::CousinReference(swap_parent) => {
grovedbg_types::ReferencePath::CousinReference { swap_parent }
}
ReferencePathType::RemovedCousinReference(swap_parent) => {
grovedbg_types::ReferencePath::RemovedCousinReference { swap_parent }
}
ReferencePathType::SiblingReference(sibling_key) => {
grovedbg_types::ReferencePath::SiblingReference { sibling_key }
}
}
}

fn node_to_update(
path: Path,
NodeDbg {
Expand Down
2 changes: 1 addition & 1 deletion grovedb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ use std::sync::Arc;
use std::{collections::HashMap, option::Option::None, path::Path};

#[cfg(feature = "minimal")]
use bidirectional_references::BidirectionalReference;
pub use bidirectional_references::BidirectionalReference;
#[cfg(feature = "grovedbg")]
use debugger::start_visualizer;
#[cfg(any(feature = "minimal", feature = "verify"))]
Expand Down
6 changes: 3 additions & 3 deletions grovedb/src/operations/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ impl Default for ProveOptions {
}
}

#[derive(Encode, Decode)]
#[derive(Clone, Encode, Decode)]
pub struct LayerProof {
pub merk_proof: Vec<u8>,
pub lower_layers: BTreeMap<Key, LayerProof>,
}

#[derive(Encode, Decode)]
#[derive(Clone, Encode, Decode)]
pub enum GroveDBProof {
V0(GroveDBProofV0),
}
Expand Down Expand Up @@ -176,7 +176,7 @@ impl GroveDBProof {
}
}

#[derive(Encode, Decode)]
#[derive(Clone, Encode, Decode)]
pub struct GroveDBProofV0 {
pub root_layer: LayerProof,
pub prove_options: ProveOptions,
Expand Down
40 changes: 24 additions & 16 deletions grovedbg-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,51 +61,37 @@ pub struct NodeUpdate {

#[serde_as]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum Reference {
pub enum ReferencePath {
AbsolutePathReference {
#[serde_as(as = "Vec<Base64>")]
path: Path,
#[serde_as(as = "Option<Base64>")]
element_flags: Option<Vec<u8>>,
},
UpstreamRootHeightReference {
n_keep: u32,
#[serde_as(as = "Vec<Base64>")]
path_append: Vec<PathSegment>,
#[serde_as(as = "Option<Base64>")]
element_flags: Option<Vec<u8>>,
},
UpstreamRootHeightWithParentPathAdditionReference {
n_keep: u32,
#[serde_as(as = "Vec<Base64>")]
path_append: Vec<PathSegment>,
#[serde_as(as = "Option<Base64>")]
element_flags: Option<Vec<u8>>,
},
UpstreamFromElementHeightReference {
n_remove: u32,
#[serde_as(as = "Vec<Base64>")]
path_append: Vec<PathSegment>,
#[serde_as(as = "Option<Base64>")]
element_flags: Option<Vec<u8>>,
},
CousinReference {
#[serde_as(as = "Base64")]
swap_parent: PathSegment,
#[serde_as(as = "Option<Base64>")]
element_flags: Option<Vec<u8>>,
},
RemovedCousinReference {
#[serde_as(as = "Vec<Base64>")]
swap_parent: Vec<PathSegment>,
#[serde_as(as = "Option<Base64>")]
element_flags: Option<Vec<u8>>,
},
SiblingReference {
#[serde_as(as = "Base64")]
sibling_key: Key,
#[serde_as(as = "Option<Base64>")]
element_flags: Option<Vec<u8>>,
},
}

Expand Down Expand Up @@ -153,12 +139,34 @@ pub enum Element {
#[serde_as(as = "Option<Base64>")]
element_flags: Option<Vec<u8>>,
},
ItemWithBackwardReferences {
#[serde_as(as = "Base64")]
value: Vec<u8>,
#[serde_as(as = "Option<Base64>")]
element_flags: Option<Vec<u8>>,
},
SumItem {
value: i64,
#[serde_as(as = "Option<Base64>")]
element_flags: Option<Vec<u8>>,
},
Reference(Reference),
SumItemWithBackwardReferences {
value: i64,
#[serde_as(as = "Option<Base64>")]
element_flags: Option<Vec<u8>>,
},
Reference {
reference_path: ReferencePath,
#[serde_as(as = "Option<Base64>")]
element_flags: Option<Vec<u8>>,
},
BidirectionalReference {
reference_path: ReferencePath,
#[serde_as(as = "Option<Base64>")]
element_flags: Option<Vec<u8>>,
slot_idx: u8,
cascade_on_update: bool,
},
}

#[serde_as]
Expand Down