Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: state sync optimization #346

Merged
merged 10 commits into from
Jan 6, 2025
Prev Previous commit
Next Next commit
fmt
  • Loading branch information
ogabrielides committed Jan 3, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 29c49be13a0b0cced142da0fdab97e6a361387c4
27 changes: 17 additions & 10 deletions grovedb/src/replication/state_sync_session.rs
Original file line number Diff line number Diff line change
@@ -200,25 +200,31 @@ impl<'db> MultiStateSyncSession<'db> {
unsafe { Pin::into_inner_unchecked(self) }.transaction
}

/// Adds synchronization information for a subtree into the current synchronization session.
/// Adds synchronization information for a subtree into the current
/// synchronization session.
///
/// This function interacts with a `GroveDb` database to open a Merk tree at the specified path,
/// calculate and verify its cryptographic hashes, and update the session state with the relevant
/// synchronization information. The function generates and returns the global chunk ID for
/// This function interacts with a `GroveDb` database to open a Merk tree at
/// the specified path, calculate and verify its cryptographic hashes,
/// and update the session state with the relevant synchronization
/// information. The function generates and returns the global chunk ID for
/// the subtree.
///
/// # Parameters
/// - `self`: A pinned, boxed instance of the `MultiStateSyncSession`.
/// - `db`: A reference to the `GroveDb` instance.
/// - `path`: The path to the subtree as a `SubtreePath`.
/// - `hash`: The expected cryptographic hash of the subtree.
/// - `actual_hash`: An optional actual cryptographic hash to compare against the expected hash.
/// - `chunk_prefix`: A 32-byte prefix used for identifying chunks in the synchronization process.
/// - `actual_hash`: An optional actual cryptographic hash to compare
/// against the expected hash.
/// - `chunk_prefix`: A 32-byte prefix used for identifying chunks in the
/// synchronization process.
/// - `grove_version`: The GroveDB version to use for processing.
///
/// # Returns
/// - `Ok(Vec<u8>)`: On success, returns the encoded global chunk ID for the subtree.
/// - `Err(Error)`: If the Merk tree cannot be opened or synchronization information cannot be added.
/// - `Ok(Vec<u8>)`: On success, returns the encoded global chunk ID for the
/// subtree.
/// - `Err(Error)`: If the Merk tree cannot be opened or synchronization
/// information cannot be added.
///
/// # Errors
/// This function returns an error if:
@@ -227,8 +233,9 @@ impl<'db> MultiStateSyncSession<'db> {
/// - Internal errors occur during processing.
///
/// # Safety
/// - This function uses unsafe code to create a reference to the transaction.
/// Ensure that the transaction is properly managed and the lifetime guarantees are respected.
/// - This function uses unsafe code to create a reference to the
/// transaction. Ensure that the transaction is properly managed and the
/// lifetime guarantees are respected.
pub fn add_subtree_sync_info<'b, B: AsRef<[u8]>>(
self: &mut Pin<Box<MultiStateSyncSession<'db>>>,
db: &'db GroveDb,
Loading