Skip to content

Commit

Permalink
refactor: suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ogabrielides committed Dec 30, 2024
1 parent 1700991 commit 72cd05b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion grovedb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ pub use crate::error::Error;
#[cfg(feature = "full")]
use crate::operations::proof::util::hex_to_ascii;
#[cfg(feature = "full")]
use crate::replication::replication_utils::util_encode_vec_ops;
use crate::replication::utils::encode_vec_ops;

Check warning on line 222 in grovedb/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `crate::replication::utils::encode_vec_ops`

warning: unused import: `crate::replication::utils::encode_vec_ops` --> grovedb/src/lib.rs:222:5 | 222 | use crate::replication::utils::encode_vec_ops; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#[cfg(feature = "full")]
use crate::util::{root_merk_optional_tx, storage_context_optional_tx};
#[cfg(feature = "full")]
Expand Down
14 changes: 7 additions & 7 deletions grovedb/src/replication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl GroveDb {

let root_app_hash = self.root_hash(transaction, grove_version).value?;
let (chunk_prefix, root_key, is_sum_tree, chunk_id) =
replication_utils::decode_global_chunk_id(global_chunk_id, &root_app_hash)?;
utils::decode_global_chunk_id(global_chunk_id, &root_app_hash)?;

// TODO: Refactor this by writing fetch_chunk_inner (as only merk constructor
// and type are different)
Expand Down Expand Up @@ -125,7 +125,7 @@ impl GroveDb {
e
))
})?;
let op_bytes = replication_utils::util_encode_vec_ops(chunk).map_err(|e| {
let op_bytes = utils::encode_vec_ops(chunk).map_err(|e| {
Error::CorruptedData(format!(
"failed to encode chunk ops:{} with:{}",
hex::encode(chunk_prefix),
Expand Down Expand Up @@ -170,7 +170,7 @@ impl GroveDb {
e
))
})?;
let op_bytes = replication_utils::util_encode_vec_ops(chunk).map_err(|e| {
let op_bytes = utils::encode_vec_ops(chunk).map_err(|e| {
Error::CorruptedData(format!(
"failed to encode chunk ops:{} with:{}",
hex::encode(chunk_prefix),
Expand Down Expand Up @@ -238,7 +238,7 @@ impl GroveDb {

println!(
" starting:{:?}...",
replication_utils::path_to_string(&[])
utils::path_to_string(&[])
);

let root_prefix = [0u8; 32];
Expand All @@ -258,7 +258,7 @@ impl GroveDb {
}
}

pub(crate) mod replication_utils {
pub(crate) mod utils {
use grovedb_merk::{
ed::Encode,
proofs::{Decoder, Op},
Expand Down Expand Up @@ -419,7 +419,7 @@ pub(crate) mod replication_utils {
/// # Returns
/// - `Ok(Vec<u8>)`: A byte vector representing the encoded operations.
/// - `Err(Error)`: An error if the encoding process fails.
pub fn util_encode_vec_ops(chunk: Vec<Op>) -> Result<Vec<u8>, Error> {
pub fn encode_vec_ops(chunk: Vec<Op>) -> Result<Vec<u8>, Error> {
let mut res = vec![];
for op in chunk {
op.encode_into(&mut res)
Expand All @@ -436,7 +436,7 @@ pub(crate) mod replication_utils {
/// # Returns
/// - `Ok(Vec<Op>)`: A vector of decoded `Op` operations.
/// - `Err(Error)`: An error if the decoding process fails.
pub fn util_decode_vec_ops(chunk: Vec<u8>) -> Result<Vec<Op>, Error> {
pub fn decode_vec_ops(chunk: Vec<u8>) -> Result<Vec<Op>, Error> {
let decoder = Decoder::new(&chunk);
let mut res = vec![];
for op in decoder {
Expand Down
19 changes: 7 additions & 12 deletions grovedb/src/replication/state_sync_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use grovedb_storage::{
use grovedb_version::version::GroveVersion;

use super::{
replication_utils::{encode_global_chunk_id, path_to_string, util_decode_vec_ops},
utils::{encode_global_chunk_id, path_to_string, decode_vec_ops},
CURRENT_STATE_SYNC_VERSION,
};
use crate::{replication, Element, Error, GroveDb, Transaction};
Expand Down Expand Up @@ -100,7 +100,7 @@ impl<'db> SubtreeStateSyncInfo<'db> {
}
self.pending_chunks.remove(chunk_id);
if !chunk_data.is_empty() {
match util_decode_vec_ops(chunk_data) {
match decode_vec_ops(chunk_data) {
Ok(ops) => {
match self.restorer.process_chunk(chunk_id, ops, grove_version) {
Ok(next_chunk_ids) => {
Expand Down Expand Up @@ -209,13 +209,9 @@ impl<'db> MultiStateSyncSession<'db> {
chunk_prefix: [u8; 32],
grove_version: &GroveVersion,
) -> Result<Vec<u8>, Error> {
// SAFETY: we get an immutable reference of a transaction that stays behind
// `Pin` so this reference shall remain valid for the whole session
// object lifetime.
let transaction_ref: &'db Transaction<'db> = unsafe {
let tx: &mut Transaction<'db> =
&mut Pin::into_inner_unchecked(self.as_mut()).transaction;
&*(tx as *mut _)
let tx: &Transaction<'db> = &self.as_ref().transaction;
&*(tx as *const _)
};

if let Ok((merk, root_key, is_sum_tree)) =
Expand Down Expand Up @@ -316,7 +312,7 @@ impl<'db> MultiStateSyncSession<'db> {
let mut next_chunk_ids = vec![];

let (chunk_prefix, _, _, chunk_id) =
replication::replication_utils::decode_global_chunk_id(
replication::utils::decode_global_chunk_id(
global_chunk_id,
&self.app_hash,
)?;
Expand Down Expand Up @@ -431,9 +427,8 @@ impl<'db> MultiStateSyncSession<'db> {
grove_version: &GroveVersion,
) -> Result<SubtreesMetadata, Error> {
let transaction_ref: &'db Transaction<'db> = unsafe {
let tx: &mut Transaction<'db> =
&mut Pin::into_inner_unchecked(self.as_mut()).transaction;
&*(tx as *mut _)
let tx: &Transaction<'db> = &self.as_ref().transaction;
&*(tx as *const _)
};
let subtree_path: Vec<&[u8]> = path_vec.iter().map(|vec| vec.as_slice()).collect();
let path: &[&[u8]] = &subtree_path;
Expand Down

0 comments on commit 72cd05b

Please sign in to comment.