diff --git a/packages/rs-drive-abci/src/execution/engine/run_block_proposal/v0/mod.rs b/packages/rs-drive-abci/src/execution/engine/run_block_proposal/v0/mod.rs index 0b20f41d88..1ae4a1e639 100644 --- a/packages/rs-drive-abci/src/execution/engine/run_block_proposal/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/engine/run_block_proposal/v0/mod.rs @@ -269,6 +269,14 @@ where Error::Execution(ExecutionError::UpdateValidatorProposedAppVersionError(e)) })?; // This is a system error + // Rebroadcast expired withdrawals if they exist + self.rebroadcast_expired_withdrawal_documents( + &block_info, + &last_committed_platform_state, + transaction, + platform_version, + )?; + // Mark all previously broadcasted and chainlocked withdrawals as complete // only when we are on a new core height if block_state_info.core_chain_locked_height() != last_block_core_height { diff --git a/packages/rs-drive-abci/src/execution/platform_events/protocol_upgrade/perform_events_on_first_block_of_protocol_change/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/protocol_upgrade/perform_events_on_first_block_of_protocol_change/v0/mod.rs index d732893b80..1c50e27e7a 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/protocol_upgrade/perform_events_on_first_block_of_protocol_change/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/protocol_upgrade/perform_events_on_first_block_of_protocol_change/v0/mod.rs @@ -3,7 +3,8 @@ use crate::platform_types::platform::Platform; use dpp::version::PlatformVersion; use dpp::version::ProtocolVersion; use drive::drive::identity::withdrawals::paths::{ - get_withdrawal_root_path, WITHDRAWAL_TRANSACTIONS_SUM_AMOUNT_TREE_KEY, + get_withdrawal_root_path, WITHDRAWAL_TRANSACTIONS_BROADCASTED_KEY, + WITHDRAWAL_TRANSACTIONS_SUM_AMOUNT_TREE_KEY, }; use drive::grovedb::{Element, Transaction}; @@ -68,6 +69,14 @@ impl Platform { None, &platform_version.drive, )?; + self.drive.grove_insert_if_not_exists( + (&path).into(), + &WITHDRAWAL_TRANSACTIONS_BROADCASTED_KEY, + Element::empty_tree(), + Some(transaction), + None, + &platform_version.drive, + )?; Ok(()) } } diff --git a/packages/rs-drive-abci/src/execution/platform_events/withdrawals/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/withdrawals/mod.rs index 0de6cbfcef..d7779c47b0 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/withdrawals/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/withdrawals/mod.rs @@ -4,4 +4,5 @@ pub(in crate::execution) mod cleanup_expired_locks_of_withdrawal_amounts; pub(in crate::execution) mod dequeue_and_build_unsigned_withdrawal_transactions; pub(in crate::execution) mod fetch_transactions_block_inclusion_status; pub(in crate::execution) mod pool_withdrawals_into_transactions_queue; +pub(in crate::execution) mod rebroadcast_expired_withdrawal_documents; pub(in crate::execution) mod update_broadcasted_withdrawal_statuses; diff --git a/packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v0/mod.rs index 2f353c8225..86ebeb6fbb 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v0/mod.rs @@ -44,125 +44,8 @@ where ); return Ok(()); } - let documents = self.drive.fetch_oldest_withdrawal_documents_by_status( - withdrawals_contract::WithdrawalStatus::QUEUED.into(), - platform_version - .system_limits - .withdrawal_transactions_per_block_limit, - transaction, - platform_version, - )?; - - if documents.is_empty() { - return Ok(()); - } - - // Only take documents up to the withdrawal amount - let current_withdrawal_limit = self - .drive - .calculate_current_withdrawal_limit(transaction, platform_version)?; - - // Only process documents up to the current withdrawal limit. - let mut total_withdrawal_amount = 0u64; - - // Iterate over the documents and accumulate their withdrawal amounts. - let mut documents_to_process = vec![]; - for document in documents { - // Get the withdrawal amount from the document properties. - let amount: u64 = document - .properties() - .get_integer(withdrawal::properties::AMOUNT)?; - - // Check if adding this amount would exceed the current withdrawal limit. - let potential_total_withdrawal_amount = - total_withdrawal_amount.checked_add(amount).ok_or_else(|| { - Error::Execution(ExecutionError::Overflow( - "overflow in total withdrawal amount", - )) - })?; - - if potential_total_withdrawal_amount > current_withdrawal_limit { - // If adding this withdrawal would exceed the limit, stop processing further. - break; - } - - total_withdrawal_amount = potential_total_withdrawal_amount; - - // Add this document to the list of documents to be processed. - documents_to_process.push(document); - } - - if documents_to_process.is_empty() { - return Ok(()); - } - - let start_transaction_index = self - .drive - .fetch_next_withdrawal_transaction_index(transaction, platform_version)?; - - let (withdrawal_transactions, total_amount) = self - .build_untied_withdrawal_transactions_from_documents( - &mut documents_to_process, - start_transaction_index, - block_info, - platform_version, - )?; - - let withdrawal_transactions_count = withdrawal_transactions.len(); - - let mut drive_operations = vec![]; - - self.drive - .add_enqueue_untied_withdrawal_transaction_operations( - withdrawal_transactions, - total_amount, - &mut drive_operations, - platform_version, - )?; - - let end_transaction_index = start_transaction_index + withdrawal_transactions_count as u64; - - self.drive - .add_update_next_withdrawal_transaction_index_operation( - end_transaction_index, - &mut drive_operations, - platform_version, - )?; - - tracing::debug!( - "Pooled {} withdrawal documents into {} transactions with indices from {} to {}", - documents_to_process.len(), - withdrawal_transactions_count, - start_transaction_index, - end_transaction_index, - ); - - let withdrawals_contract = self.drive.cache.system_data_contracts.load_withdrawals(); - - self.drive.add_update_multiple_documents_operations( - &documents_to_process, - &withdrawals_contract, - withdrawals_contract - .document_type_for_name(withdrawal::NAME) - .map_err(|_| { - Error::Execution(ExecutionError::CorruptedCodeExecution( - "Can't fetch withdrawal data contract", - )) - })?, - &mut drive_operations, - &platform_version.drive, - )?; - - self.drive.apply_drive_operations( - drive_operations, - true, - block_info, - transaction, - platform_version, - None, - )?; - - Ok(()) + // Just use the v1 as to not duplicate code + self.pool_withdrawals_into_transactions_queue_v1(block_info, transaction, platform_version) } } diff --git a/packages/rs-drive-abci/src/execution/platform_events/withdrawals/rebroadcast_expired_withdrawal_documents/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/withdrawals/rebroadcast_expired_withdrawal_documents/mod.rs new file mode 100644 index 0000000000..f4e9daab97 --- /dev/null +++ b/packages/rs-drive-abci/src/execution/platform_events/withdrawals/rebroadcast_expired_withdrawal_documents/mod.rs @@ -0,0 +1,64 @@ +use crate::error::execution::ExecutionError; +use crate::error::Error; +use crate::platform_types::platform::Platform; + +use crate::rpc::core::CoreRPCLike; +use dpp::block::block_info::BlockInfo; + +use crate::platform_types::platform_state::PlatformState; +use dpp::version::PlatformVersion; +use drive::grovedb::Transaction; + +mod v0; +mod v1; + +impl Platform +where + C: CoreRPCLike, +{ + /// Rebroadcasts expired withdrawal documents if any exist. + /// + /// This function attempts to rebroadcast expired withdrawal documents by checking if there are + /// any documents with the status `EXPIRED`. It updates the status of such documents to + /// `BROADCASTED`, increments their revision, and reschedules them for broadcasting. + /// + /// # Parameters + /// - `block_info`: Information about the current block (e.g., timestamp). + /// - `transaction`: The transaction within which the rebroadcast should be executed. + /// - `platform_version`: The version of the platform, used to determine the correct method implementation. + /// + /// # Returns + /// - `Ok(())` if the rebroadcast process succeeds without issues. + /// - `Err(ExecutionError::UnknownVersionMismatch)` if the platform version is unsupported. + pub fn rebroadcast_expired_withdrawal_documents( + &self, + block_info: &BlockInfo, + last_committed_platform_state: &PlatformState, + transaction: &Transaction, + platform_version: &PlatformVersion, + ) -> Result<(), Error> { + match platform_version + .drive_abci + .methods + .withdrawals + .rebroadcast_expired_withdrawal_documents + { + 0 => self.rebroadcast_expired_withdrawal_documents_v0( + block_info, + last_committed_platform_state, + transaction, + platform_version, + ), + 1 => self.rebroadcast_expired_withdrawal_documents_v1( + block_info, + transaction, + platform_version, + ), + version => Err(Error::Execution(ExecutionError::UnknownVersionMismatch { + method: "rebroadcast_expired_withdrawal_documents".to_string(), + known_versions: vec![0, 1], + received: version, + })), + } + } +} diff --git a/packages/rs-drive-abci/src/execution/platform_events/withdrawals/rebroadcast_expired_withdrawal_documents/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/withdrawals/rebroadcast_expired_withdrawal_documents/v0/mod.rs new file mode 100644 index 0000000000..011867a872 --- /dev/null +++ b/packages/rs-drive-abci/src/execution/platform_events/withdrawals/rebroadcast_expired_withdrawal_documents/v0/mod.rs @@ -0,0 +1,39 @@ +use crate::error::Error; +use crate::platform_types::platform_state::v0::PlatformStateV0Methods; +use crate::platform_types::platform_state::PlatformState; +use crate::{platform_types::platform::Platform, rpc::core::CoreRPCLike}; +use dpp::block::block_info::BlockInfo; +use dpp::version::PlatformVersion; +use drive::grovedb::Transaction; + +impl Platform +where + C: CoreRPCLike, +{ + pub(super) fn rebroadcast_expired_withdrawal_documents_v0( + &self, + block_info: &BlockInfo, + last_committed_platform_state: &PlatformState, + transaction: &Transaction, + platform_version: &PlatformVersion, + ) -> Result<(), Error> { + // Currently Core only supports using the first 2 quorums (out of 24 for mainnet). + // For us, we just use the latest quorum to be extra safe. + let Some(position_of_current_quorum) = + last_committed_platform_state.current_validator_set_position_in_list_by_most_recent() + else { + tracing::warn!("Current quorum not in current validator set, not making withdrawals"); + return Ok(()); + }; + if position_of_current_quorum != 0 { + tracing::debug!( + "Current quorum is not most recent, it is in position {}, not making withdrawals", + position_of_current_quorum + ); + return Ok(()); + } + // Version 1 changes on Version 0, by not having the Core 2 Quorum limit. + // Hence we can just use the v1 here after the extra logic of v0 + self.rebroadcast_expired_withdrawal_documents_v1(block_info, transaction, platform_version) + } +} diff --git a/packages/rs-drive-abci/src/execution/platform_events/withdrawals/rebroadcast_expired_withdrawal_documents/v1/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/withdrawals/rebroadcast_expired_withdrawal_documents/v1/mod.rs new file mode 100644 index 0000000000..7e90dc51cb --- /dev/null +++ b/packages/rs-drive-abci/src/execution/platform_events/withdrawals/rebroadcast_expired_withdrawal_documents/v1/mod.rs @@ -0,0 +1,119 @@ +use dpp::block::block_info::BlockInfo; +use dpp::data_contract::accessors::v0::DataContractV0Getters; +use dpp::data_contracts::withdrawals_contract::WithdrawalStatus; +use dpp::document::document_methods::DocumentMethodsV0; +use dpp::document::{DocumentV0Getters, DocumentV0Setters}; +use dpp::platform_value::btreemap_extensions::BTreeValueMapHelper; + +use dpp::system_data_contracts::withdrawals_contract::v1::document_types::withdrawal; +use dpp::version::PlatformVersion; +use std::collections::BTreeSet; + +use crate::{ + error::{execution::ExecutionError, Error}, + platform_types::platform::Platform, + rpc::core::CoreRPCLike, +}; +use dpp::withdrawal::WithdrawalTransactionIndex; +use drive::grovedb::Transaction; +use drive::util::batch::DriveOperation; + +impl Platform +where + C: CoreRPCLike, +{ + /// Version 1 changes on Version 0, by not having the Core 2 Quorum limit. + /// We should switch to Version 1 once Core has fixed the issue + pub(super) fn rebroadcast_expired_withdrawal_documents_v1( + &self, + block_info: &BlockInfo, + transaction: &Transaction, + platform_version: &PlatformVersion, + ) -> Result<(), Error> { + let expired_withdrawal_documents_to_retry_signing = + self.drive.fetch_oldest_withdrawal_documents_by_status( + WithdrawalStatus::EXPIRED.into(), + platform_version + .system_limits + .retry_signing_expired_withdrawal_documents_per_block_limit, + transaction.into(), + platform_version, + )?; + + if expired_withdrawal_documents_to_retry_signing.is_empty() { + return Ok(()); + } + + // Collecting unique withdrawal indices of expired documents + let expired_withdrawal_indices: Vec = + expired_withdrawal_documents_to_retry_signing + .iter() + .map(|document| { + document + .properties() + .get_optional_u64(withdrawal::properties::TRANSACTION_INDEX)? + .ok_or(Error::Execution(ExecutionError::CorruptedDriveResponse( + "Can't get transaction index from withdrawal document".to_string(), + ))) + }) + .collect::, Error>>()? + .into_iter() + .collect(); + + let mut drive_operations: Vec = vec![]; + + // Collecting only documents that have been updated + let mut documents_to_update = Vec::new(); + + for mut document in expired_withdrawal_documents_to_retry_signing { + document.set_u8( + withdrawal::properties::STATUS, + WithdrawalStatus::BROADCASTED as u8, + ); + + document.set_updated_at(Some(block_info.time_ms)); + + document.increment_revision().map_err(Error::Protocol)?; + + documents_to_update.push(document); + } + + if documents_to_update.is_empty() { + return Ok(()); + } + + self.drive + .move_broadcasted_withdrawal_transactions_back_to_queue_operations( + expired_withdrawal_indices, + &mut drive_operations, + platform_version, + )?; + + let withdrawals_contract = self.drive.cache.system_data_contracts.load_withdrawals(); + + self.drive.add_update_multiple_documents_operations( + &documents_to_update, + &withdrawals_contract, + withdrawals_contract + .document_type_for_name(withdrawal::NAME) + .map_err(|_| { + Error::Execution(ExecutionError::CorruptedCodeExecution( + "Can't fetch withdrawal data contract", + )) + })?, + &mut drive_operations, + &platform_version.drive, + )?; + + self.drive.apply_drive_operations( + drive_operations, + true, + block_info, + transaction.into(), + platform_version, + None, + )?; + + Ok(()) + } +} diff --git a/packages/rs-drive-abci/src/execution/platform_events/withdrawals/update_broadcasted_withdrawal_statuses/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/withdrawals/update_broadcasted_withdrawal_statuses/v0/mod.rs index 81210da62e..470d234939 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/withdrawals/update_broadcasted_withdrawal_statuses/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/withdrawals/update_broadcasted_withdrawal_statuses/v0/mod.rs @@ -8,19 +8,17 @@ use dpp::platform_value::btreemap_extensions::BTreeValueMapHelper; use dpp::system_data_contracts::withdrawals_contract::v1::document_types::withdrawal; use dpp::version::PlatformVersion; -use itertools::Itertools; -use std::collections::HashSet; - -use dpp::withdrawal::WithdrawalTransactionIndex; -use drive::config::DEFAULT_QUERY_LIMIT; -use drive::grovedb::Transaction; -use drive::util::batch::DriveOperation; +use std::collections::BTreeSet; use crate::{ error::{execution::ExecutionError, Error}, platform_types::platform::Platform, rpc::core::CoreRPCLike, }; +use dpp::withdrawal::WithdrawalTransactionIndex; +use drive::config::DEFAULT_QUERY_LIMIT; +use drive::grovedb::Transaction; +use drive::util::batch::DriveOperation; impl Platform where @@ -45,20 +43,21 @@ where return Ok(()); } - // Collecting unique withdrawal indices - let broadcasted_withdrawal_indices = broadcasted_withdrawal_documents - .iter() - .map(|document| { - document - .properties() - .get_optional_u64(withdrawal::properties::TRANSACTION_INDEX)? - .ok_or(Error::Execution(ExecutionError::CorruptedDriveResponse( - "Can't get transaction index from withdrawal document".to_string(), - ))) - }) - .collect::, Error>>()? - .into_iter() - .collect_vec(); + // Collecting unique withdrawal indices of broadcasted documents + let broadcasted_withdrawal_indices: Vec = + broadcasted_withdrawal_documents + .iter() + .map(|document| { + document + .properties() + .get_optional_u64(withdrawal::properties::TRANSACTION_INDEX)? + .ok_or(Error::Execution(ExecutionError::CorruptedDriveResponse( + "Can't get transaction index from withdrawal document".to_string(), + ))) + }) + .collect::, Error>>()? + .into_iter() + .collect(); let withdrawal_transaction_statuses = self.fetch_transactions_block_inclusion_status( block_info.core_height, @@ -68,6 +67,18 @@ where let mut drive_operations: Vec = vec![]; + // Let's remove broadcasted withdrawal transactions that are now chainlocked + let chainlocked_indexes = withdrawal_transaction_statuses + .iter() + .filter_map(|(index, status)| { + if *status == AssetUnlockStatus::Chainlocked { + Some(*index) + } else { + None + } + }) + .collect::>(); + // Collecting only documents that have been updated let mut documents_to_update = Vec::new(); @@ -118,7 +129,6 @@ where "Withdrawal with transaction index {} is marked as expired", withdrawal_index ); - WithdrawalStatus::EXPIRED } else { continue; @@ -137,6 +147,13 @@ where return Ok(()); } + self.drive + .remove_broadcasted_withdrawal_transactions_after_completion_operations( + chainlocked_indexes, + &mut drive_operations, + platform_version, + )?; + let withdrawals_contract = self.drive.cache.system_data_contracts.load_withdrawals(); self.drive.add_update_multiple_documents_operations( diff --git a/packages/rs-drive-abci/tests/strategy_tests/withdrawal_tests.rs b/packages/rs-drive-abci/tests/strategy_tests/withdrawal_tests.rs index e0c3398417..ccbcae5d73 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/withdrawal_tests.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/withdrawal_tests.rs @@ -790,15 +790,13 @@ mod tests { .expect_send_raw_transaction() .returning(move |_| Ok(Txid::all_zeros())); - let mut chain_locked_height = 1; - // Have to go with a complicated shared object for the core state because we need to change // rpc response along the way but we can't mutate `platform.core_rpc` later // because platform reference is moved into the AbciApplication. let shared_core_state = Arc::new(Mutex::new(CoreState { asset_unlock_statuses: BTreeMap::new(), chain_lock: ChainLock { - block_height: chain_locked_height, + block_height: 1, block_hash: BlockHash::from_byte_array([1; 32]), signature: BLSSignature::from([2; 96]), }, @@ -1122,10 +1120,7 @@ mod tests { // Simulate transactions being added to the core mempool let mut core_state = shared_core_state.lock().unwrap(); - let number_of_blocks_before_expiration: u32 = 48; - chain_locked_height += number_of_blocks_before_expiration; - - core_state.chain_lock.block_height = chain_locked_height; + core_state.chain_lock.block_height = 50; last_block_withdrawals.iter().for_each(|tx| { let index = asset_unlock_index(tx); @@ -1142,12 +1137,25 @@ mod tests { // Run block 5 // Tests withdrawal expiration - let ChainExecutionOutcome { .. } = { + let ChainExecutionOutcome { + abci_app, + proposers, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, + current_proposer_versions, + end_time_ms, + withdrawals: last_block_withdrawals, + identity_nonce_counter, + identity_contract_nonce_counter, + instant_lock_quorums, + identities, + .. + } = { let outcome = continue_chain_for_strategy( abci_app, ChainExecutionParameters { block_start: 5, - core_height_start: 2, + core_height_start: 50, block_count: 1, proposers, validator_quorums: quorums, @@ -1223,6 +1231,197 @@ mod tests { outcome }; + + // Run block 6 + // Should broadcast previously expired transaction + let ChainExecutionOutcome { + abci_app, + proposers, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, + current_proposer_versions, + end_time_ms, + identity_nonce_counter, + identity_contract_nonce_counter, + instant_lock_quorums, + identities, + .. + } = { + let outcome = continue_chain_for_strategy( + abci_app, + ChainExecutionParameters { + block_start: 6, + core_height_start: 50, + block_count: 1, + proposers, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, + current_proposer_versions: Some(current_proposer_versions), + current_identity_nonce_counter: identity_nonce_counter, + current_identity_contract_nonce_counter: identity_contract_nonce_counter, + current_votes: BTreeMap::default(), + start_time_ms: GENESIS_TIME_MS, + current_time_ms: end_time_ms, + instant_lock_quorums, + current_identities: identities, + }, + continue_strategy_no_operations.clone(), + config.clone(), + StrategyRandomness::SeedEntropy(2), + ); + + let withdrawal_documents_pooled = outcome + .abci_app + .platform + .drive + .fetch_oldest_withdrawal_documents_by_status( + withdrawals_contract::WithdrawalStatus::POOLED.into(), + DEFAULT_QUERY_LIMIT, + None, + platform_version, + ) + .unwrap(); + + let withdrawal_documents_broadcasted = outcome + .abci_app + .platform + .drive + .fetch_oldest_withdrawal_documents_by_status( + withdrawals_contract::WithdrawalStatus::BROADCASTED.into(), + DEFAULT_QUERY_LIMIT, + None, + platform_version, + ) + .unwrap(); + + let withdrawal_documents_completed = outcome + .abci_app + .platform + .drive + .fetch_oldest_withdrawal_documents_by_status( + withdrawals_contract::WithdrawalStatus::COMPLETE.into(), + DEFAULT_QUERY_LIMIT, + None, + platform_version, + ) + .unwrap(); + + let withdrawal_documents_expired = outcome + .abci_app + .platform + .drive + .fetch_oldest_withdrawal_documents_by_status( + withdrawals_contract::WithdrawalStatus::EXPIRED.into(), + DEFAULT_QUERY_LIMIT, + None, + platform_version, + ) + .unwrap(); + + assert!(withdrawal_documents_pooled.is_empty()); + assert!(withdrawal_documents_completed.is_empty()); + + assert_eq!(withdrawal_documents_broadcasted.len(), 1); + + assert!(withdrawal_documents_expired.is_empty()); + + outcome + }; + + // Update core state saying transaction is chainlocked + { + let mut core_state = shared_core_state.lock().unwrap(); + + // First, set all previously broadcasted transactions to Chainlocked + core_state + .asset_unlock_statuses + .iter_mut() + .for_each(|(index, status_result)| { + // Do not settle yet transactions that were broadcasted in the last block + status_result.index = *index; + status_result.status = AssetUnlockStatus::Chainlocked; + }); + + core_state.chain_lock.block_height = 51; + + drop(core_state); + } + + let outcome = continue_chain_for_strategy( + abci_app, + ChainExecutionParameters { + block_start: 7, + core_height_start: 51, + block_count: 1, + proposers, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, + current_proposer_versions: Some(current_proposer_versions), + current_identity_nonce_counter: identity_nonce_counter, + current_identity_contract_nonce_counter: identity_contract_nonce_counter, + current_votes: BTreeMap::default(), + start_time_ms: GENESIS_TIME_MS, + current_time_ms: end_time_ms, + instant_lock_quorums, + current_identities: identities, + }, + continue_strategy_no_operations.clone(), + config.clone(), + StrategyRandomness::SeedEntropy(2), + ); + + let withdrawal_documents_pooled = outcome + .abci_app + .platform + .drive + .fetch_oldest_withdrawal_documents_by_status( + withdrawals_contract::WithdrawalStatus::POOLED.into(), + DEFAULT_QUERY_LIMIT, + None, + platform_version, + ) + .unwrap(); + + let withdrawal_documents_broadcasted = outcome + .abci_app + .platform + .drive + .fetch_oldest_withdrawal_documents_by_status( + withdrawals_contract::WithdrawalStatus::BROADCASTED.into(), + DEFAULT_QUERY_LIMIT, + None, + platform_version, + ) + .unwrap(); + + let withdrawal_documents_completed = outcome + .abci_app + .platform + .drive + .fetch_oldest_withdrawal_documents_by_status( + withdrawals_contract::WithdrawalStatus::COMPLETE.into(), + DEFAULT_QUERY_LIMIT, + None, + platform_version, + ) + .unwrap(); + + let withdrawal_documents_expired = outcome + .abci_app + .platform + .drive + .fetch_oldest_withdrawal_documents_by_status( + withdrawals_contract::WithdrawalStatus::EXPIRED.into(), + DEFAULT_QUERY_LIMIT, + None, + platform_version, + ) + .unwrap(); + + assert_eq!(withdrawal_documents_completed.len(), 1); + assert!(withdrawal_documents_pooled.is_empty()); + assert!(withdrawal_documents_broadcasted.is_empty()); + assert!(withdrawal_documents_expired.is_empty()); } #[test] diff --git a/packages/rs-drive/src/drive/balances/mod.rs b/packages/rs-drive/src/drive/balances/mod.rs index 0af170831e..39f15f4298 100644 --- a/packages/rs-drive/src/drive/balances/mod.rs +++ b/packages/rs-drive/src/drive/balances/mod.rs @@ -79,7 +79,7 @@ mod tests { #[test] fn verify_total_credits_structure() { - let drive: Drive = setup_drive_with_initial_state_structure(); + let drive: Drive = setup_drive_with_initial_state_structure(None); let db_transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::latest(); diff --git a/packages/rs-drive/src/drive/contract/get_fetch/fetch_contract_with_history/mod.rs b/packages/rs-drive/src/drive/contract/get_fetch/fetch_contract_with_history/mod.rs index ee60215b7f..fdcb837850 100644 --- a/packages/rs-drive/src/drive/contract/get_fetch/fetch_contract_with_history/mod.rs +++ b/packages/rs-drive/src/drive/contract/get_fetch/fetch_contract_with_history/mod.rs @@ -256,7 +256,7 @@ mod tests { TestData { data_contract, - drive: setup_drive_with_initial_state_structure(), + drive: setup_drive_with_initial_state_structure(None), } } diff --git a/packages/rs-drive/src/drive/contract/get_fetch/get_contract_with_fetch_info/mod.rs b/packages/rs-drive/src/drive/contract/get_fetch/get_contract_with_fetch_info/mod.rs index e49ee0b1f8..5bee42052d 100644 --- a/packages/rs-drive/src/drive/contract/get_fetch/get_contract_with_fetch_info/mod.rs +++ b/packages/rs-drive/src/drive/contract/get_fetch/get_contract_with_fetch_info/mod.rs @@ -248,7 +248,7 @@ mod tests { #[test] fn should_return_none_if_contract_not_exist() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let result = drive @@ -261,7 +261,7 @@ mod tests { #[test] fn should_return_fees_for_non_existing_contract_if_epoch_is_passed() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let result = drive diff --git a/packages/rs-drive/src/drive/contract/mod.rs b/packages/rs-drive/src/drive/contract/mod.rs index 6ccfda8292..c48343d6c4 100644 --- a/packages/rs-drive/src/drive/contract/mod.rs +++ b/packages/rs-drive/src/drive/contract/mod.rs @@ -68,7 +68,7 @@ mod tests { #[deprecated(note = "This function is marked as unused.")] #[allow(deprecated)] fn setup_deep_nested_50_contract() -> (Drive, DataContract) { - let drive: Drive = setup_drive_with_initial_state_structure(); + let drive: Drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let contract_path = "tests/supporting_files/contract/deepNested/deep-nested50.json"; @@ -93,7 +93,7 @@ mod tests { #[deprecated(note = "This function is marked as unused.")] #[allow(deprecated)] fn setup_deep_nested_10_contract() -> (Drive, DataContract) { - let drive: Drive = setup_drive_with_initial_state_structure(); + let drive: Drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let contract_path = "tests/supporting_files/contract/deepNested/deep-nested10.json"; @@ -115,7 +115,7 @@ mod tests { } pub(in crate::drive::contract) fn setup_reference_contract() -> (Drive, DataContract) { - let drive: Drive = setup_drive_with_initial_state_structure(); + let drive: Drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let contract_path = "tests/supporting_files/contract/references/references.json"; @@ -138,7 +138,7 @@ mod tests { } pub(in crate::drive::contract) fn setup_dashpay() -> (Drive, DataContract) { - let drive: Drive = setup_drive_with_initial_state_structure(); + let drive: Drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); // let's construct the grovedb structure for the dashpay data contract @@ -159,7 +159,7 @@ mod tests { pub(in crate::drive::contract) fn setup_dashpay_with_generalized_encryption_contract( ) -> (Drive, DataContract) { - let drive: Drive = setup_drive_with_initial_state_structure(); + let drive: Drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); // let's construct the grovedb structure for the dashpay data contract @@ -419,7 +419,7 @@ mod tests { #[test] fn test_create_reference_contract_without_apply() { - let drive: Drive = setup_drive_with_initial_state_structure(); + let drive: Drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let contract_path = "tests/supporting_files/contract/references/references.json"; @@ -441,7 +441,7 @@ mod tests { #[test] fn test_create_reference_contract_with_history_without_apply() { - let drive: Drive = setup_drive_with_initial_state_structure(); + let drive: Drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let contract_path = @@ -464,7 +464,7 @@ mod tests { #[test] fn test_update_reference_contract_without_apply() { - let drive: Drive = setup_drive_with_initial_state_structure(); + let drive: Drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let contract_path = "tests/supporting_files/contract/references/references.json"; diff --git a/packages/rs-drive/src/drive/credit_pools/epochs/credit_distribution_pools/get_epoch_fee_multiplier/v0/mod.rs b/packages/rs-drive/src/drive/credit_pools/epochs/credit_distribution_pools/get_epoch_fee_multiplier/v0/mod.rs index d89596e693..46984456fa 100644 --- a/packages/rs-drive/src/drive/credit_pools/epochs/credit_distribution_pools/get_epoch_fee_multiplier/v0/mod.rs +++ b/packages/rs-drive/src/drive/credit_pools/epochs/credit_distribution_pools/get_epoch_fee_multiplier/v0/mod.rs @@ -61,7 +61,7 @@ mod tests { #[test] fn test_error_if_epoch_tree_is_not_initiated_v0() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let transaction = drive.grove.start_transaction(); @@ -77,7 +77,7 @@ mod tests { #[test] fn test_error_if_value_has_invalid_length_v0() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let transaction = drive.grove.start_transaction(); @@ -106,7 +106,7 @@ mod tests { #[test] fn test_value_is_set_v0() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let transaction = drive.grove.start_transaction(); diff --git a/packages/rs-drive/src/drive/credit_pools/epochs/credit_distribution_pools/get_epoch_processing_credits_for_distribution/v0/mod.rs b/packages/rs-drive/src/drive/credit_pools/epochs/credit_distribution_pools/get_epoch_processing_credits_for_distribution/v0/mod.rs index ad944b1d36..05782b23b2 100644 --- a/packages/rs-drive/src/drive/credit_pools/epochs/credit_distribution_pools/get_epoch_processing_credits_for_distribution/v0/mod.rs +++ b/packages/rs-drive/src/drive/credit_pools/epochs/credit_distribution_pools/get_epoch_processing_credits_for_distribution/v0/mod.rs @@ -54,7 +54,7 @@ mod tests { #[test] fn test_error_if_value_has_wrong_element_type() { let platform_version = PlatformVersion::latest(); - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let epoch = Epoch::new(0).unwrap(); diff --git a/packages/rs-drive/src/drive/credit_pools/epochs/credit_distribution_pools/get_epoch_storage_credits_for_distribution/v0/mod.rs b/packages/rs-drive/src/drive/credit_pools/epochs/credit_distribution_pools/get_epoch_storage_credits_for_distribution/v0/mod.rs index f52962d3be..c12720a8b6 100644 --- a/packages/rs-drive/src/drive/credit_pools/epochs/credit_distribution_pools/get_epoch_storage_credits_for_distribution/v0/mod.rs +++ b/packages/rs-drive/src/drive/credit_pools/epochs/credit_distribution_pools/get_epoch_storage_credits_for_distribution/v0/mod.rs @@ -53,7 +53,7 @@ mod tests { #[test] fn test_error_if_epoch_tree_is_not_initiated_v0() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::latest(); @@ -75,7 +75,7 @@ mod tests { #[test] fn test_error_if_value_has_invalid_length_v0() { let platform_version = PlatformVersion::latest(); - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let epoch = Epoch::new(0).unwrap(); diff --git a/packages/rs-drive/src/drive/credit_pools/epochs/credit_distribution_pools/get_epoch_total_credits_for_distribution/v0/mod.rs b/packages/rs-drive/src/drive/credit_pools/epochs/credit_distribution_pools/get_epoch_total_credits_for_distribution/v0/mod.rs index 9e6cf57e43..ea9fce1ef1 100644 --- a/packages/rs-drive/src/drive/credit_pools/epochs/credit_distribution_pools/get_epoch_total_credits_for_distribution/v0/mod.rs +++ b/packages/rs-drive/src/drive/credit_pools/epochs/credit_distribution_pools/get_epoch_total_credits_for_distribution/v0/mod.rs @@ -48,7 +48,7 @@ mod tests { #[test] fn test_get_epoch_total_credits_for_distribution_v0() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::latest(); diff --git a/packages/rs-drive/src/drive/credit_pools/epochs/has_epoch_tree_exists.rs b/packages/rs-drive/src/drive/credit_pools/epochs/has_epoch_tree_exists.rs index 7fca44958e..7106d15a79 100644 --- a/packages/rs-drive/src/drive/credit_pools/epochs/has_epoch_tree_exists.rs +++ b/packages/rs-drive/src/drive/credit_pools/epochs/has_epoch_tree_exists.rs @@ -41,7 +41,7 @@ mod tests { #[test] fn test_return_true_if_tree_exists() { let platform_version = PlatformVersion::latest(); - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let epoch_tree = Epoch::new(GENESIS_EPOCH_INDEX).unwrap(); @@ -59,7 +59,7 @@ mod tests { // default will be 40 epochs per era // 50 eras // = 2000 - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let epoch_tree = Epoch::new(2000 + 1).unwrap(); diff --git a/packages/rs-drive/src/drive/credit_pools/epochs/operations_factory.rs b/packages/rs-drive/src/drive/credit_pools/epochs/operations_factory.rs index 8274656c2b..81248a8e5a 100644 --- a/packages/rs-drive/src/drive/credit_pools/epochs/operations_factory.rs +++ b/packages/rs-drive/src/drive/credit_pools/epochs/operations_factory.rs @@ -315,7 +315,7 @@ mod tests { #[test] fn test_increment_block_count_to_1_if_proposers_tree_is_not_committed() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::first(); @@ -358,7 +358,7 @@ mod tests { #[test] fn test_existing_block_count_is_incremented() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::first(); @@ -445,7 +445,7 @@ mod tests { #[test] fn test_values_are_set() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::first(); @@ -480,7 +480,7 @@ mod tests { #[test] fn test_values_are_set() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::first(); @@ -561,7 +561,7 @@ mod tests { #[test] fn test_values_are_deleted() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::first(); @@ -633,7 +633,7 @@ mod tests { #[test] fn test_value_is_set() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::first(); @@ -668,7 +668,7 @@ mod tests { #[test] fn test_update_start_time() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::first(); @@ -694,7 +694,7 @@ mod tests { #[test] fn test_update_epoch_start_block_height() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::first(); @@ -718,7 +718,7 @@ mod tests { #[test] fn test_update_epoch_start_block_core_height() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::first(); @@ -745,7 +745,7 @@ mod tests { #[test] fn test_error_if_epoch_tree_is_not_initiated() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::first(); @@ -767,7 +767,7 @@ mod tests { #[test] fn test_value_is_set() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::first(); @@ -801,7 +801,7 @@ mod tests { #[test] fn test_error_if_epoch_tree_is_not_initiated() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::first(); @@ -823,7 +823,7 @@ mod tests { #[test] fn test_value_is_set() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::first(); @@ -857,7 +857,7 @@ mod tests { #[test] fn test_values_has_been_deleted() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::first(); @@ -905,7 +905,7 @@ mod tests { #[test] fn test_values_are_being_deleted() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let epoch = Epoch::new(0).unwrap(); diff --git a/packages/rs-drive/src/drive/credit_pools/epochs/proposers/fetch_epoch_proposers/v0/mod.rs b/packages/rs-drive/src/drive/credit_pools/epochs/proposers/fetch_epoch_proposers/v0/mod.rs index e86547c225..992cb31dd9 100644 --- a/packages/rs-drive/src/drive/credit_pools/epochs/proposers/fetch_epoch_proposers/v0/mod.rs +++ b/packages/rs-drive/src/drive/credit_pools/epochs/proposers/fetch_epoch_proposers/v0/mod.rs @@ -135,7 +135,7 @@ mod tests { #[test] fn test_value() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let transaction = drive.grove.start_transaction(); diff --git a/packages/rs-drive/src/drive/credit_pools/epochs/proposers/get_epochs_proposer_block_count/v0/mod.rs b/packages/rs-drive/src/drive/credit_pools/epochs/proposers/get_epochs_proposer_block_count/v0/mod.rs index 9ebe6efdc3..8475308ffd 100644 --- a/packages/rs-drive/src/drive/credit_pools/epochs/proposers/get_epochs_proposer_block_count/v0/mod.rs +++ b/packages/rs-drive/src/drive/credit_pools/epochs/proposers/get_epochs_proposer_block_count/v0/mod.rs @@ -63,7 +63,7 @@ mod tests { #[test] fn test_error_if_value_has_invalid_length_v0() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let transaction = drive.grove.start_transaction(); @@ -100,7 +100,7 @@ mod tests { #[test] fn test_error_if_epoch_tree_is_not_initiated_v0() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let transaction = drive.grove.start_transaction(); diff --git a/packages/rs-drive/src/drive/credit_pools/epochs/proposers/is_epochs_proposers_tree_empty/mod.rs b/packages/rs-drive/src/drive/credit_pools/epochs/proposers/is_epochs_proposers_tree_empty/mod.rs index dad59b749e..a1266856f0 100644 --- a/packages/rs-drive/src/drive/credit_pools/epochs/proposers/is_epochs_proposers_tree_empty/mod.rs +++ b/packages/rs-drive/src/drive/credit_pools/epochs/proposers/is_epochs_proposers_tree_empty/mod.rs @@ -51,7 +51,7 @@ mod tests { #[test] fn test_check_if_empty() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let drive_version = DriveVersion::default(); let transaction = drive.grove.start_transaction(); diff --git a/packages/rs-drive/src/drive/credit_pools/epochs/proposers/prove_epoch_proposers/v0/mod.rs b/packages/rs-drive/src/drive/credit_pools/epochs/proposers/prove_epoch_proposers/v0/mod.rs index 396591cea5..8deba51b9b 100644 --- a/packages/rs-drive/src/drive/credit_pools/epochs/proposers/prove_epoch_proposers/v0/mod.rs +++ b/packages/rs-drive/src/drive/credit_pools/epochs/proposers/prove_epoch_proposers/v0/mod.rs @@ -63,7 +63,7 @@ mod tests { #[test] fn test_value() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let transaction = drive.grove.start_transaction(); diff --git a/packages/rs-drive/src/drive/credit_pools/epochs/start_block/mod.rs b/packages/rs-drive/src/drive/credit_pools/epochs/start_block/mod.rs index bea94b346e..2788fd9ff2 100644 --- a/packages/rs-drive/src/drive/credit_pools/epochs/start_block/mod.rs +++ b/packages/rs-drive/src/drive/credit_pools/epochs/start_block/mod.rs @@ -43,7 +43,7 @@ mod tests { #[test] fn test_error_if_epoch_tree_is_not_initiated() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::latest(); @@ -64,7 +64,7 @@ mod tests { #[test] fn test_error_if_value_is_not_set() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::latest(); @@ -79,7 +79,7 @@ mod tests { #[test] fn test_error_if_value_has_invalid_length() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::latest(); @@ -110,7 +110,7 @@ mod tests { #[test] fn test_error_if_value_has_invalid_length_core_height() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::latest(); @@ -144,7 +144,7 @@ mod tests { #[test] fn test_error_if_element_has_invalid_type() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::latest(); @@ -175,7 +175,7 @@ mod tests { #[test] fn test_error_if_element_has_invalid_type_core_height() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let transaction = drive.grove.start_transaction(); @@ -218,7 +218,7 @@ mod tests { #[test] fn test_next_block_height() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::latest(); @@ -258,7 +258,7 @@ mod tests { #[test] fn test_none_if_there_are_no_start_block_heights() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::latest(); @@ -277,7 +277,7 @@ mod tests { #[test] fn test_none_if_start_block_height_is_outside_of_specified_epoch_range() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -309,7 +309,7 @@ mod tests { #[test] fn test_start_block_height_in_two_epoch_in_case_of_gaps() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); diff --git a/packages/rs-drive/src/drive/credit_pools/epochs/start_time/get_epoch_start_time/v0/mod.rs b/packages/rs-drive/src/drive/credit_pools/epochs/start_time/get_epoch_start_time/v0/mod.rs index 65414461dd..390a878b74 100644 --- a/packages/rs-drive/src/drive/credit_pools/epochs/start_time/get_epoch_start_time/v0/mod.rs +++ b/packages/rs-drive/src/drive/credit_pools/epochs/start_time/get_epoch_start_time/v0/mod.rs @@ -56,7 +56,7 @@ mod tests { #[test] fn test_error_if_epoch_tree_is_not_initiated() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::latest(); @@ -77,7 +77,7 @@ mod tests { #[test] fn test_error_if_value_is_not_set() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::latest(); @@ -92,7 +92,7 @@ mod tests { #[test] fn test_error_if_element_has_invalid_type() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::latest(); @@ -122,7 +122,7 @@ mod tests { #[test] fn test_error_if_value_has_invalid_length() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::latest(); diff --git a/packages/rs-drive/src/drive/credit_pools/mod.rs b/packages/rs-drive/src/drive/credit_pools/mod.rs index 398980bc91..9696cce681 100644 --- a/packages/rs-drive/src/drive/credit_pools/mod.rs +++ b/packages/rs-drive/src/drive/credit_pools/mod.rs @@ -195,7 +195,7 @@ mod tests { #[test] fn should_do_nothing_if_credits_per_epoch_are_empty() { let platform_version = PlatformVersion::latest(); - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let credits_per_epoch = SignedCreditsPerEpoch::default(); @@ -216,7 +216,7 @@ mod tests { #[test] fn should_update_epoch_storage_fee_pools() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); const TO_EPOCH_INDEX: EpochIndex = 10; @@ -281,7 +281,7 @@ mod tests { #[test] fn should_subtract_negative_credits_from_future_epochs() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::latest(); diff --git a/packages/rs-drive/src/drive/credit_pools/operations.rs b/packages/rs-drive/src/drive/credit_pools/operations.rs index 7dd78802b5..9aad69bf5b 100644 --- a/packages/rs-drive/src/drive/credit_pools/operations.rs +++ b/packages/rs-drive/src/drive/credit_pools/operations.rs @@ -52,7 +52,7 @@ mod tests { #[test] fn test_values_are_set() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::latest(); @@ -65,7 +65,7 @@ mod tests { #[test] fn test_epoch_trees_are_created() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let transaction = drive.grove.start_transaction(); @@ -106,7 +106,7 @@ mod tests { #[test] fn test_update_and_get_value() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::latest(); diff --git a/packages/rs-drive/src/drive/credit_pools/pending_epoch_refunds/methods/add_delete_pending_epoch_refunds_except_specified/v0/mod.rs b/packages/rs-drive/src/drive/credit_pools/pending_epoch_refunds/methods/add_delete_pending_epoch_refunds_except_specified/v0/mod.rs index 49cf61635e..21b200ade4 100644 --- a/packages/rs-drive/src/drive/credit_pools/pending_epoch_refunds/methods/add_delete_pending_epoch_refunds_except_specified/v0/mod.rs +++ b/packages/rs-drive/src/drive/credit_pools/pending_epoch_refunds/methods/add_delete_pending_epoch_refunds_except_specified/v0/mod.rs @@ -74,7 +74,7 @@ mod tests { #[test] fn should_add_delete_operations_v0() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let transaction = drive.grove.start_transaction(); diff --git a/packages/rs-drive/src/drive/credit_pools/pending_epoch_refunds/methods/fetch_and_add_pending_epoch_refunds_to_collection/v0/mod.rs b/packages/rs-drive/src/drive/credit_pools/pending_epoch_refunds/methods/fetch_and_add_pending_epoch_refunds_to_collection/v0/mod.rs index c593f5d49f..737cadc748 100644 --- a/packages/rs-drive/src/drive/credit_pools/pending_epoch_refunds/methods/fetch_and_add_pending_epoch_refunds_to_collection/v0/mod.rs +++ b/packages/rs-drive/src/drive/credit_pools/pending_epoch_refunds/methods/fetch_and_add_pending_epoch_refunds_to_collection/v0/mod.rs @@ -87,7 +87,7 @@ mod tests { #[test] fn should_fetch_and_merge_pending_updates_v0() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let transaction = drive.grove.start_transaction(); diff --git a/packages/rs-drive/src/drive/credit_pools/storage_fee_distribution_pool/get_storage_fees_from_distribution_pool/v0/mod.rs b/packages/rs-drive/src/drive/credit_pools/storage_fee_distribution_pool/get_storage_fees_from_distribution_pool/v0/mod.rs index 98e8dac0f1..ee90eec06c 100644 --- a/packages/rs-drive/src/drive/credit_pools/storage_fee_distribution_pool/get_storage_fees_from_distribution_pool/v0/mod.rs +++ b/packages/rs-drive/src/drive/credit_pools/storage_fee_distribution_pool/get_storage_fees_from_distribution_pool/v0/mod.rs @@ -68,7 +68,7 @@ mod tests { #[test] fn test_error_if_wrong_value_encoded() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::first(); @@ -96,7 +96,7 @@ mod tests { #[test] fn test_error_if_storage_pool_is_not_initiated() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); let platform_version = PlatformVersion::first(); diff --git a/packages/rs-drive/src/drive/credit_pools/unpaid_epoch/get_unpaid_epoch_index/v0/mod.rs b/packages/rs-drive/src/drive/credit_pools/unpaid_epoch/get_unpaid_epoch_index/v0/mod.rs index a9c1e14a2d..bcfdaf59b1 100644 --- a/packages/rs-drive/src/drive/credit_pools/unpaid_epoch/get_unpaid_epoch_index/v0/mod.rs +++ b/packages/rs-drive/src/drive/credit_pools/unpaid_epoch/get_unpaid_epoch_index/v0/mod.rs @@ -71,7 +71,7 @@ mod tests { #[test] fn test_error_if_element_has_invalid_type() { let platform_version = PlatformVersion::latest(); - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); // We need to first delete the item, because you can not replace an item with a tree @@ -111,7 +111,7 @@ mod tests { #[test] fn test_error_if_value_has_invalid_length() { let platform_version = PlatformVersion::latest(); - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); drive diff --git a/packages/rs-drive/src/drive/document/delete/mod.rs b/packages/rs-drive/src/drive/document/delete/mod.rs index 07d7326135..3f64724bfd 100644 --- a/packages/rs-drive/src/drive/document/delete/mod.rs +++ b/packages/rs-drive/src/drive/document/delete/mod.rs @@ -181,7 +181,7 @@ mod tests { #[test] fn test_add_and_remove_family_one_document() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let db_transaction = drive.grove.start_transaction(); @@ -322,7 +322,7 @@ mod tests { #[test] fn test_add_and_remove_family_documents() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let db_transaction = drive.grove.start_transaction(); @@ -506,7 +506,7 @@ mod tests { #[test] fn test_add_and_remove_family_documents_with_empty_fields() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let db_transaction = drive.grove.start_transaction(); @@ -781,7 +781,7 @@ mod tests { #[test] fn test_delete_dashpay_documents() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let db_transaction = drive.grove.start_transaction(); @@ -881,7 +881,7 @@ mod tests { #[test] fn test_delete_dashpay_documents_without_apply() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let db_transaction = drive.grove.start_transaction(); diff --git a/packages/rs-drive/src/drive/document/insert/mod.rs b/packages/rs-drive/src/drive/document/insert/mod.rs index 6b88440bf2..ae327e8c30 100644 --- a/packages/rs-drive/src/drive/document/insert/mod.rs +++ b/packages/rs-drive/src/drive/document/insert/mod.rs @@ -154,7 +154,7 @@ mod tests { #[test] fn test_add_dashpay_documents() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let db_transaction = drive.grove.start_transaction(); @@ -250,7 +250,7 @@ mod tests { #[test] fn test_add_dashpay_contact_request_with_fee() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let db_transaction = drive.grove.start_transaction(); @@ -315,7 +315,7 @@ mod tests { #[test] fn test_add_dashpay_profile_with_fee() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let db_transaction = drive.grove.start_transaction(); @@ -380,7 +380,7 @@ mod tests { #[test] fn test_add_dashpay_profile_average_case_cost_fee() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let db_transaction = drive.grove.start_transaction(); @@ -445,7 +445,7 @@ mod tests { #[test] fn test_unknown_state_cost_dashpay_fee_for_add_documents() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let db_transaction = drive.grove.start_transaction(); @@ -521,7 +521,7 @@ mod tests { #[test] fn test_add_dashpay_fee_for_documents_detail() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let db_transaction = drive.grove.start_transaction(); @@ -614,7 +614,7 @@ mod tests { #[test] fn test_add_dpns_document_with_fee() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let db_transaction = drive.grove.start_transaction(); diff --git a/packages/rs-drive/src/drive/document/mod.rs b/packages/rs-drive/src/drive/document/mod.rs index 08a8a4be48..fb0cd21529 100644 --- a/packages/rs-drive/src/drive/document/mod.rs +++ b/packages/rs-drive/src/drive/document/mod.rs @@ -155,7 +155,7 @@ pub(crate) mod tests { /// Setup Dashpay pub fn setup_dashpay(_prefix: &str, mutable_contact_requests: bool) -> (Drive, DataContract) { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); diff --git a/packages/rs-drive/src/drive/document/update/mod.rs b/packages/rs-drive/src/drive/document/update/mod.rs index 313af57de8..e7dc236f43 100644 --- a/packages/rs-drive/src/drive/document/update/mod.rs +++ b/packages/rs-drive/src/drive/document/update/mod.rs @@ -514,7 +514,7 @@ mod tests { #[test] fn test_create_update_and_delete_document() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -673,7 +673,7 @@ mod tests { #[test] fn test_modify_dashpay_contact_request() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let db_transaction = drive.grove.start_transaction(); @@ -762,7 +762,7 @@ mod tests { #[test] fn test_update_dashpay_profile_with_history() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let db_transaction = drive.grove.start_transaction(); @@ -1815,7 +1815,7 @@ mod tests { #[test] fn test_update_document_without_apply_should_calculate_storage_fees() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); diff --git a/packages/rs-drive/src/drive/identity/balance/prove.rs b/packages/rs-drive/src/drive/identity/balance/prove.rs index 81542d575a..0fcdd61cb5 100644 --- a/packages/rs-drive/src/drive/identity/balance/prove.rs +++ b/packages/rs-drive/src/drive/identity/balance/prove.rs @@ -70,7 +70,7 @@ mod tests { #[test] fn should_prove_a_single_identity_balance() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::first(); @@ -113,7 +113,7 @@ mod tests { #[test] fn should_prove_multiple_identity_balances() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let identities: BTreeMap<[u8; 32], Identity> = Identity::random_identities(10, 3, Some(14), platform_version) diff --git a/packages/rs-drive/src/drive/identity/balance/update.rs b/packages/rs-drive/src/drive/identity/balance/update.rs index df5644b546..dc7c94e3e7 100644 --- a/packages/rs-drive/src/drive/identity/balance/update.rs +++ b/packages/rs-drive/src/drive/identity/balance/update.rs @@ -22,7 +22,7 @@ mod tests { #[test] fn should_add_to_balance() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -89,7 +89,7 @@ mod tests { #[test] fn should_fail_if_balance_is_not_persisted() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -111,7 +111,7 @@ mod tests { #[test] fn should_deduct_from_debt_if_balance_is_nil() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let identity = create_test_identity(&drive, [0; 32], Some(1), None, platform_version) @@ -194,7 +194,7 @@ mod tests { #[test] fn should_keep_nil_balance_and_reduce_debt_if_added_balance_is_lower() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let identity = create_test_identity(&drive, [0; 32], Some(1), None, platform_version) .expect("expected an identity"); @@ -273,7 +273,7 @@ mod tests { #[test] fn should_estimate_costs_without_state() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -337,7 +337,7 @@ mod tests { #[test] fn should_remove_from_balance() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -405,7 +405,7 @@ mod tests { #[test] fn should_estimated_costs_without_state() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -481,7 +481,7 @@ mod tests { #[test] fn should_do_nothing_if_there_is_no_balance_change() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -505,7 +505,7 @@ mod tests { #[test] fn should_add_to_balance() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -570,7 +570,7 @@ mod tests { #[test] fn should_fail_if_balance_is_not_persisted() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -590,7 +590,7 @@ mod tests { #[test] fn should_deduct_from_debt_if_balance_is_nil() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -665,7 +665,7 @@ mod tests { #[test] fn should_keep_nil_balance_and_reduce_debt_if_added_balance_is_lower() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -734,7 +734,7 @@ mod tests { #[test] fn should_remove_from_balance_less_amount() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -788,7 +788,7 @@ mod tests { #[test] fn should_remove_from_balance_bigger_amount_and_get_into_debt() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -861,7 +861,7 @@ mod tests { #[test] fn should_return_error_if_required_amount_bigger_than_balance() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); diff --git a/packages/rs-drive/src/drive/identity/fetch/full_identity/mod.rs b/packages/rs-drive/src/drive/identity/fetch/full_identity/mod.rs index 95dc07e00d..ebfe8128a9 100644 --- a/packages/rs-drive/src/drive/identity/fetch/full_identity/mod.rs +++ b/packages/rs-drive/src/drive/identity/fetch/full_identity/mod.rs @@ -17,7 +17,7 @@ mod tests { #[test] fn should_get_full_identities() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let identities: BTreeMap<[u8; 32], Option> = @@ -60,7 +60,7 @@ mod tests { #[test] fn should_return_none_if_identity_is_not_present() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -80,7 +80,7 @@ mod tests { #[test] fn should_get_a_full_identity() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let identity = Identity::random_identity(3, Some(14), platform_version) diff --git a/packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identities/v0/mod.rs b/packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identities/v0/mod.rs index 66e2899199..1bac303eee 100644 --- a/packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identities/v0/mod.rs +++ b/packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identities/v0/mod.rs @@ -38,7 +38,7 @@ mod tests { #[test] fn should_prove_two_full_identities_query_no_tx() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let identities: BTreeMap<[u8; 32], Option> = @@ -111,7 +111,7 @@ mod tests { #[test] fn should_prove_ten_full_identities_query_no_tx() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let identities: BTreeMap<[u8; 32], Option> = diff --git a/packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identities_by_unique_public_key_hashes/v0/mod.rs b/packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identities_by_unique_public_key_hashes/v0/mod.rs index b7be9365d3..44f7965678 100644 --- a/packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identities_by_unique_public_key_hashes/v0/mod.rs +++ b/packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identities_by_unique_public_key_hashes/v0/mod.rs @@ -63,7 +63,7 @@ mod tests { #[test] fn should_prove_multiple_identities() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); diff --git a/packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identity/v0/mod.rs b/packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identity/v0/mod.rs index 4d3676d9b1..1f8cc5580c 100644 --- a/packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identity/v0/mod.rs +++ b/packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identity/v0/mod.rs @@ -37,7 +37,7 @@ mod tests { #[test] fn should_prove_full_identity_query_no_tx() { let platform_version = PlatformVersion::latest(); - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let identity = Identity::random_identity(5, Some(14), platform_version) .expect("expected a random identity"); diff --git a/packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identity_by_unique_public_key_hash/v0/mod.rs b/packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identity_by_unique_public_key_hash/v0/mod.rs index 3df63086c2..f474fa5231 100644 --- a/packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identity_by_unique_public_key_hash/v0/mod.rs +++ b/packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identity_by_unique_public_key_hash/v0/mod.rs @@ -57,7 +57,7 @@ mod tests { #[test] fn should_prove_a_single_identity() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::first(); diff --git a/packages/rs-drive/src/drive/identity/fetch/prove/prove_identity_id_by_unique_public_key_hash/v0/mod.rs b/packages/rs-drive/src/drive/identity/fetch/prove/prove_identity_id_by_unique_public_key_hash/v0/mod.rs index cd41d83e24..8900c2e2dc 100644 --- a/packages/rs-drive/src/drive/identity/fetch/prove/prove_identity_id_by_unique_public_key_hash/v0/mod.rs +++ b/packages/rs-drive/src/drive/identity/fetch/prove/prove_identity_id_by_unique_public_key_hash/v0/mod.rs @@ -32,7 +32,7 @@ mod tests { #[test] fn should_prove_a_single_identity_id() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let identity = Identity::random_identity(3, Some(14), platform_version) .expect("expected a random identity"); diff --git a/packages/rs-drive/src/drive/identity/fetch/prove/prove_identity_ids_by_unique_public_key_hashes/v0/mod.rs b/packages/rs-drive/src/drive/identity/fetch/prove/prove_identity_ids_by_unique_public_key_hashes/v0/mod.rs index 28a7cfa35c..1b4636e6b5 100644 --- a/packages/rs-drive/src/drive/identity/fetch/prove/prove_identity_ids_by_unique_public_key_hashes/v0/mod.rs +++ b/packages/rs-drive/src/drive/identity/fetch/prove/prove_identity_ids_by_unique_public_key_hashes/v0/mod.rs @@ -38,7 +38,7 @@ mod tests { #[test] fn should_prove_multiple_identity_ids() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let identities: BTreeMap<[u8; 32], Identity> = diff --git a/packages/rs-drive/src/drive/identity/insert/add_new_identity/v0/mod.rs b/packages/rs-drive/src/drive/identity/insert/add_new_identity/v0/mod.rs index 6b6dfbf6d0..f756234431 100644 --- a/packages/rs-drive/src/drive/identity/insert/add_new_identity/v0/mod.rs +++ b/packages/rs-drive/src/drive/identity/insert/add_new_identity/v0/mod.rs @@ -320,7 +320,7 @@ mod tests { #[test] fn test_insert_identity_v0() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let db_transaction = drive.grove.start_transaction(); diff --git a/packages/rs-drive/src/drive/identity/update/mod.rs b/packages/rs-drive/src/drive/identity/update/mod.rs index b28d7f3134..c846d8d43d 100644 --- a/packages/rs-drive/src/drive/identity/update/mod.rs +++ b/packages/rs-drive/src/drive/identity/update/mod.rs @@ -21,7 +21,7 @@ mod tests { #[test] fn should_add_one_new_key_to_identity() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::first(); @@ -81,7 +81,7 @@ mod tests { #[test] fn should_add_two_dozen_new_keys_to_identity() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::first(); @@ -141,7 +141,7 @@ mod tests { #[test] fn should_estimated_costs_without_state() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::first(); @@ -200,7 +200,7 @@ mod tests { #[test] fn should_disable_a_few_keys() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::first(); @@ -279,7 +279,7 @@ mod tests { #[test] fn should_estimated_costs_without_state() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::first(); @@ -328,7 +328,7 @@ mod tests { #[test] fn estimated_costs_should_have_same_storage_cost() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::first(); @@ -387,7 +387,7 @@ mod tests { #[test] fn should_update_revision() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::first(); @@ -447,7 +447,7 @@ mod tests { #[test] fn should_estimated_costs_without_state() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::first(); diff --git a/packages/rs-drive/src/drive/identity/withdrawals/document/fetch_oldest_withdrawal_documents_by_status/v0/mod.rs b/packages/rs-drive/src/drive/identity/withdrawals/document/fetch_oldest_withdrawal_documents_by_status/v0/mod.rs index b60e41be44..4e611e39fb 100644 --- a/packages/rs-drive/src/drive/identity/withdrawals/document/fetch_oldest_withdrawal_documents_by_status/v0/mod.rs +++ b/packages/rs-drive/src/drive/identity/withdrawals/document/fetch_oldest_withdrawal_documents_by_status/v0/mod.rs @@ -113,7 +113,7 @@ mod tests { #[test] fn test_return_list_of_documents() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); diff --git a/packages/rs-drive/src/drive/identity/withdrawals/document/find_withdrawal_documents_by_status_and_transaction_indices/v0/mod.rs b/packages/rs-drive/src/drive/identity/withdrawals/document/find_withdrawal_documents_by_status_and_transaction_indices/v0/mod.rs index e6b4a8e640..ea92ef5a67 100644 --- a/packages/rs-drive/src/drive/identity/withdrawals/document/find_withdrawal_documents_by_status_and_transaction_indices/v0/mod.rs +++ b/packages/rs-drive/src/drive/identity/withdrawals/document/find_withdrawal_documents_by_status_and_transaction_indices/v0/mod.rs @@ -116,7 +116,7 @@ mod tests { #[test] fn test_find_pooled_withdrawal_documents_by_transaction_index() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); diff --git a/packages/rs-drive/src/drive/identity/withdrawals/paths.rs b/packages/rs-drive/src/drive/identity/withdrawals/paths.rs index fd1e3d0405..3d85be63b3 100644 --- a/packages/rs-drive/src/drive/identity/withdrawals/paths.rs +++ b/packages/rs-drive/src/drive/identity/withdrawals/paths.rs @@ -10,6 +10,8 @@ pub const WITHDRAWAL_TRANSACTIONS_NEXT_INDEX_KEY: [u8; 1] = [0]; pub const WITHDRAWAL_TRANSACTIONS_QUEUE_KEY: [u8; 1] = [1]; /// constant id for subtree containing the sum of withdrawals pub const WITHDRAWAL_TRANSACTIONS_SUM_AMOUNT_TREE_KEY: [u8; 1] = [2]; +/// constant id for subtree containing the untied withdrawal transactions after they were broadcasted +pub const WITHDRAWAL_TRANSACTIONS_BROADCASTED_KEY: [u8; 1] = [3]; impl Drive { /// Add operations for creating initial withdrawal state structure @@ -33,6 +35,10 @@ impl Drive { vec![vec![RootTree::WithdrawalTransactions as u8]], WITHDRAWAL_TRANSACTIONS_SUM_AMOUNT_TREE_KEY.to_vec(), ); + batch.add_insert_empty_sum_tree( + vec![vec![RootTree::WithdrawalTransactions as u8]], + WITHDRAWAL_TRANSACTIONS_BROADCASTED_KEY.to_vec(), + ); } } } @@ -78,3 +84,19 @@ pub fn get_withdrawal_transactions_sum_tree_path() -> [&'static [u8]; 2] { &WITHDRAWAL_TRANSACTIONS_SUM_AMOUNT_TREE_KEY, ] } + +/// Helper function to get the withdrawal transactions broadcasted path as Vec +pub fn get_withdrawal_transactions_broadcasted_path_vec() -> Vec> { + vec![ + vec![RootTree::WithdrawalTransactions as u8], + WITHDRAWAL_TRANSACTIONS_BROADCASTED_KEY.to_vec(), + ] +} + +/// Helper function to get the withdrawal transactions broadcasted path as [u8] +pub fn get_withdrawal_transactions_broadcasted_path() -> [&'static [u8]; 2] { + [ + Into::<&[u8; 1]>::into(RootTree::WithdrawalTransactions), + &WITHDRAWAL_TRANSACTIONS_BROADCASTED_KEY, + ] +} diff --git a/packages/rs-drive/src/drive/identity/withdrawals/transaction/index/mod.rs b/packages/rs-drive/src/drive/identity/withdrawals/transaction/index/mod.rs index 9928d324da..a2dafcb7cb 100644 --- a/packages/rs-drive/src/drive/identity/withdrawals/transaction/index/mod.rs +++ b/packages/rs-drive/src/drive/identity/withdrawals/transaction/index/mod.rs @@ -14,7 +14,7 @@ mod tests { #[test] fn test_next_withdrawal_transaction_index() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -59,7 +59,7 @@ mod tests { #[test] fn test_initial_withdrawal_transaction_index() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); diff --git a/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/dequeue_untied_withdrawal_transactions/v0/mod.rs b/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/dequeue_untied_withdrawal_transactions/v0/mod.rs index 6edeaa9822..5911ed5cda 100644 --- a/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/dequeue_untied_withdrawal_transactions/v0/mod.rs +++ b/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/dequeue_untied_withdrawal_transactions/v0/mod.rs @@ -69,12 +69,14 @@ impl Drive { }) .collect::, Error>>()?; - if !withdrawal_transactions.is_empty() { - for (index, _) in withdrawal_transactions.iter() { - drive_operation_types.push(DriveOperation::WithdrawalOperation( - WithdrawalOperationType::DeleteWithdrawalTransaction { index: *index }, - )); - } + let indexes: Vec = withdrawal_transactions + .iter() + .map(|(index, _)| *index) + .collect(); + if !indexes.is_empty() { + drive_operation_types.push(DriveOperation::WithdrawalOperation( + WithdrawalOperationType::MoveWithdrawalTransactionsToBroadcasted { indexes }, + )); } Ok(withdrawal_transactions) diff --git a/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/mod.rs b/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/mod.rs index 8926ea5c0c..b7817dd338 100644 --- a/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/mod.rs +++ b/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/mod.rs @@ -1,8 +1,14 @@ -/// This module dedicated for a versioned add_enqueue_untied_withdrawal_transaction_operations +/// This module is dedicated for a versioned add_enqueue_untied_withdrawal_transaction_operations pub mod add_enqueue_untied_withdrawal_transaction_operations; -/// This module dedicated for a versioned dequeue_untied_withdrawal_transactions +/// This module is dedicated for a versioned dequeue_untied_withdrawal_transactions pub mod dequeue_untied_withdrawal_transactions; +/// This module is dedicated to removing broadcasted withdrawal transactions after core says they were completed +pub mod remove_broadcasted_withdrawal_transactions_after_completion; + +/// This module is dedicated to moving broadcasted withdrawal transactions back to the main queue +pub mod move_broadcasted_withdrawal_transactions_back_to_queue_operations; + #[cfg(test)] mod tests { use crate::util::batch::DriveOperation; @@ -10,14 +16,13 @@ mod tests { use dpp::block::epoch::Epoch; use crate::util::test_helpers::setup::setup_drive_with_initial_state_structure; - use dpp::version::PlatformVersion; use dpp::withdrawal::{WithdrawalTransactionIndex, WithdrawalTransactionIndexAndBytes}; + use platform_version::version::PlatformVersion; #[test] fn test_enqueue_and_dequeue() { - let drive = setup_drive_with_initial_state_structure(); - let platform_version = PlatformVersion::latest(); + let drive = setup_drive_with_initial_state_structure(None); let transaction = drive.grove.start_transaction(); diff --git a/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/move_broadcasted_withdrawal_transactions_back_to_queue_operations/mod.rs b/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/move_broadcasted_withdrawal_transactions_back_to_queue_operations/mod.rs new file mode 100644 index 0000000000..d7ca0deb45 --- /dev/null +++ b/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/move_broadcasted_withdrawal_transactions_back_to_queue_operations/mod.rs @@ -0,0 +1,43 @@ +use crate::drive::Drive; +use crate::error::drive::DriveError; +use crate::error::Error; +use crate::util::batch::DriveOperation; +use dpp::withdrawal::WithdrawalTransactionIndex; +use platform_version::version::PlatformVersion; + +mod v0; + +impl Drive { + /// Moves broadcasted withdrawal transactions back to the queue + pub fn move_broadcasted_withdrawal_transactions_back_to_queue_operations( + &self, + indexes: Vec, + drive_operation_types: &mut Vec, + platform_version: &PlatformVersion, + ) -> Result<(), Error> { + match platform_version + .drive + .methods + .identity + .withdrawals + .transaction + .queue + .move_broadcasted_withdrawal_transactions_back_to_queue_operations + { + 0 => { + self.move_broadcasted_withdrawal_transactions_back_to_queue_operations_v0( + indexes, + drive_operation_types, + ); + + Ok(()) + } + version => Err(Error::Drive(DriveError::UnknownVersionMismatch { + method: "move_broadcasted_withdrawal_transactions_back_to_queue_operations" + .to_string(), + known_versions: vec![0], + received: version, + })), + } + } +} diff --git a/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/move_broadcasted_withdrawal_transactions_back_to_queue_operations/v0/mod.rs b/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/move_broadcasted_withdrawal_transactions_back_to_queue_operations/v0/mod.rs new file mode 100644 index 0000000000..7fc17d4d8a --- /dev/null +++ b/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/move_broadcasted_withdrawal_transactions_back_to_queue_operations/v0/mod.rs @@ -0,0 +1,25 @@ +use crate::drive::Drive; +use crate::util::batch::drive_op_batch::WithdrawalOperationType; +use crate::util::batch::DriveOperation; +use dpp::withdrawal::WithdrawalTransactionIndex; + +impl Drive { + pub(super) fn move_broadcasted_withdrawal_transactions_back_to_queue_operations_v0( + &self, + indexes: Vec, + drive_operation_types: &mut Vec, + ) { + if !indexes.is_empty() { + tracing::trace!( + "Moving {} broadcasted withdrawal transactions back to the queue for resigning: {:?}", + indexes.len(), + indexes + ); + drive_operation_types.push(DriveOperation::WithdrawalOperation( + WithdrawalOperationType::MoveBroadcastedWithdrawalTransactionsBackToQueueForResigning { + indexes, + }, + )); + } + } +} diff --git a/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/remove_broadcasted_withdrawal_transactions_after_completion/mod.rs b/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/remove_broadcasted_withdrawal_transactions_after_completion/mod.rs new file mode 100644 index 0000000000..a3f0c50dbc --- /dev/null +++ b/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/remove_broadcasted_withdrawal_transactions_after_completion/mod.rs @@ -0,0 +1,40 @@ +mod v0; + +use crate::drive::Drive; +use crate::error::drive::DriveError; +use crate::error::Error; +use crate::util::batch::DriveOperation; +use dpp::withdrawal::WithdrawalTransactionIndex; +use platform_version::version::PlatformVersion; + +impl Drive { + /// Get specified amount of withdrawal transactions from the DB + pub fn remove_broadcasted_withdrawal_transactions_after_completion_operations( + &self, + indexes: Vec, + drive_operation_types: &mut Vec, + platform_version: &PlatformVersion, + ) -> Result<(), Error> { + match platform_version + .drive + .methods + .identity + .withdrawals + .transaction + .queue + .remove_broadcasted_withdrawal_transactions_after_completion_operations + { + 0 => Ok(self + .remove_broadcasted_withdrawal_transactions_after_completion_operations_v0( + indexes, + drive_operation_types, + )), + version => Err(Error::Drive(DriveError::UnknownVersionMismatch { + method: "remove_broadcasted_withdrawal_transactions_after_completion_operations" + .to_string(), + known_versions: vec![0], + received: version, + })), + } + } +} diff --git a/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/remove_broadcasted_withdrawal_transactions_after_completion/v0/mod.rs b/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/remove_broadcasted_withdrawal_transactions_after_completion/v0/mod.rs new file mode 100644 index 0000000000..70cf03bad1 --- /dev/null +++ b/packages/rs-drive/src/drive/identity/withdrawals/transaction/queue/remove_broadcasted_withdrawal_transactions_after_completion/v0/mod.rs @@ -0,0 +1,15 @@ +use crate::drive::Drive; +use crate::util::batch::drive_op_batch::WithdrawalOperationType; +use crate::util::batch::DriveOperation; +use dpp::withdrawal::WithdrawalTransactionIndex; +impl Drive { + pub(super) fn remove_broadcasted_withdrawal_transactions_after_completion_operations_v0( + &self, + indexes: Vec, + drive_operation_types: &mut Vec, + ) { + drive_operation_types.push(DriveOperation::WithdrawalOperation( + WithdrawalOperationType::DeleteCompletedBroadcastedWithdrawalTransactions { indexes }, + )); + } +} diff --git a/packages/rs-drive/src/drive/initialization/genesis_core_height/mod.rs b/packages/rs-drive/src/drive/initialization/genesis_core_height/mod.rs index 5e8f21d95e..189bbac47a 100644 --- a/packages/rs-drive/src/drive/initialization/genesis_core_height/mod.rs +++ b/packages/rs-drive/src/drive/initialization/genesis_core_height/mod.rs @@ -81,7 +81,7 @@ mod tests { #[test] fn test_initial_state_structure_proper_heights() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let db_transaction = drive.grove.start_transaction(); diff --git a/packages/rs-drive/src/drive/initialization/v0/mod.rs b/packages/rs-drive/src/drive/initialization/v0/mod.rs index 39387184e5..ff30075d68 100644 --- a/packages/rs-drive/src/drive/initialization/v0/mod.rs +++ b/packages/rs-drive/src/drive/initialization/v0/mod.rs @@ -199,7 +199,7 @@ mod tests { #[test] fn test_create_initial_state_structure() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -228,7 +228,7 @@ mod tests { #[test] fn test_initial_state_structure_proper_heights() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let _db_transaction = drive.grove.start_transaction(); diff --git a/packages/rs-drive/src/drive/system/genesis_time/mod.rs b/packages/rs-drive/src/drive/system/genesis_time/mod.rs index cd888ccd31..9eee51529b 100644 --- a/packages/rs-drive/src/drive/system/genesis_time/mod.rs +++ b/packages/rs-drive/src/drive/system/genesis_time/mod.rs @@ -94,7 +94,7 @@ mod tests { #[test] fn should_return_some_if_genesis_time_is_persisted() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let genesis_time_ms = 100; diff --git a/packages/rs-drive/src/query/mod.rs b/packages/rs-drive/src/query/mod.rs index 456b4fc411..1d7cf24371 100644 --- a/packages/rs-drive/src/query/mod.rs +++ b/packages/rs-drive/src/query/mod.rs @@ -2038,7 +2038,7 @@ mod tests { } fn setup_family_birthday_contract() -> (Drive, DataContract) { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); diff --git a/packages/rs-drive/src/util/batch/drive_op_batch/mod.rs b/packages/rs-drive/src/util/batch/drive_op_batch/mod.rs index 144bcda787..abdd9f4cc6 100644 --- a/packages/rs-drive/src/util/batch/drive_op_batch/mod.rs +++ b/packages/rs-drive/src/util/batch/drive_op_batch/mod.rs @@ -229,7 +229,7 @@ mod tests { #[test] fn test_add_dashpay_documents() { - let drive: Drive = setup_drive_with_initial_state_structure(); + let drive: Drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); let mut drive_operations = vec![]; @@ -336,7 +336,7 @@ mod tests { #[test] fn test_add_multiple_dashpay_documents_individually_should_succeed() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -435,7 +435,7 @@ mod tests { #[test] fn test_add_multiple_dashpay_documents() { - let drive: Drive = setup_drive_with_initial_state_structure(); + let drive: Drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -568,7 +568,7 @@ mod tests { #[test] fn test_add_multiple_family_documents() { - let drive: Drive = setup_drive_with_initial_state_structure(); + let drive: Drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -679,7 +679,7 @@ mod tests { #[test] fn test_update_multiple_family_documents() { - let drive: Drive = setup_drive_with_initial_state_structure(); + let drive: Drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -897,7 +897,7 @@ mod tests { #[test] fn test_update_multiple_family_documents_with_index_being_removed_and_added() { - let drive: Drive = setup_drive_with_initial_state_structure(); + let drive: Drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); diff --git a/packages/rs-drive/src/util/batch/drive_op_batch/withdrawals.rs b/packages/rs-drive/src/util/batch/drive_op_batch/withdrawals.rs index a24c5b8efe..2a95fc39a7 100644 --- a/packages/rs-drive/src/util/batch/drive_op_batch/withdrawals.rs +++ b/packages/rs-drive/src/util/batch/drive_op_batch/withdrawals.rs @@ -1,22 +1,26 @@ use std::collections::HashMap; use crate::drive::identity::withdrawals::paths::{ - get_withdrawal_root_path_vec, get_withdrawal_transactions_queue_path, + get_withdrawal_root_path_vec, get_withdrawal_transactions_broadcasted_path, + get_withdrawal_transactions_broadcasted_path_vec, get_withdrawal_transactions_queue_path, get_withdrawal_transactions_queue_path_vec, get_withdrawal_transactions_sum_tree_path_vec, WITHDRAWAL_TRANSACTIONS_NEXT_INDEX_KEY, }; -use crate::util::grove_operations::{BatchDeleteApplyType, BatchInsertApplyType}; +use crate::util::grove_operations::{ + BatchDeleteApplyType, BatchInsertApplyType, BatchMoveApplyType, +}; use crate::util::object_size_info::PathKeyElementInfo; use crate::{drive::Drive, error::Error, fees::op::LowLevelDriveOperation}; use dpp::block::block_info::BlockInfo; use super::DriveLowLevelOperationConverter; +use crate::query::Query; use dpp::fee::{Credits, SignedCredits}; use dpp::prelude::TimestampMillis; use dpp::version::PlatformVersion; use dpp::withdrawal::{WithdrawalTransactionIndex, WithdrawalTransactionIndexAndBytes}; -use grovedb::Element; use grovedb::{batch::KeyInfoPath, EstimatedLayerInformation, TransactionArg}; +use grovedb::{Element, PathQuery, SizedQuery}; /// Operations for Withdrawals #[derive(Clone, Debug)] @@ -31,10 +35,20 @@ pub enum WithdrawalOperationType { /// transaction id bytes withdrawal_transactions: Vec, }, - /// Delete withdrawal - DeleteWithdrawalTransaction { - /// withdrawal transaction tuple with id and bytes - index: WithdrawalTransactionIndex, + /// Deletes the withdrawal transactions from the main queue and adds them to the broadcasted queue + MoveWithdrawalTransactionsToBroadcasted { + /// A vector of the indexes to be moved + indexes: Vec, + }, + /// Deletes the withdrawal transactions from the main queue and adds them to the broadcasted queue + MoveBroadcastedWithdrawalTransactionsBackToQueueForResigning { + /// A vector of the indexes to be moved + indexes: Vec, + }, + /// Deletes the withdrawal transactions from the broadcasted queue + DeleteCompletedBroadcastedWithdrawalTransactions { + /// A vector of the indexes to be deleted + indexes: Vec, }, /// Reserve an amount in the system for withdrawals, the reservation will expire at the date given ReserveWithdrawalAmount { @@ -119,14 +133,116 @@ impl DriveLowLevelOperationConverter for WithdrawalOperationType { Ok(drive_operations) } - WithdrawalOperationType::DeleteWithdrawalTransaction { index } => { + WithdrawalOperationType::MoveWithdrawalTransactionsToBroadcasted { indexes } => { + let mut drive_operations = vec![]; + + if indexes.is_empty() { + return Ok(drive_operations); + } + + let original_path = get_withdrawal_transactions_queue_path_vec(); + let new_path = get_withdrawal_transactions_broadcasted_path_vec(); + + let mut query = Query::new(); + + let len = indexes.len(); + + query.insert_keys( + indexes + .into_iter() + .map(|index| index.to_be_bytes().to_vec()) + .collect(), + ); + + let path_query = PathQuery::new( + original_path, + SizedQuery::new(query, Some(len as u16), None), + ); + + drive.batch_move_items_in_path_query( + &path_query, + new_path, + true, + // we know that we are not deleting a subtree + BatchMoveApplyType::StatefulBatchMove { + is_known_to_be_subtree_with_sum: Some((false, false)), + }, + transaction, + &mut drive_operations, + &platform_version.drive, + )?; + + Ok(drive_operations) + } + WithdrawalOperationType::MoveBroadcastedWithdrawalTransactionsBackToQueueForResigning { indexes } => { + let mut drive_operations = vec![]; + + if indexes.is_empty() { + return Ok(drive_operations); + } + + let original_path = get_withdrawal_transactions_broadcasted_path_vec(); + let new_path = get_withdrawal_transactions_queue_path_vec(); + + let mut query = Query::new(); + + let len = indexes.len(); + + query.insert_keys( + indexes + .into_iter() + .map(|index| index.to_be_bytes().to_vec()) + .collect(), + ); + + let path_query = PathQuery::new( + original_path, + SizedQuery::new(query, Some(len as u16), None), + ); + + drive.batch_move_items_in_path_query( + &path_query, + new_path, + true, + // we know that we are not deleting a subtree + BatchMoveApplyType::StatefulBatchMove { + is_known_to_be_subtree_with_sum: Some((false, false)), + }, + transaction, + &mut drive_operations, + &platform_version.drive, + )?; + + Ok(drive_operations) + } + WithdrawalOperationType::DeleteCompletedBroadcastedWithdrawalTransactions { indexes } => { let mut drive_operations = vec![]; - let path = get_withdrawal_transactions_queue_path(); + if indexes.is_empty() { + return Ok(drive_operations); + } + + let path = get_withdrawal_transactions_broadcasted_path_vec(); + + let mut query = Query::new(); + + let len = indexes.len(); + + query.insert_keys( + indexes + .into_iter() + .map(|index| index.to_be_bytes().to_vec()) + .collect(), + ); + + let path_query = PathQuery::new( + path, + SizedQuery::new(query, Some(len as u16), None), + ); - drive.batch_delete( - (&path).into(), - &index.to_be_bytes(), + drive.batch_delete_items_in_path_query( + &path_query, + true, // we know that we are not deleting a subtree BatchDeleteApplyType::StatefulBatchDelete { is_known_to_be_subtree_with_sum: Some((false, false)), diff --git a/packages/rs-drive/src/util/grove_operations/batch_move_items_in_path_query/mod.rs b/packages/rs-drive/src/util/grove_operations/batch_move_items_in_path_query/mod.rs new file mode 100644 index 0000000000..ae886e0f54 --- /dev/null +++ b/packages/rs-drive/src/util/grove_operations/batch_move_items_in_path_query/mod.rs @@ -0,0 +1,58 @@ +mod v0; + +use crate::drive::Drive; +use crate::error::drive::DriveError; +use crate::error::Error; +use crate::fees::op::LowLevelDriveOperation; +use crate::util::grove_operations::BatchMoveApplyType; + +use dpp::version::drive_versions::DriveVersion; + +use grovedb::{PathQuery, TransactionArg}; + +impl Drive { + /// Pushes multiple "delete element" and "insert element operations for items in a given path based on a `PathQuery` to `drive_operations`. + /// + /// # Parameters + /// * `path_query`: The path query specifying the items to delete within the path. + /// * `error_if_intermediate_path_tree_not_present`: Tells the function to either error or do nothing if an intermediate tree is not present. + /// * `apply_type`: The apply type for the move operations. + /// * `transaction`: The transaction argument. + /// * `drive_operations`: The vector containing low-level drive operations. + /// * `drive_version`: The drive version to select the correct function version to run. + /// + /// # Returns + /// * `Ok(())` if the operation was successful. + /// * `Err(DriveError::UnknownVersionMismatch)` if the drive version does not match known versions. + pub fn batch_move_items_in_path_query( + &self, + path_query: &PathQuery, + new_path: Vec>, + error_if_intermediate_path_tree_not_present: bool, + apply_type: BatchMoveApplyType, + transaction: TransactionArg, + drive_operations: &mut Vec, + drive_version: &DriveVersion, + ) -> Result<(), Error> { + match drive_version + .grove_methods + .batch + .batch_move_items_in_path_query + { + 0 => self.batch_move_items_in_path_query_v0( + path_query, + new_path, + error_if_intermediate_path_tree_not_present, + apply_type, + transaction, + drive_operations, + drive_version, + ), + version => Err(Error::Drive(DriveError::UnknownVersionMismatch { + method: "batch_move_items_in_path_query".to_string(), + known_versions: vec![0], + received: version, + })), + } + } +} diff --git a/packages/rs-drive/src/util/grove_operations/batch_move_items_in_path_query/v0/mod.rs b/packages/rs-drive/src/util/grove_operations/batch_move_items_in_path_query/v0/mod.rs new file mode 100644 index 0000000000..f8b2b904cc --- /dev/null +++ b/packages/rs-drive/src/util/grove_operations/batch_move_items_in_path_query/v0/mod.rs @@ -0,0 +1,530 @@ +use crate::drive::Drive; +use crate::error::drive::DriveError; +use crate::error::Error; +use crate::fees::op::LowLevelDriveOperation; +use crate::fees::op::LowLevelDriveOperation::GroveOperation; +use crate::util::grove_operations::{push_drive_operation_result, BatchMoveApplyType}; +use grovedb::batch::key_info::KeyInfo; +use grovedb::batch::{KeyInfoPath, QualifiedGroveDbOp}; +use grovedb::operations::delete::DeleteOptions; +use grovedb::query_result_type::QueryResultType; +use grovedb::{GroveDb, PathQuery, TransactionArg}; +use grovedb_storage::rocksdb_storage::RocksDbStorage; +use platform_version::version::drive_versions::DriveVersion; + +impl Drive { + /// Version 0 implementation of the "delete multiple elements" and "insert multiple elements" operation based on a `PathQuery`. + /// Deletes items in the specified path that match the given query. + /// Then inserts those items at the given path. + /// + /// # Parameters + /// * `path_query`: The path query specifying the items to delete within the path. + /// * `error_if_intermediate_path_tree_not_present`: Tells the function to either error or do nothing if an intermediate tree is not present. + /// * `apply_type`: The apply type for the move operations. + /// * `transaction`: The transaction argument. + /// * `drive_operations`: The vector containing low-level drive operations. + /// * `drive_version`: The drive version to select the correct function version to run. + /// + /// # Returns + /// * `Ok(())` if the operation was successful. + /// * `Err(DriveError::CorruptedCodeExecution)` if the operation is not supported. + pub(super) fn batch_move_items_in_path_query_v0( + &self, + path_query: &PathQuery, + new_path: Vec>, + error_if_intermediate_path_tree_not_present: bool, + apply_type: BatchMoveApplyType, + transaction: TransactionArg, + drive_operations: &mut Vec, + drive_version: &DriveVersion, + ) -> Result<(), Error> { + if path_query.query.limit == None { + return Err(Error::Drive(DriveError::NotSupported( + "Limits are required for path_query", + ))); + } + let query_result = if path_query + .query + .query + .items + .iter() + .all(|query_item| query_item.is_key()) + { + // Fetch the elements that match the path query + let query_result = self.grove_get_raw_path_query_with_optional( + path_query, + error_if_intermediate_path_tree_not_present, + transaction, + drive_operations, + drive_version, + )?; + + query_result + .into_iter() + .filter_map(|(path, key, maybe_element)| { + maybe_element.map(|element| (path, key, element)) + }) + .collect() + } else { + self.grove_get_raw_path_query( + path_query, + transaction, + QueryResultType::QueryPathKeyElementTrioResultType, + drive_operations, + drive_version, + )? + .0 + .to_path_key_elements() + }; + + // Iterate over each element and add a delete operation for it + for (path, key, element) in query_result { + let current_batch_operations = + LowLevelDriveOperation::grovedb_operations_batch(drive_operations); + let options = DeleteOptions { + allow_deleting_non_empty_trees: false, + deleting_non_empty_trees_returns_error: true, + base_root_storage_is_free: true, + validate_tree_at_path_exists: false, + }; + let delete_operation = match apply_type { + BatchMoveApplyType::StatelessBatchMove { + is_sum_tree, + estimated_key_size, + estimated_value_size, + .. + } => GroveDb::average_case_delete_operation_for_delete::( + &KeyInfoPath::from_known_owned_path(path.to_vec()), + &KeyInfo::KnownKey(key.to_vec()), + is_sum_tree, + false, + true, + 0, + (estimated_key_size, estimated_value_size), + &drive_version.grove_version, + ) + .map(|r| r.map(Some)), + BatchMoveApplyType::StatefulBatchMove { + is_known_to_be_subtree_with_sum, + } => self.grove.delete_operation_for_delete_internal( + (path.as_slice()).into(), + key.as_slice(), + &options, + is_known_to_be_subtree_with_sum, + ¤t_batch_operations.operations, + transaction, + &drive_version.grove_version, + ), + }; + + if let Some(delete_operation) = + push_drive_operation_result(delete_operation, drive_operations)? + { + // Add the delete operation to the batch of drive operations + drive_operations.push(GroveOperation(delete_operation)); + // Adds the insert operation to the batch of drive operations + drive_operations.push(GroveOperation(QualifiedGroveDbOp::insert_or_replace_op( + new_path.clone(), + key, + element, + ))); + } + } + + Ok(()) + } +} +#[cfg(test)] +mod tests { + use crate::util::grove_operations::QueryType; + use crate::{ + error::Error, util::grove_operations::BatchMoveApplyType, + util::test_helpers::setup::setup_drive, + }; + use assert_matches::assert_matches; + use grovedb::{Element, PathQuery, Query, SizedQuery}; + use grovedb_path::SubtreePath; + use platform_version::version::PlatformVersion; + + #[test] + fn test_batch_move_items_in_path_query_success() { + // Set up a test drive instance and transaction + let drive = setup_drive(None); + let platform_version = PlatformVersion::latest(); + let transaction = drive.grove.start_transaction(); + + // Insert elements that will be moved + let path = vec![b"root".to_vec()]; + let new_path = vec![b"new_root".to_vec()]; + let key1 = b"key1".to_vec(); + let key2 = b"key2".to_vec(); + let element1 = Element::new_item(b"value1".to_vec()); + let element2 = Element::new_item(b"value2".to_vec()); + + // Insert the root tree and new root tree + drive + .grove_insert_empty_tree( + SubtreePath::empty(), + b"root", + Some(&transaction), + None, + &mut vec![], + &platform_version.drive, + ) + .expect("expected to insert root tree"); + + drive + .grove_insert_empty_tree( + SubtreePath::empty(), + b"new_root", + Some(&transaction), + None, + &mut vec![], + &platform_version.drive, + ) + .expect("expected to insert new root tree"); + + drive + .grove + .insert( + path.as_slice(), + &key1, + element1.clone(), + None, + Some(&transaction), + &platform_version.drive.grove_version, + ) + .unwrap() + .expect("expected to insert element1"); + + drive + .grove + .insert( + path.as_slice(), + &key2, + element2.clone(), + None, + Some(&transaction), + &platform_version.drive.grove_version, + ) + .unwrap() + .expect("expected to insert element2"); + + // Create a path query that matches the inserted elements + let mut query = Query::new(); + query.insert_key(key1.clone()); + query.insert_key(key2.clone()); + let path_query = PathQuery::new(path.clone(), SizedQuery::new(query, Some(100), None)); + + // Set up the apply type and drive operations vector + let apply_type = BatchMoveApplyType::StatefulBatchMove { + is_known_to_be_subtree_with_sum: Some((false, false)), + }; + let mut drive_operations = Vec::new(); + + // Call the function + drive + .batch_move_items_in_path_query_v0( + &path_query, + new_path.clone(), + true, + apply_type, + Some(&transaction), + &mut drive_operations, + &platform_version.drive, + ) + .expect("expected to move items"); + + // Apply batch operations + drive + .apply_batch_low_level_drive_operations( + None, + Some(&transaction), + drive_operations, + &mut vec![], + &platform_version.drive, + ) + .expect("expected to apply operations"); + + // Commit the transaction + drive + .grove + .commit_transaction(transaction) + .unwrap() + .expect("expected to commit transaction"); + + // Verify that keys have been moved to the new path + let get_result_1 = drive.grove_get( + new_path.as_slice().into(), + &key1, + QueryType::StatefulQuery, + None, + &mut vec![], + &platform_version.drive, + ); + assert_matches!(get_result_1, Ok(Some(Element::Item(value, _))) if value == b"value1".to_vec()); + + let get_result_2 = drive.grove_get( + new_path.as_slice().into(), + &key2, + QueryType::StatefulQuery, + None, + &mut vec![], + &platform_version.drive, + ); + assert_matches!(get_result_2, Ok(Some(Element::Item(value, _))) if value == b"value2".to_vec()); + + // Verify that keys are no longer in the original path + let get_result_1_old = drive.grove_get( + path.as_slice().into(), + &key1, + QueryType::StatefulQuery, + None, + &mut vec![], + &platform_version.drive, + ); + assert_matches!( + get_result_1_old, + Err(Error::GroveDB(grovedb::Error::PathKeyNotFound(_))) + ); + + let get_result_2_old = drive.grove_get( + path.as_slice().into(), + &key2, + QueryType::StatefulQuery, + None, + &mut vec![], + &platform_version.drive, + ); + assert_matches!( + get_result_2_old, + Err(Error::GroveDB(grovedb::Error::PathKeyNotFound(_))) + ); + } + + #[test] + fn test_batch_move_items_in_path_query_no_elements() { + // Set up a test drive instance and transaction + let drive = setup_drive(None); + let platform_version = PlatformVersion::latest(); + let transaction = drive.grove.start_transaction(); + + // Create the root tree to allow querying it + drive + .grove_insert_empty_tree( + SubtreePath::empty(), + b"root", + Some(&transaction), + None, + &mut vec![], + &platform_version.drive, + ) + .expect("expected to insert root tree"); + + // Create a path query that does not match any elements + let path = vec![b"root".to_vec()]; + let new_path = vec![b"new_root".to_vec()]; + let mut query = Query::new(); + query.insert_key(b"non_existent_key".to_vec()); + let path_query = PathQuery::new(path.clone(), SizedQuery::new(query, Some(1), None)); + + // Set up the apply type and drive operations vector + let apply_type = BatchMoveApplyType::StatefulBatchMove { + is_known_to_be_subtree_with_sum: Some((false, false)), + }; + let mut drive_operations = Vec::new(); + + // Call the function + let result = drive.batch_move_items_in_path_query_v0( + &path_query, + new_path.clone(), + true, + apply_type, + Some(&transaction), + &mut drive_operations, + &platform_version.drive, + ); + + assert!(result.is_ok()); + } + + #[test] + fn test_batch_move_items_in_path_query_range_query() { + // Set up a test drive instance and transaction + let drive = setup_drive(None); + let platform_version = PlatformVersion::latest(); + let transaction = drive.grove.start_transaction(); + + // Insert the root tree + drive + .grove_insert_empty_tree( + SubtreePath::empty(), + b"root", + Some(&transaction), + None, + &mut vec![], + &platform_version.drive, + ) + .expect("expected to insert root tree"); + + // Insert three elements with keys 1, 2, and 3 + let path = vec![b"root".to_vec()]; + let new_path = vec![b"new_root".to_vec()]; + let key1 = b"1".to_vec(); + let key2 = b"2".to_vec(); + let key3 = b"3".to_vec(); + let element = Element::new_item(b"value".to_vec()); + + // Insert the new root tree + drive + .grove_insert_empty_tree( + SubtreePath::empty(), + b"new_root", + Some(&transaction), + None, + &mut vec![], + &platform_version.drive, + ) + .expect("expected to insert new root tree"); + + drive + .grove + .insert( + path.as_slice(), + &key1, + element.clone(), + None, + Some(&transaction), + &platform_version.drive.grove_version, + ) + .unwrap() + .expect("expected insert for key 1"); + + drive + .grove + .insert( + path.as_slice(), + &key2, + element.clone(), + None, + Some(&transaction), + &platform_version.drive.grove_version, + ) + .unwrap() + .expect("expected insert for key 2"); + + drive + .grove + .insert( + path.as_slice(), + &key3, + element.clone(), + None, + Some(&transaction), + &platform_version.drive.grove_version, + ) + .unwrap() + .expect("expected insert for key 3"); + + // Create a range path query that matches keys less than 3 + let mut query = Query::new(); + query.insert_range_to(..b"3".to_vec()); + let path_query = PathQuery::new(path.clone(), SizedQuery::new(query, Some(100), None)); + + // Set up the apply type and drive operations vector + let apply_type = BatchMoveApplyType::StatefulBatchMove { + is_known_to_be_subtree_with_sum: Some((false, false)), + }; + let mut drive_operations = Vec::new(); + + // Call the function + drive + .batch_move_items_in_path_query_v0( + &path_query, + new_path.clone(), + true, + apply_type, + Some(&transaction), + &mut drive_operations, + &platform_version.drive, + ) + .expect("expected to batch move items"); + + // Apply batch operations + drive + .apply_batch_low_level_drive_operations( + None, + Some(&transaction), + drive_operations, + &mut vec![], + &platform_version.drive, + ) + .expect("expected to apply operations"); + + // Commit the transaction + drive + .grove + .commit_transaction(transaction) + .unwrap() + .expect("expected to commit transaction"); + + // Verify that keys 1 and 2 have been moved to the new path + let get_result_1 = drive.grove_get( + new_path.as_slice().into(), + &key1, + QueryType::StatefulQuery, + None, + &mut vec![], + &platform_version.drive, + ); + assert_matches!(get_result_1, Ok(Some(Element::Item(value, _))) if value == b"value".to_vec()); + + let get_result_2 = drive.grove_get( + new_path.as_slice().into(), + &key2, + QueryType::StatefulQuery, + None, + &mut vec![], + &platform_version.drive, + ); + assert_matches!(get_result_2, Ok(Some(Element::Item(value, _))) if value == b"value".to_vec()); + + // Verify that keys 1 and 2 are no longer in the original path + let get_result_1_old = drive.grove_get( + path.as_slice().into(), + &key1, + QueryType::StatefulQuery, + None, + &mut vec![], + &platform_version.drive, + ); + assert_matches!( + get_result_1_old, + Err(Error::GroveDB(grovedb::Error::PathKeyNotFound(_))) + ); + + let get_result_2_old = drive.grove_get( + path.as_slice().into(), + &key2, + QueryType::StatefulQuery, + None, + &mut vec![], + &platform_version.drive, + ); + assert_matches!( + get_result_2_old, + Err(Error::GroveDB(grovedb::Error::PathKeyNotFound(_))) + ); + + // Verify that key 3 is still in the original path + let get_result_3 = drive.grove_get( + path.as_slice().into(), + &key3, + QueryType::StatefulQuery, + None, + &mut vec![], + &platform_version.drive, + ); + assert_matches!(get_result_3, Ok(Some(Element::Item(..)))); + } +} diff --git a/packages/rs-drive/src/util/grove_operations/mod.rs b/packages/rs-drive/src/util/grove_operations/mod.rs index 9861e14648..41736ed442 100644 --- a/packages/rs-drive/src/util/grove_operations/mod.rs +++ b/packages/rs-drive/src/util/grove_operations/mod.rs @@ -126,6 +126,9 @@ pub mod grove_get_proved_path_query_with_conditional; /// Inserts an element if it does not exist and returns the existing element if it does in GroveDB. pub mod grove_insert_if_not_exists_return_existing_element; +/// Moved items that are found in a path query to a new path. +pub mod batch_move_items_in_path_query; + use grovedb_costs::CostContext; use grovedb::EstimatedLayerInformation; @@ -177,7 +180,7 @@ pub enum BatchDeleteApplyType { StatelessBatchDelete { /// Are we deleting in a sum tree is_sum_tree: bool, - /// What is the estimated value size + /// What is the estimated key size estimated_key_size: u32, /// What is the estimated value size estimated_value_size: u32, @@ -189,6 +192,29 @@ pub enum BatchDeleteApplyType { }, } +/// Batch move apply type +#[derive(Debug, Copy, Clone)] +pub enum BatchMoveApplyType { + /// Stateless batch move + StatelessBatchMove { + /// Are we moving from inside a sum tree + in_tree_using_sums: bool, + /// Are we moving a sum tree + is_sum_tree: bool, + /// What is the estimated key size + estimated_key_size: u32, + /// What is the estimated value size + estimated_value_size: u32, + /// The flags length + flags_len: FlagsLen, + }, + /// Stateful batch move + StatefulBatchMove { + /// Are we known to be in a subtree and does this subtree have sums + is_known_to_be_subtree_with_sum: Option<(IsSubTree, IsSumSubTree)>, + }, +} + #[derive(Clone)] /// Batch delete up tree apply type pub enum BatchDeleteUpTreeApplyType { diff --git a/packages/rs-drive/src/util/test_helpers/setup.rs b/packages/rs-drive/src/util/test_helpers/setup.rs index a9e4cb6aad..d80f600def 100644 --- a/packages/rs-drive/src/util/test_helpers/setup.rs +++ b/packages/rs-drive/src/util/test_helpers/setup.rs @@ -46,13 +46,15 @@ pub fn setup_drive(drive_config: Option) -> Drive { #[cfg(feature = "full")] /// Sets up Drive using a temporary directory and the default initial state structure. -pub fn setup_drive_with_initial_state_structure() -> Drive { +pub fn setup_drive_with_initial_state_structure( + specific_platform_version: Option<&PlatformVersion>, +) -> Drive { let drive = setup_drive(Some(DriveConfig { batching_consistency_verification: true, ..Default::default() })); - let platform_version = PlatformVersion::latest(); + let platform_version = specific_platform_version.unwrap_or(PlatformVersion::latest()); drive .create_initial_state_structure(None, platform_version) .expect("should create root tree successfully"); diff --git a/packages/rs-drive/tests/dashpay.rs b/packages/rs-drive/tests/dashpay.rs index f00008712c..1dbc23e8aa 100644 --- a/packages/rs-drive/tests/dashpay.rs +++ b/packages/rs-drive/tests/dashpay.rs @@ -11,7 +11,7 @@ mod contact_request { #[test] fn test_user_id_query() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -47,7 +47,7 @@ mod contact_request { #[test] fn test_user_id_by_created_at_query() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -83,7 +83,7 @@ mod contact_request { #[test] fn test_owner_id_query() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -119,7 +119,7 @@ mod contact_request { #[test] fn test_owner_id_by_created_at_query() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -155,7 +155,7 @@ mod contact_request { #[test] fn test_owner_id_and_to_user_id_query() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); diff --git a/packages/rs-drive/tests/masternode_rewards.rs b/packages/rs-drive/tests/masternode_rewards.rs index 56464bbae5..0c7fc4bbc8 100644 --- a/packages/rs-drive/tests/masternode_rewards.rs +++ b/packages/rs-drive/tests/masternode_rewards.rs @@ -11,7 +11,7 @@ mod reward_share { #[test] fn test_owner_id_query() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -47,7 +47,7 @@ mod reward_share { #[test] fn test_owner_id_and_pay_to_id_query() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); diff --git a/packages/rs-drive/tests/query_tests.rs b/packages/rs-drive/tests/query_tests.rs index 0850fc8d62..e7a880a02c 100644 --- a/packages/rs-drive/tests/query_tests.rs +++ b/packages/rs-drive/tests/query_tests.rs @@ -4804,7 +4804,7 @@ fn test_dpns_query_start_after_with_null_id_desc() { #[cfg(feature = "server")] #[test] fn test_query_a_b_c_d_e_contract() { - let drive: Drive = setup_drive_with_initial_state_structure(); + let drive: Drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); @@ -4919,7 +4919,7 @@ fn test_query_a_b_c_d_e_contract() { #[cfg(feature = "server")] #[test] fn test_query_documents_by_created_at() { - let drive = setup_drive_with_initial_state_structure(); + let drive = setup_drive_with_initial_state_structure(None); let platform_version = PlatformVersion::latest(); diff --git a/packages/rs-platform-version/src/version/drive_abci_versions.rs b/packages/rs-platform-version/src/version/drive_abci_versions.rs index 22905e5ce5..f7d5dda710 100644 --- a/packages/rs-platform-version/src/version/drive_abci_versions.rs +++ b/packages/rs-platform-version/src/version/drive_abci_versions.rs @@ -338,6 +338,7 @@ pub struct DriveAbciIdentityCreditWithdrawalMethodVersions { pub fetch_transactions_block_inclusion_status: FeatureVersion, pub pool_withdrawals_into_transactions_queue: FeatureVersion, pub update_broadcasted_withdrawal_statuses: FeatureVersion, + pub rebroadcast_expired_withdrawal_documents: FeatureVersion, pub append_signatures_and_broadcast_withdrawal_transactions: FeatureVersion, pub cleanup_expired_locks_of_withdrawal_amounts: FeatureVersion, } diff --git a/packages/rs-platform-version/src/version/drive_versions.rs b/packages/rs-platform-version/src/version/drive_versions.rs index c4bb57124c..2deecab9de 100644 --- a/packages/rs-platform-version/src/version/drive_versions.rs +++ b/packages/rs-platform-version/src/version/drive_versions.rs @@ -462,6 +462,7 @@ pub struct DriveGroveBatchMethodVersions { pub batch_replace: FeatureVersion, pub batch_delete: FeatureVersion, pub batch_delete_items_in_path_query: FeatureVersion, + pub batch_move_items_in_path_query: FeatureVersion, pub batch_remove_raw: FeatureVersion, pub batch_delete_up_tree_while_empty: FeatureVersion, pub batch_refresh_reference: FeatureVersion, @@ -590,6 +591,8 @@ pub struct DriveIdentityWithdrawalTransactionIndexMethodVersions { pub struct DriveIdentityWithdrawalTransactionQueueMethodVersions { pub add_enqueue_untied_withdrawal_transaction_operations: FeatureVersion, pub dequeue_untied_withdrawal_transactions: FeatureVersion, + pub remove_broadcasted_withdrawal_transactions_after_completion_operations: FeatureVersion, + pub move_broadcasted_withdrawal_transactions_back_to_queue_operations: FeatureVersion, } #[derive(Clone, Debug, Default)] diff --git a/packages/rs-platform-version/src/version/limits.rs b/packages/rs-platform-version/src/version/limits.rs index ef15539565..4d10e3810d 100644 --- a/packages/rs-platform-version/src/version/limits.rs +++ b/packages/rs-platform-version/src/version/limits.rs @@ -5,5 +5,6 @@ pub struct SystemLimits { pub max_state_transition_size: u64, pub max_transitions_in_documents_batch: u16, pub withdrawal_transactions_per_block_limit: u16, + pub retry_signing_expired_withdrawal_documents_per_block_limit: u16, pub max_withdrawal_amount: u64, } diff --git a/packages/rs-platform-version/src/version/mocks/v2_test.rs b/packages/rs-platform-version/src/version/mocks/v2_test.rs index 813ac270df..1869831859 100644 --- a/packages/rs-platform-version/src/version/mocks/v2_test.rs +++ b/packages/rs-platform-version/src/version/mocks/v2_test.rs @@ -475,6 +475,8 @@ pub const TEST_PLATFORM_V2: PlatformVersion = PlatformVersion { queue: DriveIdentityWithdrawalTransactionQueueMethodVersions { add_enqueue_untied_withdrawal_transaction_operations: 0, dequeue_untied_withdrawal_transactions: 0, + remove_broadcasted_withdrawal_transactions_after_completion_operations: 0, + move_broadcasted_withdrawal_transactions_back_to_queue_operations: 0, }, }, calculate_current_withdrawal_limit: 0, @@ -577,6 +579,7 @@ pub const TEST_PLATFORM_V2: PlatformVersion = PlatformVersion { batch_replace: 0, batch_delete: 0, batch_delete_items_in_path_query: 0, + batch_move_items_in_path_query: 0, batch_remove_raw: 0, batch_delete_up_tree_while_empty: 0, batch_refresh_reference: 0, @@ -674,6 +677,7 @@ pub const TEST_PLATFORM_V2: PlatformVersion = PlatformVersion { fetch_transactions_block_inclusion_status: 0, pool_withdrawals_into_transactions_queue: 0, update_broadcasted_withdrawal_statuses: 0, + rebroadcast_expired_withdrawal_documents: 0, append_signatures_and_broadcast_withdrawal_transactions: 0, cleanup_expired_locks_of_withdrawal_amounts: 0, }, @@ -850,7 +854,7 @@ pub const TEST_PLATFORM_V2: PlatformVersion = PlatformVersion { }, }, withdrawal_constants: DriveAbciWithdrawalConstants { - core_expiration_blocks: 24, + core_expiration_blocks: 48, cleanup_expired_locks_of_withdrawal_amounts_limit: 0, }, query: DriveAbciQueryVersions { @@ -1290,6 +1294,7 @@ pub const TEST_PLATFORM_V2: PlatformVersion = PlatformVersion { max_state_transition_size: 20000, max_transitions_in_documents_batch: 1, withdrawal_transactions_per_block_limit: 4, + retry_signing_expired_withdrawal_documents_per_block_limit: 1, max_withdrawal_amount: 50_000_000_000_000, }, consensus: ConsensusVersions { diff --git a/packages/rs-platform-version/src/version/mocks/v3_test.rs b/packages/rs-platform-version/src/version/mocks/v3_test.rs index a81949c490..9fef855e85 100644 --- a/packages/rs-platform-version/src/version/mocks/v3_test.rs +++ b/packages/rs-platform-version/src/version/mocks/v3_test.rs @@ -475,6 +475,8 @@ pub const TEST_PLATFORM_V3: PlatformVersion = PlatformVersion { queue: DriveIdentityWithdrawalTransactionQueueMethodVersions { add_enqueue_untied_withdrawal_transaction_operations: 0, dequeue_untied_withdrawal_transactions: 0, + remove_broadcasted_withdrawal_transactions_after_completion_operations: 0, + move_broadcasted_withdrawal_transactions_back_to_queue_operations: 0, }, }, calculate_current_withdrawal_limit: 0, @@ -577,6 +579,7 @@ pub const TEST_PLATFORM_V3: PlatformVersion = PlatformVersion { batch_replace: 0, batch_delete: 0, batch_delete_items_in_path_query: 0, + batch_move_items_in_path_query: 0, batch_remove_raw: 0, batch_delete_up_tree_while_empty: 0, batch_refresh_reference: 0, @@ -674,6 +677,7 @@ pub const TEST_PLATFORM_V3: PlatformVersion = PlatformVersion { fetch_transactions_block_inclusion_status: 0, pool_withdrawals_into_transactions_queue: 1, update_broadcasted_withdrawal_statuses: 0, + rebroadcast_expired_withdrawal_documents: 1, append_signatures_and_broadcast_withdrawal_transactions: 0, cleanup_expired_locks_of_withdrawal_amounts: 0, }, @@ -850,7 +854,7 @@ pub const TEST_PLATFORM_V3: PlatformVersion = PlatformVersion { }, }, withdrawal_constants: DriveAbciWithdrawalConstants { - core_expiration_blocks: 24, + core_expiration_blocks: 48, cleanup_expired_locks_of_withdrawal_amounts_limit: 64, }, query: DriveAbciQueryVersions { @@ -1293,6 +1297,7 @@ pub const TEST_PLATFORM_V3: PlatformVersion = PlatformVersion { max_state_transition_size: 20480, //20 KiB max_transitions_in_documents_batch: 1, withdrawal_transactions_per_block_limit: 4, + retry_signing_expired_withdrawal_documents_per_block_limit: 1, max_withdrawal_amount: 50_000_000_000_000, }, consensus: ConsensusVersions { diff --git a/packages/rs-platform-version/src/version/v1.rs b/packages/rs-platform-version/src/version/v1.rs index 9ea4fad720..38200b9a61 100644 --- a/packages/rs-platform-version/src/version/v1.rs +++ b/packages/rs-platform-version/src/version/v1.rs @@ -474,6 +474,8 @@ pub const PLATFORM_V1: PlatformVersion = PlatformVersion { queue: DriveIdentityWithdrawalTransactionQueueMethodVersions { add_enqueue_untied_withdrawal_transaction_operations: 0, dequeue_untied_withdrawal_transactions: 0, + remove_broadcasted_withdrawal_transactions_after_completion_operations: 0, + move_broadcasted_withdrawal_transactions_back_to_queue_operations: 0, }, }, calculate_current_withdrawal_limit: 0, @@ -576,6 +578,7 @@ pub const PLATFORM_V1: PlatformVersion = PlatformVersion { batch_replace: 0, batch_delete: 0, batch_delete_items_in_path_query: 0, + batch_move_items_in_path_query: 0, batch_remove_raw: 0, batch_delete_up_tree_while_empty: 0, batch_refresh_reference: 0, @@ -673,6 +676,7 @@ pub const PLATFORM_V1: PlatformVersion = PlatformVersion { fetch_transactions_block_inclusion_status: 0, pool_withdrawals_into_transactions_queue: 0, update_broadcasted_withdrawal_statuses: 0, + rebroadcast_expired_withdrawal_documents: 0, append_signatures_and_broadcast_withdrawal_transactions: 0, cleanup_expired_locks_of_withdrawal_amounts: 0, }, @@ -849,7 +853,7 @@ pub const PLATFORM_V1: PlatformVersion = PlatformVersion { }, }, withdrawal_constants: DriveAbciWithdrawalConstants { - core_expiration_blocks: 24, + core_expiration_blocks: 48, cleanup_expired_locks_of_withdrawal_amounts_limit: 0, }, query: DriveAbciQueryVersions { @@ -1292,6 +1296,7 @@ pub const PLATFORM_V1: PlatformVersion = PlatformVersion { max_state_transition_size: 20480, //20 KiB max_transitions_in_documents_batch: 1, withdrawal_transactions_per_block_limit: 4, + retry_signing_expired_withdrawal_documents_per_block_limit: 1, max_withdrawal_amount: 50_000_000_000_000, }, consensus: ConsensusVersions { diff --git a/packages/rs-platform-version/src/version/v2.rs b/packages/rs-platform-version/src/version/v2.rs index dc7b10212d..591e17d0c4 100644 --- a/packages/rs-platform-version/src/version/v2.rs +++ b/packages/rs-platform-version/src/version/v2.rs @@ -474,6 +474,8 @@ pub const PLATFORM_V2: PlatformVersion = PlatformVersion { queue: DriveIdentityWithdrawalTransactionQueueMethodVersions { add_enqueue_untied_withdrawal_transaction_operations: 0, dequeue_untied_withdrawal_transactions: 0, + remove_broadcasted_withdrawal_transactions_after_completion_operations: 0, + move_broadcasted_withdrawal_transactions_back_to_queue_operations: 0, }, }, calculate_current_withdrawal_limit: 0, @@ -576,6 +578,7 @@ pub const PLATFORM_V2: PlatformVersion = PlatformVersion { batch_replace: 0, batch_delete: 0, batch_delete_items_in_path_query: 0, + batch_move_items_in_path_query: 0, batch_remove_raw: 0, batch_delete_up_tree_while_empty: 0, batch_refresh_reference: 0, @@ -673,6 +676,7 @@ pub const PLATFORM_V2: PlatformVersion = PlatformVersion { fetch_transactions_block_inclusion_status: 0, pool_withdrawals_into_transactions_queue: 0, update_broadcasted_withdrawal_statuses: 0, + rebroadcast_expired_withdrawal_documents: 0, append_signatures_and_broadcast_withdrawal_transactions: 0, cleanup_expired_locks_of_withdrawal_amounts: 0, }, @@ -849,7 +853,7 @@ pub const PLATFORM_V2: PlatformVersion = PlatformVersion { }, }, withdrawal_constants: DriveAbciWithdrawalConstants { - core_expiration_blocks: 24, + core_expiration_blocks: 48, cleanup_expired_locks_of_withdrawal_amounts_limit: 0, }, query: DriveAbciQueryVersions { @@ -1292,6 +1296,7 @@ pub const PLATFORM_V2: PlatformVersion = PlatformVersion { max_state_transition_size: 20480, //20 KiB max_transitions_in_documents_batch: 1, withdrawal_transactions_per_block_limit: 4, + retry_signing_expired_withdrawal_documents_per_block_limit: 1, max_withdrawal_amount: 50_000_000_000_000, }, consensus: ConsensusVersions { diff --git a/packages/rs-platform-version/src/version/v3.rs b/packages/rs-platform-version/src/version/v3.rs index ba527c98f6..543c759df7 100644 --- a/packages/rs-platform-version/src/version/v3.rs +++ b/packages/rs-platform-version/src/version/v3.rs @@ -481,6 +481,8 @@ pub const PLATFORM_V3: PlatformVersion = PlatformVersion { queue: DriveIdentityWithdrawalTransactionQueueMethodVersions { add_enqueue_untied_withdrawal_transaction_operations: 0, dequeue_untied_withdrawal_transactions: 0, + remove_broadcasted_withdrawal_transactions_after_completion_operations: 0, + move_broadcasted_withdrawal_transactions_back_to_queue_operations: 0, }, }, calculate_current_withdrawal_limit: 0, @@ -583,6 +585,7 @@ pub const PLATFORM_V3: PlatformVersion = PlatformVersion { batch_replace: 0, batch_delete: 0, batch_delete_items_in_path_query: 0, + batch_move_items_in_path_query: 0, batch_remove_raw: 0, batch_delete_up_tree_while_empty: 0, batch_refresh_reference: 0, @@ -680,6 +683,7 @@ pub const PLATFORM_V3: PlatformVersion = PlatformVersion { fetch_transactions_block_inclusion_status: 0, pool_withdrawals_into_transactions_queue: 0, update_broadcasted_withdrawal_statuses: 0, + rebroadcast_expired_withdrawal_documents: 0, append_signatures_and_broadcast_withdrawal_transactions: 0, cleanup_expired_locks_of_withdrawal_amounts: 0, }, @@ -856,7 +860,7 @@ pub const PLATFORM_V3: PlatformVersion = PlatformVersion { }, }, withdrawal_constants: DriveAbciWithdrawalConstants { - core_expiration_blocks: 24, + core_expiration_blocks: 48, cleanup_expired_locks_of_withdrawal_amounts_limit: 0, }, query: DriveAbciQueryVersions { @@ -1299,6 +1303,7 @@ pub const PLATFORM_V3: PlatformVersion = PlatformVersion { max_state_transition_size: 20480, //20 KiB max_transitions_in_documents_batch: 1, withdrawal_transactions_per_block_limit: 4, + retry_signing_expired_withdrawal_documents_per_block_limit: 1, max_withdrawal_amount: 50_000_000_000_000, }, consensus: ConsensusVersions { diff --git a/packages/rs-platform-version/src/version/v4.rs b/packages/rs-platform-version/src/version/v4.rs index 4d05a510c9..8e4d150310 100644 --- a/packages/rs-platform-version/src/version/v4.rs +++ b/packages/rs-platform-version/src/version/v4.rs @@ -476,6 +476,8 @@ pub const PLATFORM_V4: PlatformVersion = PlatformVersion { queue: DriveIdentityWithdrawalTransactionQueueMethodVersions { add_enqueue_untied_withdrawal_transaction_operations: 0, dequeue_untied_withdrawal_transactions: 0, + remove_broadcasted_withdrawal_transactions_after_completion_operations: 0, + move_broadcasted_withdrawal_transactions_back_to_queue_operations: 0, }, }, calculate_current_withdrawal_limit: 0, @@ -578,6 +580,7 @@ pub const PLATFORM_V4: PlatformVersion = PlatformVersion { batch_replace: 0, batch_delete: 0, batch_delete_items_in_path_query: 0, + batch_move_items_in_path_query: 0, batch_remove_raw: 0, batch_delete_up_tree_while_empty: 0, batch_refresh_reference: 0, @@ -675,6 +678,7 @@ pub const PLATFORM_V4: PlatformVersion = PlatformVersion { fetch_transactions_block_inclusion_status: 0, pool_withdrawals_into_transactions_queue: 0, update_broadcasted_withdrawal_statuses: 0, + rebroadcast_expired_withdrawal_documents: 0, append_signatures_and_broadcast_withdrawal_transactions: 0, cleanup_expired_locks_of_withdrawal_amounts: 0, }, @@ -851,7 +855,7 @@ pub const PLATFORM_V4: PlatformVersion = PlatformVersion { }, }, withdrawal_constants: DriveAbciWithdrawalConstants { - core_expiration_blocks: 24, + core_expiration_blocks: 48, cleanup_expired_locks_of_withdrawal_amounts_limit: 64, }, query: DriveAbciQueryVersions { @@ -1294,6 +1298,7 @@ pub const PLATFORM_V4: PlatformVersion = PlatformVersion { max_state_transition_size: 20480, //20 KiB max_transitions_in_documents_batch: 1, withdrawal_transactions_per_block_limit: 4, + retry_signing_expired_withdrawal_documents_per_block_limit: 1, max_withdrawal_amount: 50_000_000_000_000, //500 Dash }, consensus: ConsensusVersions {