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

chore(drive): log grovedb operations #1446

Merged
merged 4 commits into from
Oct 6, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ pub(crate) fn fetch_documents_for_transitions_knowing_contract_id_and_document_t
));
};

let contract_fetch_info = contract_fetch_info;

let Some(document_type) = contract_fetch_info
.contract
.document_type_optional_for_name(document_type_name)
Expand Down
1 change: 1 addition & 0 deletions packages/rs-drive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,5 @@ full = [
"rust_decimal_macros",
"lazy_static",
]
grovedb_operations_logging = []
verify = ["grovedb/verify", "grovedb-costs"]
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use grovedb::batch::{BatchApplyOptions, GroveDbOp};
use grovedb::TransactionArg;
use grovedb_costs::storage_cost::removal::StorageRemovedBytes::BasicStorageRemoval;
use grovedb_costs::storage_cost::transition::OperationStorageTransitionType;
use tracing::Level;

impl Drive {
/// Applies the given groveDB operations batch and gets and passes the costs to `push_drive_operation_result`.
Expand Down Expand Up @@ -42,6 +43,15 @@ impl Drive {
}
}

// Clone ops only if we log them
#[cfg(feature = "grovedb_operations_logging")]
let maybe_ops_for_logs = if tracing::event_enabled!(target: "grovedb_operations", Level::TRACE)
{
Some(ops.clone())
} else {
None
};

let cost_context = self.grove.apply_batch_with_element_flags_update(
ops.operations,
Some(BatchApplyOptions {
Expand Down Expand Up @@ -140,6 +150,26 @@ impl Drive {
},
transaction,
);

#[cfg(feature = "grovedb_operations_logging")]
if tracing::event_enabled!(target: "grovedb_operations", Level::TRACE)
&& cost_context.value.is_ok()
{
let root_hash = self
.grove
.root_hash(transaction)
.unwrap()
.map_err(Error::GroveDB)?;

tracing::trace!(
target = "grovedb_operations",
ops = ?maybe_ops_for_logs.unwrap(),
root_hash = ?root_hash,
is_transactional = transaction.is_some(),
"grovedb batch applied",
);
}

push_drive_operation_result(cost_context, drive_operations)
}
}
34 changes: 32 additions & 2 deletions packages/rs-drive/src/drive/grove_operations/grove_clear/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::error::Error;
use grovedb::operations::delete::ClearOptions;
use grovedb::TransactionArg;
use grovedb_path::SubtreePath;
use tracing::Level;

impl Drive {
/// Pushes the `OperationCost` of deleting an element in groveDB to `drive_operations`.
Expand All @@ -16,10 +17,39 @@ impl Drive {
allow_deleting_subtrees: false,
trying_to_clear_with_subtrees_returns_error: false,
};

#[cfg(feature = "grovedb_operations_logging")]
let maybe_path_for_logs = if tracing::event_enabled!(target: "grovedb_operations", Level::TRACE)
{
Some(path.clone())
} else {
None
};

// we will always return true if there is no error when we don't check for subtrees
self.grove
let result = self
.grove
.clear_subtree(path, Some(options), transaction)
.map_err(Error::GroveDB)
.map(|_| ())
.map(|_| ());

#[cfg(feature = "grovedb_operations_logging")]
if tracing::event_enabled!(target: "grovedb_operations", Level::TRACE) && result.is_ok() {
let root_hash = self
.grove
.root_hash(transaction)
.unwrap()
.map_err(Error::GroveDB)?;

tracing::trace!(
target = "grovedb_operations",
path = ?maybe_path_for_logs.unwrap().to_vec(),
shumkov marked this conversation as resolved.
Show resolved Hide resolved
root_hash = ?root_hash,
shumkov marked this conversation as resolved.
Show resolved Hide resolved
is_transactional = transaction.is_some(),
"grovedb clear",
);
}

result
}
}
Loading