From bded523fd23481ef1a69a91744f723955e2f97d0 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Sat, 30 Sep 2023 16:59:33 +0300 Subject: [PATCH 1/4] chore(drive): log grovedb operations --- .../v0/mod.rs | 24 +++++++++++++++ .../grove_operations/grove_clear/v0/mod.rs | 30 +++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/packages/rs-drive/src/drive/grove_operations/grove_apply_batch_with_add_costs/v0/mod.rs b/packages/rs-drive/src/drive/grove_operations/grove_apply_batch_with_add_costs/v0/mod.rs index 0763f56fe83..e300fc9cbe4 100644 --- a/packages/rs-drive/src/drive/grove_operations/grove_apply_batch_with_add_costs/v0/mod.rs +++ b/packages/rs-drive/src/drive/grove_operations/grove_apply_batch_with_add_costs/v0/mod.rs @@ -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`. @@ -42,6 +43,13 @@ impl Drive { } } + // Clone batch only if we log them + let maybe_ops_for_logs = if tracing::event_enabled!(Level::TRACE) { + Some(ops.clone()) + } else { + None + }; + let cost_context = self.grove.apply_batch_with_element_flags_update( ops.operations, Some(BatchApplyOptions { @@ -140,6 +148,22 @@ impl Drive { }, transaction, ); + + if tracing::event_enabled!(Level::TRACE) && cost_context.value.is_ok() { + let root_hash = self + .grove + .root_hash(transaction) + .unwrap() + .map_err(Error::GroveDB)?; + + tracing::trace!( + ops = ?maybe_ops_for_logs.unwrap(), + root_hash = ?root_hash, + is_transactional = transaction.is_some(), + "apply grovedb batch", + ); + } + push_drive_operation_result(cost_context, drive_operations) } } diff --git a/packages/rs-drive/src/drive/grove_operations/grove_clear/v0/mod.rs b/packages/rs-drive/src/drive/grove_operations/grove_clear/v0/mod.rs index 9777b567449..5f13c55a3f0 100644 --- a/packages/rs-drive/src/drive/grove_operations/grove_clear/v0/mod.rs +++ b/packages/rs-drive/src/drive/grove_operations/grove_clear/v0/mod.rs @@ -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`. @@ -16,10 +17,35 @@ impl Drive { allow_deleting_subtrees: false, trying_to_clear_with_subtrees_returns_error: false, }; + + let maybe_path_for_logs = if tracing::event_enabled!(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(|_| ()); + + if tracing::event_enabled!(Level::TRACE) && result.is_ok() { + let root_hash = self + .grove + .root_hash(transaction) + .unwrap() + .map_err(Error::GroveDB)?; + + tracing::trace!( + path = ?maybe_path_for_logs.unwrap().to_vec(), + root_hash = ?root_hash, + is_transactional = transaction.is_some(), + "grovedb clear", + ); + } + + result } } From 6a1dd6eb3946edba593efd66cf65cafb795a9ac4 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 6 Oct 2023 13:47:05 +0700 Subject: [PATCH 2/4] chore: define target and feature for logs --- packages/rs-drive/Cargo.toml | 1 + .../grove_apply_batch_with_add_costs/v0/mod.rs | 12 +++++++++--- .../src/drive/grove_operations/grove_clear/v0/mod.rs | 8 ++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/rs-drive/Cargo.toml b/packages/rs-drive/Cargo.toml index c923db94d85..fbc4013db5b 100644 --- a/packages/rs-drive/Cargo.toml +++ b/packages/rs-drive/Cargo.toml @@ -91,4 +91,5 @@ full = [ "rust_decimal_macros", "lazy_static", ] +grovedb_operations_logging = [] verify = ["grovedb/verify", "grovedb-costs"] diff --git a/packages/rs-drive/src/drive/grove_operations/grove_apply_batch_with_add_costs/v0/mod.rs b/packages/rs-drive/src/drive/grove_operations/grove_apply_batch_with_add_costs/v0/mod.rs index e300fc9cbe4..d8fb9553530 100644 --- a/packages/rs-drive/src/drive/grove_operations/grove_apply_batch_with_add_costs/v0/mod.rs +++ b/packages/rs-drive/src/drive/grove_operations/grove_apply_batch_with_add_costs/v0/mod.rs @@ -44,7 +44,9 @@ impl Drive { } // Clone batch only if we log them - let maybe_ops_for_logs = if tracing::event_enabled!(Level::TRACE) { + #[cfg(feature = "grovedb_operations_logging")] + let maybe_ops_for_logs = if tracing::event_enabled!(target: "grovedb_operations", Level::TRACE) + { Some(ops.clone()) } else { None @@ -149,7 +151,10 @@ impl Drive { transaction, ); - if tracing::event_enabled!(Level::TRACE) && cost_context.value.is_ok() { + #[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) @@ -157,10 +162,11 @@ impl Drive { .map_err(Error::GroveDB)?; tracing::trace!( + target = "grovedb_operations", ops = ?maybe_ops_for_logs.unwrap(), root_hash = ?root_hash, is_transactional = transaction.is_some(), - "apply grovedb batch", + "grovedb batch applied", ); } diff --git a/packages/rs-drive/src/drive/grove_operations/grove_clear/v0/mod.rs b/packages/rs-drive/src/drive/grove_operations/grove_clear/v0/mod.rs index 5f13c55a3f0..1b41f82bf6b 100644 --- a/packages/rs-drive/src/drive/grove_operations/grove_clear/v0/mod.rs +++ b/packages/rs-drive/src/drive/grove_operations/grove_clear/v0/mod.rs @@ -18,7 +18,9 @@ impl Drive { trying_to_clear_with_subtrees_returns_error: false, }; - let maybe_path_for_logs = if tracing::event_enabled!(Level::TRACE) { + #[cfg(feature = "grovedb_operations_logging")] + let maybe_path_for_logs = if tracing::event_enabled!(target: "grovedb_operations", Level::TRACE) + { Some(path.clone()) } else { None @@ -31,7 +33,8 @@ impl Drive { .map_err(Error::GroveDB) .map(|_| ()); - if tracing::event_enabled!(Level::TRACE) && result.is_ok() { + #[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) @@ -39,6 +42,7 @@ impl Drive { .map_err(Error::GroveDB)?; tracing::trace!( + target = "grovedb_operations", path = ?maybe_path_for_logs.unwrap().to_vec(), root_hash = ?root_hash, is_transactional = transaction.is_some(), From 4305471d1caaed2715dd697ef14c3c32b759df94 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 6 Oct 2023 13:58:59 +0700 Subject: [PATCH 3/4] style: fix clippy warning --- .../documents_batch/state/v0/fetch_documents.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/documents_batch/state/v0/fetch_documents.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/documents_batch/state/v0/fetch_documents.rs index 75f5abfe02c..1b55ac6a673 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/documents_batch/state/v0/fetch_documents.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/documents_batch/state/v0/fetch_documents.rs @@ -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) From ae6ec3398674992f275602243173df52aa610540 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 6 Oct 2023 14:05:45 +0700 Subject: [PATCH 4/4] Update mod.rs --- .../grove_operations/grove_apply_batch_with_add_costs/v0/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rs-drive/src/drive/grove_operations/grove_apply_batch_with_add_costs/v0/mod.rs b/packages/rs-drive/src/drive/grove_operations/grove_apply_batch_with_add_costs/v0/mod.rs index d8fb9553530..d1c696c9206 100644 --- a/packages/rs-drive/src/drive/grove_operations/grove_apply_batch_with_add_costs/v0/mod.rs +++ b/packages/rs-drive/src/drive/grove_operations/grove_apply_batch_with_add_costs/v0/mod.rs @@ -43,7 +43,7 @@ impl Drive { } } - // Clone batch only if we log them + // 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) {