Skip to content

Commit 306b86c

Browse files
fix(drive): apply batch is not using transaction in remove_all_votes_given_by_identities (#2309)
Co-authored-by: Ivan Shumkov <[email protected]>
1 parent dacc6db commit 306b86c

File tree

6 files changed

+40
-2
lines changed
  • packages
    • rs-drive-abci/src/execution
      • platform_events/voting
      • validation/state_transition/state_transitions/masternode_vote
    • rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities

6 files changed

+40
-2
lines changed

packages/rs-drive-abci/src/execution/platform_events/voting/remove_votes_for_removed_masternodes/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::error::Error;
33
use crate::platform_types::platform::Platform;
44
use crate::platform_types::platform_state::PlatformState;
55
use crate::rpc::core::CoreRPCLike;
6+
use dpp::block::block_info::BlockInfo;
67
use dpp::version::PlatformVersion;
78
use drive::grovedb::TransactionArg;
89

@@ -14,6 +15,7 @@ where
1415
/// Removes the votes for removed masternodes
1516
pub(in crate::execution) fn remove_votes_for_removed_masternodes(
1617
&self,
18+
block_info: &BlockInfo,
1719
last_committed_platform_state: &PlatformState,
1820
block_platform_state: &PlatformState,
1921
transaction: TransactionArg,
@@ -26,6 +28,7 @@ where
2628
.remove_votes_for_removed_masternodes
2729
{
2830
0 => self.remove_votes_for_removed_masternodes_v0(
31+
block_info,
2932
last_committed_platform_state,
3033
block_platform_state,
3134
transaction,

packages/rs-drive-abci/src/execution/platform_events/voting/remove_votes_for_removed_masternodes/v0/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::platform_types::platform::Platform;
33
use crate::platform_types::platform_state::v0::PlatformStateV0Methods;
44
use crate::platform_types::platform_state::PlatformState;
55
use crate::rpc::core::CoreRPCLike;
6+
use dpp::block::block_info::BlockInfo;
67
use dpp::dashcore::hashes::Hash;
78
use dpp::version::PlatformVersion;
89
use drive::grovedb::TransactionArg;
@@ -14,6 +15,7 @@ where
1415
/// Removes the votes for removed masternodes
1516
pub(super) fn remove_votes_for_removed_masternodes_v0(
1617
&self,
18+
block_info: &BlockInfo,
1719
last_committed_platform_state: &PlatformState,
1820
block_platform_state: &PlatformState,
1921
transaction: TransactionArg,
@@ -29,6 +31,9 @@ where
2931
.iter()
3032
.map(|pro_tx_hash| pro_tx_hash.as_byte_array().to_vec())
3133
.collect(),
34+
block_info.height,
35+
self.config.network,
36+
self.config.abci.chain_id.as_str(),
3237
transaction,
3338
platform_version,
3439
)?;

packages/rs-drive-abci/src/execution/platform_events/voting/run_dao_platform_events/v0/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ where
2121
// Remove any votes that
2222

2323
self.remove_votes_for_removed_masternodes(
24+
block_info,
2425
last_committed_platform_state,
2526
block_platform_state,
2627
transaction,

packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/masternode_vote/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11287,6 +11287,7 @@ mod tests {
1128711287

1128811288
platform
1128911289
.remove_votes_for_removed_masternodes(
11290+
&BlockInfo::default(),
1129011291
&platform_state_before_masternode_identity_removals,
1129111292
&block_platform_state,
1129211293
Some(&transaction),

packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use crate::drive::Drive;
55
use crate::error::drive::DriveError;
66
use crate::error::Error;
77

8+
use dpp::dashcore::Network;
9+
use dpp::prelude::BlockHeight;
810
use dpp::version::PlatformVersion;
911
use grovedb::TransactionArg;
1012

@@ -14,6 +16,9 @@ impl Drive {
1416
pub fn remove_all_votes_given_by_identities(
1517
&self,
1618
identity_ids_as_byte_arrays: Vec<Vec<u8>>,
19+
block_height: BlockHeight,
20+
network: Network,
21+
chain_id: &str,
1722
transaction: TransactionArg,
1823
platform_version: &PlatformVersion,
1924
) -> Result<(), Error> {
@@ -26,6 +31,9 @@ impl Drive {
2631
{
2732
0 => self.remove_all_votes_given_by_identities_v0(
2833
identity_ids_as_byte_arrays,
34+
block_height,
35+
network,
36+
chain_id,
2937
transaction,
3038
platform_version,
3139
),

packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identities/v0/mod.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use crate::drive::votes::paths::{
1111
use crate::drive::votes::storage_form::contested_document_resource_reference_storage_form::ContestedDocumentResourceVoteReferenceStorageForm;
1212
use crate::query::QueryItem;
1313
use crate::util::grove_operations::BatchDeleteApplyType;
14-
use dpp::prelude::Identifier;
14+
use dpp::dashcore::Network;
15+
use dpp::prelude::{BlockHeight, Identifier};
1516
use dpp::version::PlatformVersion;
1617
use grovedb::query_result_type::QueryResultType::QueryPathKeyElementTrioResultType;
1718
use grovedb::{PathQuery, Query, SizedQuery, TransactionArg};
@@ -22,6 +23,9 @@ impl Drive {
2223
pub(super) fn remove_all_votes_given_by_identities_v0(
2324
&self,
2425
identity_ids_as_byte_arrays: Vec<Vec<u8>>,
26+
block_height: BlockHeight,
27+
network: Network,
28+
chain_id: &str,
2529
transaction: TransactionArg,
2630
platform_version: &PlatformVersion,
2731
) -> Result<(), Error> {
@@ -112,9 +116,25 @@ impl Drive {
112116
}
113117

114118
if !deletion_batch.is_empty() {
119+
// We had a sequence of errors on the mainnet started since block 32326.
120+
// We got RocksDB's "transaction is busy" error because of a bug (https://github.com/dashpay/platform/pull/2309).
121+
// Due to another bug in Tenderdash (https://github.com/dashpay/tenderdash/pull/966),
122+
// validators just proceeded to the next block partially committing the state
123+
// and updating the cache (https://github.com/dashpay/platform/pull/2305).
124+
// Full nodes are stuck and proceeded after re-sync.
125+
// For the mainnet chain, we enable this fix at the block when we consider the state is consistent.
126+
let transaction =
127+
if network == Network::Dash && chain_id == "evo1" && block_height < 33000 {
128+
// Old behaviour on mainnet
129+
None
130+
} else {
131+
// We should use transaction
132+
transaction
133+
};
134+
115135
self.apply_batch_low_level_drive_operations(
116136
None,
117-
None,
137+
transaction,
118138
deletion_batch,
119139
&mut vec![],
120140
&platform_version.drive,

0 commit comments

Comments
 (0)