From 6989f1bb51029c1ce01b48d8c8b5d85c71185517 Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Mon, 4 Nov 2024 03:46:11 +0100 Subject: [PATCH 1/6] fix: issue where apply batch was not using transaction remove_all_votes_given_by_identities --- .../cleanup/remove_all_votes_given_by_identities/v0/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs index 3c36b0ec64..d4f0a04d2d 100644 --- a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs +++ b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs @@ -114,7 +114,7 @@ impl Drive { if !deletion_batch.is_empty() { self.apply_batch_low_level_drive_operations( None, - None, + transaction, deletion_batch, &mut vec![], &platform_version.drive, From 16ebb316e6dfd297284d2c588ab2c445e2901517 Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Mon, 4 Nov 2024 09:30:27 +0100 Subject: [PATCH 2/6] added more logic around fix --- .../mod.rs | 3 ++ .../v0/mod.rs | 5 ++++ .../voting/run_dao_platform_events/v0/mod.rs | 1 + .../state_transitions/masternode_vote/mod.rs | 1 + .../mod.rs | 8 +++++ .../v0/mod.rs | 30 ++++++++++++++----- 6 files changed, 40 insertions(+), 8 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/platform_events/voting/remove_votes_for_removed_masternodes/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/voting/remove_votes_for_removed_masternodes/mod.rs index 8328eb0fc1..ffd97c4292 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/voting/remove_votes_for_removed_masternodes/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/voting/remove_votes_for_removed_masternodes/mod.rs @@ -3,6 +3,7 @@ use crate::error::Error; use crate::platform_types::platform::Platform; use crate::platform_types::platform_state::PlatformState; use crate::rpc::core::CoreRPCLike; +use dpp::block::block_info::BlockInfo; use dpp::version::PlatformVersion; use drive::grovedb::TransactionArg; @@ -14,6 +15,7 @@ where /// Removes the votes for removed masternodes pub(in crate::execution) fn remove_votes_for_removed_masternodes( &self, + block_info: &BlockInfo, last_committed_platform_state: &PlatformState, block_platform_state: &PlatformState, transaction: TransactionArg, @@ -26,6 +28,7 @@ where .remove_votes_for_removed_masternodes { 0 => self.remove_votes_for_removed_masternodes_v0( + block_info, last_committed_platform_state, block_platform_state, transaction, diff --git a/packages/rs-drive-abci/src/execution/platform_events/voting/remove_votes_for_removed_masternodes/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/voting/remove_votes_for_removed_masternodes/v0/mod.rs index b0081570c7..04931a3928 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/voting/remove_votes_for_removed_masternodes/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/voting/remove_votes_for_removed_masternodes/v0/mod.rs @@ -3,6 +3,7 @@ use crate::platform_types::platform::Platform; use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::platform_types::platform_state::PlatformState; use crate::rpc::core::CoreRPCLike; +use dpp::block::block_info::BlockInfo; use dpp::dashcore::hashes::Hash; use dpp::version::PlatformVersion; use drive::grovedb::TransactionArg; @@ -14,6 +15,7 @@ where /// Removes the votes for removed masternodes pub(super) fn remove_votes_for_removed_masternodes_v0( &self, + block_info: &BlockInfo, last_committed_platform_state: &PlatformState, block_platform_state: &PlatformState, transaction: TransactionArg, @@ -29,6 +31,9 @@ where .iter() .map(|pro_tx_hash| pro_tx_hash.as_byte_array().to_vec()) .collect(), + block_info.height, + self.config.network, + self.config.abci.chain_id.as_str(), transaction, platform_version, )?; diff --git a/packages/rs-drive-abci/src/execution/platform_events/voting/run_dao_platform_events/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/voting/run_dao_platform_events/v0/mod.rs index 2ea9357af1..57fbe635b2 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/voting/run_dao_platform_events/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/voting/run_dao_platform_events/v0/mod.rs @@ -21,6 +21,7 @@ where // Remove any votes that self.remove_votes_for_removed_masternodes( + block_info, last_committed_platform_state, block_platform_state, transaction, diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/masternode_vote/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/masternode_vote/mod.rs index fe7d8095b8..9d0394c442 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/masternode_vote/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/masternode_vote/mod.rs @@ -11287,6 +11287,7 @@ mod tests { platform .remove_votes_for_removed_masternodes( + &BlockInfo::default(), &platform_state_before_masternode_identity_removals, &block_platform_state, Some(&transaction), diff --git a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/mod.rs b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/mod.rs index 0f5e0d9604..f93d92a424 100644 --- a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/mod.rs +++ b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/mod.rs @@ -5,6 +5,8 @@ use crate::drive::Drive; use crate::error::drive::DriveError; use crate::error::Error; +use dpp::dashcore::Network; +use dpp::prelude::BlockHeight; use dpp::version::PlatformVersion; use grovedb::TransactionArg; @@ -14,6 +16,9 @@ impl Drive { pub fn remove_all_votes_given_by_identities( &self, identity_ids_as_byte_arrays: Vec>, + block_height: BlockHeight, + network: Network, + chain_id: &str, transaction: TransactionArg, platform_version: &PlatformVersion, ) -> Result<(), Error> { @@ -26,6 +31,9 @@ impl Drive { { 0 => self.remove_all_votes_given_by_identities_v0( identity_ids_as_byte_arrays, + block_height, + network, + chain_id, transaction, platform_version, ), diff --git a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs index d4f0a04d2d..202746d0c2 100644 --- a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs +++ b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs @@ -11,7 +11,8 @@ use crate::drive::votes::paths::{ use crate::drive::votes::storage_form::contested_document_resource_reference_storage_form::ContestedDocumentResourceVoteReferenceStorageForm; use crate::query::QueryItem; use crate::util::grove_operations::BatchDeleteApplyType; -use dpp::prelude::Identifier; +use dpp::dashcore::Network; +use dpp::prelude::{BlockHeight, Identifier}; use dpp::version::PlatformVersion; use grovedb::query_result_type::QueryResultType::QueryPathKeyElementTrioResultType; use grovedb::{PathQuery, Query, SizedQuery, TransactionArg}; @@ -22,6 +23,9 @@ impl Drive { pub(super) fn remove_all_votes_given_by_identities_v0( &self, identity_ids_as_byte_arrays: Vec>, + block_height: BlockHeight, + network: Network, + chain_id: &str, transaction: TransactionArg, platform_version: &PlatformVersion, ) -> Result<(), Error> { @@ -112,13 +116,23 @@ impl Drive { } if !deletion_batch.is_empty() { - self.apply_batch_low_level_drive_operations( - None, - transaction, - deletion_batch, - &mut vec![], - &platform_version.drive, - )?; + if network == Network::Dash && chain_id == "evo1" && block_height < 33000 { + self.apply_batch_low_level_drive_operations( + None, + None, + deletion_batch, + &mut vec![], + &platform_version.drive, + )?; + } else { + self.apply_batch_low_level_drive_operations( + None, + transaction, + deletion_batch, + &mut vec![], + &platform_version.drive, + )?; + } } Ok(()) From a15e34d919385b45e7e797e5e24eaa09ee5b0c76 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Mon, 4 Nov 2024 15:48:22 +0700 Subject: [PATCH 3/6] docs: add comments --- .../v0/mod.rs | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs index 202746d0c2..1e789fda5e 100644 --- a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs +++ b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs @@ -116,23 +116,28 @@ impl Drive { } if !deletion_batch.is_empty() { - if network == Network::Dash && chain_id == "evo1" && block_height < 33000 { - self.apply_batch_low_level_drive_operations( - None, - None, - deletion_batch, - &mut vec![], - &platform_version.drive, - )?; + // We had a sequence of errors on the mainnet started since block 32326. + // We got RocksDB's "transaction is busy" error because of a bug (https://github.com/dashpay/platform/pull/2309). + // Due to another bug in Tenderdash (https://github.com/dashpay/tenderdash/pull/966), + // validators just proceeded to the next block partially committing the state + // and updating the cache (https://github.com/dashpay/platform/pull/2305). + // Full nodes are stuck and proceeded after re-sync. + // For the mainnet chain, we enable this fix at the block when we consider the state is consistent. + let transaction = if network == Network::Dash && chain_id == "evo1" && block_height < 33000 { + // Old behaviour on mainnet + None } else { - self.apply_batch_low_level_drive_operations( - None, - transaction, - deletion_batch, - &mut vec![], - &platform_version.drive, - )?; - } + // We should use transaction + transaction + }; + + self.apply_batch_low_level_drive_operations( + None, + None, + deletion_batch, + &mut vec![], + &platform_version.drive, + )?; } Ok(()) From 751638169b1ff867e1805f9f9ad43deb40be75e9 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Mon, 4 Nov 2024 16:43:11 +0700 Subject: [PATCH 4/6] chore: kick off CI From 63201b2af94895181abd2d945976b504f278ba57 Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Mon, 4 Nov 2024 11:18:31 +0100 Subject: [PATCH 5/6] fmt --- .../v0/mod.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs index 1e789fda5e..e76db95c53 100644 --- a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs +++ b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs @@ -123,13 +123,14 @@ impl Drive { // and updating the cache (https://github.com/dashpay/platform/pull/2305). // Full nodes are stuck and proceeded after re-sync. // For the mainnet chain, we enable this fix at the block when we consider the state is consistent. - let transaction = if network == Network::Dash && chain_id == "evo1" && block_height < 33000 { - // Old behaviour on mainnet - None - } else { - // We should use transaction - transaction - }; + let transaction = + if network == Network::Dash && chain_id == "evo1" && block_height < 33000 { + // Old behaviour on mainnet + None + } else { + // We should use transaction + transaction + }; self.apply_batch_low_level_drive_operations( None, From b5728abbb673fa97fdb6c2ad68f9d32784fd2c96 Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Mon, 4 Nov 2024 11:22:38 +0100 Subject: [PATCH 6/6] reenabled transaction --- .../cleanup/remove_all_votes_given_by_identities/v0/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs index e76db95c53..81b3d0fab7 100644 --- a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs +++ b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs @@ -134,7 +134,7 @@ impl Drive { self.apply_batch_low_level_drive_operations( None, - None, + transaction, deletion_batch, &mut vec![], &platform_version.drive,