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

fix(drive): apply batch is not using transaction in remove_all_votes_given_by_identities #2309

Merged
merged 6 commits into from
Nov 4, 2024
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 @@ -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;

Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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,
)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -14,6 +16,9 @@ impl Drive {
pub fn remove_all_votes_given_by_identities(
&self,
identity_ids_as_byte_arrays: Vec<Vec<u8>>,
block_height: BlockHeight,
network: Network,
chain_id: &str,
transaction: TransactionArg,
platform_version: &PlatformVersion,
) -> Result<(), Error> {
Expand All @@ -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,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -22,6 +23,9 @@ impl Drive {
pub(super) fn remove_all_votes_given_by_identities_v0(
&self,
identity_ids_as_byte_arrays: Vec<Vec<u8>>,
block_height: BlockHeight,
network: Network,
chain_id: &str,
transaction: TransactionArg,
platform_version: &PlatformVersion,
) -> Result<(), Error> {
Expand Down Expand Up @@ -112,9 +116,25 @@ impl Drive {
}

if !deletion_batch.is_empty() {
// 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 {
// We should use transaction
transaction
};

self.apply_batch_low_level_drive_operations(
None,
None,
transaction,
deletion_batch,
&mut vec![],
&platform_version.drive,
Expand Down
Loading