diff --git a/packages/rs-dpp/schema/meta_schemas/document/v0/document-meta.json b/packages/rs-dpp/schema/meta_schemas/document/v0/document-meta.json index 197a302e665..16e8549915c 100644 --- a/packages/rs-dpp/schema/meta_schemas/document/v0/document-meta.json +++ b/packages/rs-dpp/schema/meta_schemas/document/v0/document-meta.json @@ -480,11 +480,13 @@ "maxLength": 256 } }, + "additionalProperties": false, "required": [ "field", "regexPattern" ] - } + }, + "minItems": 1 }, "resolution": { "type": "integer", @@ -493,7 +495,9 @@ ], "description": "Resolution. 0 - Masternode Vote" } - } + }, + "required": ["resolution"], + "additionalProperties": false } }, "required": [ diff --git a/packages/rs-dpp/src/data_contract/document_type/index_level/mod.rs b/packages/rs-dpp/src/data_contract/document_type/index_level/mod.rs index 409e23281ff..75242ec6af5 100644 --- a/packages/rs-dpp/src/data_contract/document_type/index_level/mod.rs +++ b/packages/rs-dpp/src/data_contract/document_type/index_level/mod.rs @@ -202,50 +202,6 @@ impl IndexLevel { current_level.has_index_with_type = Some(index_type); } } - // - // if let Some(contested_index) = &index.contested_index { - // let mut current_level = &mut index_level; - // let mut properties_iter = index.properties.iter().peekable(); - // - // while let Some(index_part) = properties_iter.next() { - // let level_name = if contested_index.contested_field_name == index_part.name { - // &contested_index.contested_field_temp_replacement_name - // } else { - // &index_part.name - // }; - // current_level = current_level - // .sub_index_levels - // .entry(level_name.clone()) - // .or_insert_with(|| { - // counter += 1; - // IndexLevel { - // level_identifier: counter, - // sub_index_levels: Default::default(), - // has_index_with_type: None, - // } - // }); - // - // // The last property - // if properties_iter.peek().is_none() { - // // This level already has been initialized. - // // It means there are two indices with the same combination of properties. - // - // // We might need to take into account the sorting order when we have it - // if current_level.has_index_with_type.is_some() { - // // an index already exists return error - // return Err(ConsensusError::BasicError( - // BasicError::DuplicateIndexError(DuplicateIndexError::new( - // document_type_name.to_owned(), - // level_name.clone(), - // )), - // ) - // .into()); - // } - // - // current_level.has_index_with_type = Some(ContestedResourceIndex); - // } - // } - // } } Ok(index_level) diff --git a/packages/rs-dpp/src/version/mod.rs b/packages/rs-dpp/src/version/mod.rs index 9bf84a8e804..71347643217 100644 --- a/packages/rs-dpp/src/version/mod.rs +++ b/packages/rs-dpp/src/version/mod.rs @@ -10,7 +10,7 @@ lazy_static! { RwLock::new(None); } -/// Number of vote_choices for a protocol version upgrade. +/// Number of votes for a protocol version upgrade. pub type ProtocolVersionVoteCount = u64; pub trait PlatformVersionCurrentVersion { diff --git a/packages/rs-drive-abci/src/execution/platform_events/voting/check_for_ended_vote_polls/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/voting/check_for_ended_vote_polls/v0/mod.rs index d8f5398f3bb..9f39bb200de 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/voting/check_for_ended_vote_polls/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/voting/check_for_ended_vote_polls/v0/mod.rs @@ -174,7 +174,13 @@ where // We need to clean up the vote polls // This means removing it and also removing all current votes - self.clean_up_after_vote_polls_end(&vote_polls_with_info, transaction, platform_version)?; + if !vote_polls_with_info.is_empty() { + self.clean_up_after_vote_polls_end( + &vote_polls_with_info, + transaction, + platform_version, + )?; + } Ok(()) } diff --git a/packages/rs-drive-abci/src/execution/platform_events/voting/clean_up_after_contested_resources_vote_polls_end/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/voting/clean_up_after_contested_resources_vote_polls_end/v0/mod.rs index 0941f359b27..a7a9521b6ed 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/voting/clean_up_after_contested_resources_vote_polls_end/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/voting/clean_up_after_contested_resources_vote_polls_end/v0/mod.rs @@ -108,13 +108,15 @@ where )?; } - self.drive.apply_batch_low_level_drive_operations( - None, - transaction, - operations, - &mut vec![], - &platform_version.drive, - )?; + if !operations.is_empty() { + self.drive.apply_batch_low_level_drive_operations( + None, + transaction, + operations, + &mut vec![], + &platform_version.drive, + )?; + } Ok(()) } diff --git a/packages/rs-drive-abci/src/execution/platform_events/voting/clean_up_after_vote_polls_end/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/voting/clean_up_after_vote_polls_end/v0/mod.rs index c064112cf49..20f39351ef7 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/voting/clean_up_after_vote_polls_end/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/voting/clean_up_after_vote_polls_end/v0/mod.rs @@ -40,11 +40,15 @@ where } } - // Call the function to clean up contested document resource vote polls - self.clean_up_after_contested_resources_vote_polls_end( - contested_polls, - transaction, - platform_version, - ) + if !contested_polls.is_empty() { + // Call the function to clean up contested document resource vote polls + self.clean_up_after_contested_resources_vote_polls_end( + contested_polls, + transaction, + platform_version, + ) + } else { + Ok(()) + } } } diff --git a/packages/rs-drive-abci/tests/strategy_tests/main.rs b/packages/rs-drive-abci/tests/strategy_tests/main.rs index 89cf24bbafd..e2ac2889854 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/main.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/main.rs @@ -1089,7 +1089,7 @@ mod tests { .unwrap() .unwrap() ), - "437e90db3d155d1a2db90d21c2a1996c02ee1853e1da5a1b6805f6ce5260890a".to_string() + "838bf7225bdd30f5ac86d876f879b5e6721d594a9072560b27b9e33614bf5bf3".to_string() ) } @@ -1779,7 +1779,7 @@ mod tests { .unwrap() .unwrap() ), - "8bb1546dba61beb571cd289b2f4e872900776d2c73fe698d14e8124de6bf9e57".to_string() + "6e158be6c6752fc5afe2b840627c5a025eaebf10ff4fa1e1a9694ad451e60f99".to_string() ) } @@ -1904,7 +1904,7 @@ mod tests { .unwrap() .unwrap() ), - "3e0e25e19ab7f517d0256e53b85bdfecdc1614014fc0ef02b4698c270a47442a".to_string() + "67abea32d6a5c6d39b7d1fb2a2bc58c8d95c32458923669913bcba6b30ab9ae3".to_string() ) } diff --git a/packages/rs-drive-abci/tests/strategy_tests/voting_tests.rs b/packages/rs-drive-abci/tests/strategy_tests/voting_tests.rs index 996416e39ec..482ed23a994 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/voting_tests.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/voting_tests.rs @@ -281,101 +281,44 @@ mod tests { let second_contender = contenders.last().unwrap(); - assert_eq!(first_contender.document, None); - - assert_eq!(second_contender.document, None); - - assert_eq!(first_contender.identifier, identity2_id.to_vec()); - - assert_eq!(second_contender.identifier, identity1_id.to_vec()); - - assert_eq!(first_contender.vote_count, Some(50)); - - assert_eq!(second_contender.vote_count, Some(3)); - - let GetContestedResourceVoteStateResponse { version } = platform - .query_contested_resource_vote_state( - GetContestedResourceVoteStateRequest { - version: Some(get_contested_resource_vote_state_request::Version::V0( - GetContestedResourceVoteStateRequestV0 { - contract_id: dpns_contract.id().to_vec(), - document_type_name: document_type.name().clone(), - index_name: "parentNameAndLabel".to_string(), - index_values: vec![dash_encoded, quantum_encoded], - result_type: ResultType::DocumentsAndVoteTally as i32, - allow_include_locked_and_abstaining_vote_tally: true, - start_at_identifier_info: None, - count: None, - prove: true, - }, - )), - }, - &platform_state, - platform_version, - ) - .expect("expected to execute query") - .into_data() - .expect("expected query to be valid"); - - let get_contested_resource_vote_state_response::Version::V0( - GetContestedResourceVoteStateResponseV0 { - metadata: _, - result, - }, - ) = version.expect("expected a version"); - - let Some(get_contested_resource_vote_state_response_v0::Result::Proof(proof)) = result - else { - panic!("expected contenders") - }; - - let resolved_contested_document_vote_poll_drive_query = - ResolvedContestedDocumentVotePollDriveQuery { - vote_poll: ContestedDocumentResourceVotePollWithContractInfoAllowBorrowed { - contract: DataContractResolvedInfo::BorrowedDataContract(&dpns_contract), - document_type_name: document_type.name().clone(), - index_name: index_name.clone(), - index_values: vec![ - Value::Text("dash".to_string()), - Value::Text("quantum".to_string()), - ], - }, - result_type: DocumentsAndVoteTally, - offset: None, - limit: None, - start_at: None, - allow_include_locked_and_abstaining_vote_tally: true, - }; - - let (root_hash, result) = resolved_contested_document_vote_poll_drive_query - .verify_vote_poll_vote_state_proof(proof.grovedb_proof.as_ref(), platform_version) - .expect("expected to verify proof"); - assert_eq!( - root_hash, - platform_state - .last_committed_block_app_hash() - .expect("expected an app hash") + first_contender.document, + Some(vec![ + 0, 24, 85, 248, 135, 55, 81, 210, 5, 93, 112, 104, 77, 97, 177, 49, 255, 108, 242, + 0, 83, 232, 168, 214, 145, 55, 49, 246, 246, 126, 99, 17, 108, 41, 18, 75, 231, + 232, 111, 151, 233, 89, 137, 74, 103, 169, 204, 7, 140, 62, 1, 6, 212, 191, 207, + 191, 52, 188, 64, 58, 79, 9, 153, 37, 180, 0, 0, 7, 113, 117, 97, 110, 116, 117, + 109, 7, 113, 117, 97, 110, 116, 117, 109, 1, 9, 112, 48, 81, 101, 48, 107, 49, 65, + 122, 4, 100, 97, 115, 104, 48, 165, 41, 91, 32, 215, 12, 4, 215, 10, 9, 207, 71, + 187, 248, 211, 105, 252, 147, 22, 127, 31, 203, 145, 6, 255, 132, 220, 231, 96, 76, + 195, 34, 1, 41, 18, 75, 231, 232, 111, 151, 233, 89, 137, 74, 103, 169, 204, 7, + 140, 62, 1, 6, 212, 191, 207, 191, 52, 188, 64, 58, 79, 9, 153, 37, 180, 0, 1, 0 + ]) ); - assert_eq!(result.contenders.len(), 2); - - let first_contender = result.contenders.first().unwrap(); - - let second_contender = result.contenders.last().unwrap(); - - // When something is here - - assert_eq!(first_contender.serialized_document, None); - - assert_eq!(second_contender.serialized_document, None); + assert_eq!( + second_contender.document, + Some(vec![ + 0, 23, 193, 35, 24, 227, 101, 215, 103, 217, 98, 152, 114, 80, 94, 3, 27, 65, 246, + 202, 212, 59, 205, 101, 140, 243, 61, 26, 152, 167, 199, 96, 133, 139, 137, 72, + 166, 128, 21, 1, 187, 224, 67, 30, 61, 153, 77, 207, 113, 207, 90, 42, 9, 57, 254, + 81, 176, 230, 0, 7, 97, 153, 171, 164, 251, 0, 0, 7, 113, 117, 97, 110, 116, 117, + 109, 7, 113, 117, 97, 110, 116, 117, 109, 1, 36, 65, 50, 104, 52, 88, 69, 66, 112, + 116, 74, 101, 99, 48, 101, 98, 87, 53, 67, 52, 89, 106, 72, 119, 82, 81, 48, 51, + 88, 54, 83, 99, 75, 103, 89, 111, 97, 4, 100, 97, 115, 104, 110, 35, 254, 120, 68, + 194, 240, 23, 122, 207, 220, 40, 135, 147, 185, 9, 126, 239, 26, 0, 22, 196, 197, + 243, 182, 218, 58, 240, 230, 102, 185, 157, 34, 1, 139, 137, 72, 166, 128, 21, 1, + 187, 224, 67, 30, 61, 153, 77, 207, 113, 207, 90, 42, 9, 57, 254, 81, 176, 230, 0, + 7, 97, 153, 171, 164, 251, 0, 1, 0 + ]) + ); - assert_eq!(first_contender.identity_id, identity2_id); + assert_eq!(first_contender.identifier, identity2_id.to_vec()); - assert_eq!(second_contender.identity_id, identity1_id); + assert_eq!(second_contender.identifier, identity1_id.to_vec()); - assert_eq!(first_contender.vote_tally, Some(50)); + assert_eq!(first_contender.vote_count, Some(0)); - assert_eq!(second_contender.vote_tally, Some(3)); + assert_eq!(second_contender.vote_count, Some(0)); } } diff --git a/packages/rs-drive-proof-verifier/src/types.rs b/packages/rs-drive-proof-verifier/src/types.rs index 42b60d958ab..f1ea8dbc4c7 100644 --- a/packages/rs-drive-proof-verifier/src/types.rs +++ b/packages/rs-drive-proof-verifier/src/types.rs @@ -89,13 +89,13 @@ pub type ExtendedEpochInfos = RetrievedObjects; /// Results of protocol version upgrade voting. /// -/// Information about the protocol version upgrade states and number of received vote_choices, indexed by protocol version. +/// Information about the protocol version upgrade states and number of received votes, indexed by protocol version. /// Returned by [ProtocolVersionVoteCount::fetch_many()]. /// /// ## Data Structure /// /// * [`ProtocolVersion`] - key determining protocol version -/// * [`ProtocolVersionVoteCount`] - value, number of vote_choices for the protocol version upgrade +/// * [`ProtocolVersionVoteCount`] - value, number of votes for the protocol version upgrade pub type ProtocolVersionUpgrades = RetrievedObjects; /// Vote of a masternode for a protocol version. diff --git a/packages/rs-drive/src/drive/balances/add_to_system_credits/v0/mod.rs b/packages/rs-drive/src/drive/balances/add_to_system_credits/v0/mod.rs index a146ac94b95..cfec772bb09 100644 --- a/packages/rs-drive/src/drive/balances/add_to_system_credits/v0/mod.rs +++ b/packages/rs-drive/src/drive/balances/add_to_system_credits/v0/mod.rs @@ -35,7 +35,7 @@ impl Drive { platform_version, )?; let grove_db_operations = - LowLevelDriveOperation::grovedb_operations_batch(&batch_operations); + LowLevelDriveOperation::grovedb_operations_batch_consume(batch_operations); self.grove_apply_batch_with_add_costs( grove_db_operations, false, diff --git a/packages/rs-drive/src/drive/balances/remove_from_system_credits/v0/mod.rs b/packages/rs-drive/src/drive/balances/remove_from_system_credits/v0/mod.rs index 21d087f8fd7..48c50b8ec6e 100644 --- a/packages/rs-drive/src/drive/balances/remove_from_system_credits/v0/mod.rs +++ b/packages/rs-drive/src/drive/balances/remove_from_system_credits/v0/mod.rs @@ -23,7 +23,7 @@ impl Drive { platform_version, )?; let grove_db_operations = - LowLevelDriveOperation::grovedb_operations_batch(&batch_operations); + LowLevelDriveOperation::grovedb_operations_batch_consume(batch_operations); self.grove_apply_batch_with_add_costs( grove_db_operations, false, diff --git a/packages/rs-drive/src/drive/cache.rs b/packages/rs-drive/src/drive/cache.rs index 5cda6dd0978..936869cf045 100644 --- a/packages/rs-drive/src/drive/cache.rs +++ b/packages/rs-drive/src/drive/cache.rs @@ -16,7 +16,7 @@ pub struct DriveCache { /// Genesis time in ms pub genesis_time_ms: parking_lot::RwLock>, // TODO: Make protocol versions cache thread-safe - /// Lazy loaded counter of vote_choices to upgrade protocol version + /// Lazy loaded counter of votes to upgrade protocol version pub protocol_versions_counter: parking_lot::RwLock, /// Versioned system data contracts pub system_data_contracts: SystemDataContracts, diff --git a/packages/rs-drive/src/drive/grove_operations/grove_apply_batch_with_add_costs/v0/mod.rs b/packages/rs-drive/src/drive/grove_operations/grove_apply_batch_with_add_costs/v0/mod.rs index b6d86527ffe..24c4ca17467 100644 --- a/packages/rs-drive/src/drive/grove_operations/grove_apply_batch_with_add_costs/v0/mod.rs +++ b/packages/rs-drive/src/drive/grove_operations/grove_apply_batch_with_add_costs/v0/mod.rs @@ -22,7 +22,9 @@ impl Drive { drive_operations: &mut Vec, ) -> Result<(), Error> { if ops.is_empty() { - return Err(Error::Drive(DriveError::BatchIsEmpty())); + return Err(Error::Drive(DriveError::BatchIsEmpty( + "batch is empty when trying to apply batch with add costs".to_string(), + ))); } // if ops.operations.len() < 500 { // //no initialization diff --git a/packages/rs-drive/src/drive/grove_operations/grove_apply_partial_batch_with_add_costs/v0/mod.rs b/packages/rs-drive/src/drive/grove_operations/grove_apply_partial_batch_with_add_costs/v0/mod.rs index 55e400c2402..76e99ecb0bb 100644 --- a/packages/rs-drive/src/drive/grove_operations/grove_apply_partial_batch_with_add_costs/v0/mod.rs +++ b/packages/rs-drive/src/drive/grove_operations/grove_apply_partial_batch_with_add_costs/v0/mod.rs @@ -27,7 +27,9 @@ impl Drive { drive_operations: &mut Vec, ) -> Result<(), Error> { if ops.is_empty() { - return Err(Error::Drive(DriveError::BatchIsEmpty())); + return Err(Error::Drive(DriveError::BatchIsEmpty( + "batch is empty when trying to apply partial batch with add costs".to_string(), + ))); } // println!("batch {:#?}", ops); if self.config.batching_consistency_verification { diff --git a/packages/rs-drive/src/drive/mod.rs b/packages/rs-drive/src/drive/mod.rs index 497ecddf2fd..9046bfa0a80 100644 --- a/packages/rs-drive/src/drive/mod.rs +++ b/packages/rs-drive/src/drive/mod.rs @@ -129,7 +129,7 @@ pub enum RootTree { TokenBalances = 16, /// Versions desired by proposers Versions = 120, - /// Registered vote_choices + /// Registered votes Votes = 112, } diff --git a/packages/rs-drive/src/drive/operations/apply_batch_low_level_drive_operations/v0/mod.rs b/packages/rs-drive/src/drive/operations/apply_batch_low_level_drive_operations/v0/mod.rs index 2a9dfae40da..dc6e5f15326 100644 --- a/packages/rs-drive/src/drive/operations/apply_batch_low_level_drive_operations/v0/mod.rs +++ b/packages/rs-drive/src/drive/operations/apply_batch_low_level_drive_operations/v0/mod.rs @@ -19,8 +19,10 @@ impl Drive { drive_operations: &mut Vec, drive_version: &DriveVersion, ) -> Result<(), Error> { - let grove_db_operations = - LowLevelDriveOperation::grovedb_operations_batch(&batch_operations); + let (grove_db_operations, mut other_operations) = + LowLevelDriveOperation::grovedb_operations_batch_consume_with_leftovers( + batch_operations, + ); self.apply_batch_grovedb_operations( estimated_costs_only_with_layer_info, transaction, @@ -28,10 +30,7 @@ impl Drive { drive_operations, drive_version, )?; - batch_operations.into_iter().for_each(|op| match op { - GroveOperation(_) => (), - _ => drive_operations.push(op), - }); + drive_operations.append(&mut other_operations); Ok(()) } } diff --git a/packages/rs-drive/src/drive/prefunded_specialized_balances/add_prefunded_specialized_balance/v0/mod.rs b/packages/rs-drive/src/drive/prefunded_specialized_balances/add_prefunded_specialized_balance/v0/mod.rs index adb8b0ac54d..88a39525fb0 100644 --- a/packages/rs-drive/src/drive/prefunded_specialized_balances/add_prefunded_specialized_balance/v0/mod.rs +++ b/packages/rs-drive/src/drive/prefunded_specialized_balances/add_prefunded_specialized_balance/v0/mod.rs @@ -39,7 +39,7 @@ impl Drive { platform_version, )?; let grove_db_operations = - LowLevelDriveOperation::grovedb_operations_batch(&batch_operations); + LowLevelDriveOperation::grovedb_operations_batch_consume(batch_operations); self.grove_apply_batch_with_add_costs( grove_db_operations, false, diff --git a/packages/rs-drive/src/drive/protocol_upgrade/fetch_proved_validator_version_votes/v0/mod.rs b/packages/rs-drive/src/drive/protocol_upgrade/fetch_proved_validator_version_votes/v0/mod.rs index 2a6449ada36..ab4b2f71863 100644 --- a/packages/rs-drive/src/drive/protocol_upgrade/fetch_proved_validator_version_votes/v0/mod.rs +++ b/packages/rs-drive/src/drive/protocol_upgrade/fetch_proved_validator_version_votes/v0/mod.rs @@ -19,7 +19,7 @@ impl Drive { ) -> Result, Error> { if count == 0 { return Err(Error::Query(QuerySyntaxError::NoQueryItems( - "We did not ask for the vote_choices of any validators", + "We did not ask for the votes of any validators", ))); } let path = desired_version_for_validators_path_vec(); diff --git a/packages/rs-drive/src/drive/protocol_upgrade/fetch_validator_version_votes/mod.rs b/packages/rs-drive/src/drive/protocol_upgrade/fetch_validator_version_votes/mod.rs index 1b0bec6973e..f2bd0b430af 100644 --- a/packages/rs-drive/src/drive/protocol_upgrade/fetch_validator_version_votes/mod.rs +++ b/packages/rs-drive/src/drive/protocol_upgrade/fetch_validator_version_votes/mod.rs @@ -10,18 +10,18 @@ use dpp::util::deserializer::ProtocolVersion; use grovedb::TransactionArg; impl Drive { - /// Fetch validator vote_choices for versions + /// Fetch validator votes for versions /// /// # Arguments /// - /// * `start_protx_hash` - The first identifier to get vote_choices from. If none is set start from the + /// * `start_protx_hash` - The first identifier to get votes from. If none is set start from the /// first item by ordered hash. /// * `count` - How many max items to retrieve. /// * `transaction` - A `TransactionArg` object representing the transaction. /// /// # Returns /// - /// * `Result, Error>` - If successful, returns an `Ok(BTreeMap<[u8;32], ProtocolVersion>)` which contains the versions vote_choices by validators. If an error occurs during the operation, returns an `Error`. + /// * `Result, Error>` - If successful, returns an `Ok(BTreeMap<[u8;32], ProtocolVersion>)` which contains the versions votes by validators. If an error occurs during the operation, returns an `Error`. /// /// # Errors /// diff --git a/packages/rs-drive/src/drive/protocol_upgrade/fetch_validator_version_votes/v0/mod.rs b/packages/rs-drive/src/drive/protocol_upgrade/fetch_validator_version_votes/v0/mod.rs index fadd0e3e41e..b3de7313280 100644 --- a/packages/rs-drive/src/drive/protocol_upgrade/fetch_validator_version_votes/v0/mod.rs +++ b/packages/rs-drive/src/drive/protocol_upgrade/fetch_validator_version_votes/v0/mod.rs @@ -24,7 +24,7 @@ impl Drive { ) -> Result, Error> { if count == 0 { return Err(Error::Query(QuerySyntaxError::NoQueryItems( - "We did not ask for the vote_choices of any validators", + "We did not ask for the votes of any validators", ))); } let path = desired_version_for_validators_path_vec(); diff --git a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identity/mod.rs b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identity/mod.rs index 7c8e5859f97..10c431b5499 100644 --- a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identity/mod.rs +++ b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identity/mod.rs @@ -10,7 +10,7 @@ use dpp::version::PlatformVersion; use grovedb::TransactionArg; impl Drive { - /// We remove vote_choices for an identity when that identity is somehow disabled. Currently there is + /// We remove votes for an identity when that identity is somehow disabled. Currently there is /// no way to "disable" identities except for masternodes being removed from the list pub fn remove_all_votes_given_by_identity( &self, diff --git a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identity/v0/mod.rs b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identity/v0/mod.rs index 93a9a72f821..9512a126ec9 100644 --- a/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identity/v0/mod.rs +++ b/packages/rs-drive/src/drive/votes/cleanup/remove_all_votes_given_by_identity/v0/mod.rs @@ -17,7 +17,7 @@ use grovedb::reference_path::path_from_reference_path_type; use grovedb::{Element, PathQuery, Query, SizedQuery, TransactionArg}; impl Drive { - /// We remove vote_choices for an identity when that identity is somehow disabled. Currently there is + /// We remove votes for an identity when that identity is somehow disabled. Currently there is /// no way to "disable" identities except for masternodes being removed from the list pub(super) fn remove_all_votes_given_by_identity_v0( &self, diff --git a/packages/rs-drive/src/drive/votes/cleanup/remove_specific_votes_given_by_identity/v0/mod.rs b/packages/rs-drive/src/drive/votes/cleanup/remove_specific_votes_given_by_identity/v0/mod.rs index e8f7e27f579..c3f44879457 100644 --- a/packages/rs-drive/src/drive/votes/cleanup/remove_specific_votes_given_by_identity/v0/mod.rs +++ b/packages/rs-drive/src/drive/votes/cleanup/remove_specific_votes_given_by_identity/v0/mod.rs @@ -9,7 +9,7 @@ use dpp::version::PlatformVersion; use grovedb::TransactionArg; impl Drive { - /// We remove vote_choices for an identity when that identity is somehow disabled. Currently there is + /// We remove votes for an identity when that identity is somehow disabled. Currently there is /// no way to "disable" identities except for masternodes being removed from the list pub(super) fn remove_specific_votes_given_by_identity_v0( &self, diff --git a/packages/rs-drive/src/drive/votes/resolved/vote_polls/contested_document_resource_vote_poll/resolve.rs b/packages/rs-drive/src/drive/votes/resolved/vote_polls/contested_document_resource_vote_poll/resolve.rs index f3868b9f2c0..6c6a3b72901 100644 --- a/packages/rs-drive/src/drive/votes/resolved/vote_polls/contested_document_resource_vote_poll/resolve.rs +++ b/packages/rs-drive/src/drive/votes/resolved/vote_polls/contested_document_resource_vote_poll/resolve.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "server")] use crate::drive::contract::DataContractFetchInfo; #[cfg(feature = "server")] use crate::drive::object_size_info::DataContractOwnedResolvedInfo; @@ -19,7 +20,7 @@ use dpp::voting::vote_polls::contested_document_resource_vote_poll::ContestedDoc #[cfg(feature = "server")] use grovedb::TransactionArg; use platform_version::version::PlatformVersion; -#[cfg(feature = "verify")] +#[cfg(any(feature = "server", feature = "verify"))] use std::sync::Arc; /// A trait for resolving information related to a contested document resource vote poll. @@ -98,14 +99,14 @@ pub trait ContestedDocumentResourceVotePollResolver { ) -> Result, Error>; /// Resolve owned into a struct that allows for a borrowed contract - #[cfg(any(feature = "verify", feature = "server"))] + #[cfg(feature = "server")] fn resolve_with_provided_arc_contract_fetch_info( &self, data_contract: Arc, ) -> Result; /// Resolve owned into a struct that allows for a borrowed contract - #[cfg(any(feature = "verify", feature = "server"))] + #[cfg(feature = "server")] fn resolve_owned_with_provided_arc_contract_fetch_info( self, data_contract: Arc, @@ -212,7 +213,7 @@ impl ContestedDocumentResourceVotePollResolver for ContestedDocumentResourceVote ) } - #[cfg(any(feature = "verify", feature = "server"))] + #[cfg(feature = "server")] fn resolve_with_provided_arc_contract_fetch_info( &self, data_contract: Arc, @@ -241,7 +242,7 @@ impl ContestedDocumentResourceVotePollResolver for ContestedDocumentResourceVote }) } - #[cfg(any(feature = "verify", feature = "server"))] + #[cfg(feature = "server")] fn resolve_owned_with_provided_arc_contract_fetch_info( self, data_contract: Arc, diff --git a/packages/rs-drive/src/error/drive.rs b/packages/rs-drive/src/error/drive.rs index 3c3f7ba5088..361f28e5aea 100644 --- a/packages/rs-drive/src/error/drive.rs +++ b/packages/rs-drive/src/error/drive.rs @@ -166,8 +166,8 @@ pub enum DriveError { CorruptedGenesisTimeInvalidItemLength(String), /// Error - #[error("batch is empty")] - BatchIsEmpty(), + #[error("batch is empty: {0}")] + BatchIsEmpty(String), /// Error #[error("unexpected element type: {0}")] diff --git a/packages/rs-drive/src/fee/op.rs b/packages/rs-drive/src/fee/op.rs index 1a13f8ea697..ac2d94315ad 100644 --- a/packages/rs-drive/src/fee/op.rs +++ b/packages/rs-drive/src/fee/op.rs @@ -11,6 +11,7 @@ use grovedb::element::MaxReferenceHop; use grovedb::reference_path::ReferencePathType; use grovedb::{batch::GroveDbOp, Element, ElementFlags}; use grovedb_costs::OperationCost; +use itertools::Itertools; use crate::drive::batch::grovedb_op_batch::GroveDbOpBatchV0Methods; use crate::drive::fee::get_overflow_error; @@ -290,6 +291,36 @@ impl LowLevelDriveOperation { GroveDbOpBatch::from_operations(operations) } + /// Filters the groveDB ops from a list of operations and puts them in a `GroveDbOpBatch`. + pub fn grovedb_operations_batch_consume( + insert_operations: Vec, + ) -> GroveDbOpBatch { + let operations = insert_operations + .into_iter() + .filter_map(|op| match op { + GroveOperation(grovedb_op) => Some(grovedb_op), + _ => None, + }) + .collect(); + GroveDbOpBatch::from_operations(operations) + } + + /// Filters the groveDB ops from a list of operations and puts them in a `GroveDbOpBatch`. + pub fn grovedb_operations_batch_consume_with_leftovers( + insert_operations: Vec, + ) -> (GroveDbOpBatch, Vec) { + let (grove_operations, other_operations): (Vec<_>, Vec<_>) = + insert_operations.into_iter().partition_map(|op| match op { + GroveOperation(grovedb_op) => itertools::Either::Left(grovedb_op), + _ => itertools::Either::Right(op), + }); + + ( + GroveDbOpBatch::from_operations(grove_operations), + other_operations, + ) + } + /// Filters the groveDB ops from a list of operations and collects them in a `Vec`. pub fn grovedb_operations_consume( insert_operations: Vec, diff --git a/packages/rs-drive/src/query/vote_poll_vote_state_query.rs b/packages/rs-drive/src/query/vote_poll_vote_state_query.rs index e8d09f599c0..f3af3c5e96a 100644 --- a/packages/rs-drive/src/query/vote_poll_vote_state_query.rs +++ b/packages/rs-drive/src/query/vote_poll_vote_state_query.rs @@ -12,7 +12,6 @@ use crate::error::Error; use crate::fee::op::LowLevelDriveOperation; #[cfg(feature = "server")] use crate::query::GroveError; -#[cfg(feature = "server")] use dpp::block::block_info::BlockInfo; use dpp::data_contract::DataContract; use dpp::identifier::Identifier; diff --git a/packages/rs-sdk/src/platform/fetch_many.rs b/packages/rs-sdk/src/platform/fetch_many.rs index 34846b52bc8..12e012b7ca1 100644 --- a/packages/rs-sdk/src/platform/fetch_many.rs +++ b/packages/rs-sdk/src/platform/fetch_many.rs @@ -265,7 +265,7 @@ impl FetchMany for ExtendedEpochInfo { type Request = GetEpochsInfoRequest; } -/// Fetch information about number of vote_choices for each protocol version upgrade. +/// Fetch information about number of votes for each protocol version upgrade. /// /// Returns [ProtocolVersionUpgrades](drive_proof_verifier::types::ProtocolVersionUpgrades) /// indexed by [ProtocolVersion](dpp::util::deserializer::ProtocolVersion). diff --git a/packages/rs-sdk/src/platform/types/version_votes.rs b/packages/rs-sdk/src/platform/types/version_votes.rs index 8261e38ca26..651472cb05b 100644 --- a/packages/rs-sdk/src/platform/types/version_votes.rs +++ b/packages/rs-sdk/src/platform/types/version_votes.rs @@ -1,4 +1,4 @@ -//! Helpers for managing platform version vote_choices +//! Helpers for managing platform version votes use crate::platform::fetch_many::FetchMany; use crate::{platform::LimitQuery, Error, Sdk}; @@ -11,14 +11,14 @@ use drive_proof_verifier::types::{MasternodeProtocolVote, MasternodeProtocolVote /// Helper trait for managing MasternodeProtocolVote objects #[async_trait] pub trait MasternodeProtocolVoteEx { - /// Fetch masternode vote_choices for version update from the platform. + /// Fetch masternode votes for version update from the platform. /// /// ## Parameters /// /// - `sdk`: An instance of [Sdk]. - /// - `start_protxhash`: [ProTxHash] of the first masternode to fetch vote_choices for. + /// - `start_protxhash`: [ProTxHash] of the first masternode to fetch votes for. /// Use `None` to start from the beginning. - /// - `limit`: Maximum number of vote_choices to fetch. Defaults to + /// - `limit`: Maximum number of votes to fetch. Defaults to /// [DEFAULT_NODES_VOTING_LIMIT](crate::platform::query::DEFAULT_NODES_VOTING_LIMIT) /// /// ## See also diff --git a/packages/rs-sdk/tests/fetch/protocol_version_vote_count.rs b/packages/rs-sdk/tests/fetch/protocol_version_vote_count.rs index f3af50edad0..2c31ca7c2f4 100644 --- a/packages/rs-sdk/tests/fetch/protocol_version_vote_count.rs +++ b/packages/rs-sdk/tests/fetch/protocol_version_vote_count.rs @@ -12,7 +12,7 @@ async fn test_protocol_version_vote_count() { let votings = ProtocolVersionVoteCount::fetch_many(&sdk, ()) .await - .expect("fetch protocol version vote_choices"); + .expect("fetch protocol version votes"); println!("votings: {:?}", votings); diff --git a/packages/rs-sdk/tests/fetch/protocol_version_votes.rs b/packages/rs-sdk/tests/fetch/protocol_version_votes.rs index e4ac4bea644..558534ebbd4 100644 --- a/packages/rs-sdk/tests/fetch/protocol_version_votes.rs +++ b/packages/rs-sdk/tests/fetch/protocol_version_votes.rs @@ -3,7 +3,7 @@ use dash_sdk::platform::{types::version_votes::MasternodeProtocolVoteEx, FetchMa use dashcore_rpc::dashcore::{hashes::Hash, ProTxHash}; use drive_proof_verifier::types::MasternodeProtocolVote; -/// Given protxhash with only zeros, when I fetch protocol version vote_choices for nodes, I can retrieve them. +/// Given protxhash with only zeros, when I fetch protocol version votes for nodes, I can retrieve them. #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn test_protocol_version_votes_zeros() { setup_logs(); @@ -14,14 +14,14 @@ async fn test_protocol_version_votes_zeros() { let starting_protxhash = ProTxHash::from_slice(&[0u8; 32]).expect("zero protxhash"); let votings = MasternodeProtocolVote::fetch_many(&sdk, starting_protxhash) .await - .expect("fetch protocol version vote_choices by node"); + .expect("fetch protocol version votes by node"); println!("votings: {:?}", votings); assert!(!votings.is_empty()); } -/// Given protxhash with only zeros, when I fetch protocol version vote_choices for nodes, I can retrieve them. +/// Given protxhash with only zeros, when I fetch protocol version votes for nodes, I can retrieve them. #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn test_protocol_version_votes_none() { setup_logs(); @@ -31,14 +31,14 @@ async fn test_protocol_version_votes_none() { let votings = MasternodeProtocolVote::fetch_many(&sdk, None) .await - .expect("fetch protocol version vote_choices by node"); + .expect("fetch protocol version votes by node"); println!("votings: {:?}", votings); assert!(!votings.is_empty()); } -/// Given protxhash with only zeros, when I fetcg protocol version vote_choices for nodes with limit 2, I get exactly 2 items. +/// Given protxhash with only zeros, when I fetcg protocol version votes for nodes with limit 2, I get exactly 2 items. #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn test_protocol_version_votes_limit_2() { setup_logs(); @@ -49,14 +49,14 @@ async fn test_protocol_version_votes_limit_2() { let starting_protxhash = ProTxHash::from_slice(&[0u8; 32]).expect("zero protxhash"); let votings = MasternodeProtocolVote::fetch_many_with_limit(&sdk, starting_protxhash, 2) .await - .expect("fetch protocol version vote_choices by node"); + .expect("fetch protocol version votes by node"); println!("votings: {:?}", votings); assert!(votings.len() == 2); } -/// Given protxhash with only `0xFF`s, when I fetch protocol version vote_choices for nodes, I get nothing. +/// Given protxhash with only `0xFF`s, when I fetch protocol version votes for nodes, I get nothing. #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn test_protocol_version_votes_nx() { setup_logs(); @@ -67,14 +67,14 @@ async fn test_protocol_version_votes_nx() { let starting_protxhash = Some(ProTxHash::from_slice(&[0xffu8; 32]).expect("zero protxhash")); let votings = MasternodeProtocolVote::fetch_votes(&sdk, starting_protxhash, Some(2)) .await - .expect("fetch protocol version vote_choices by node"); + .expect("fetch protocol version votes by node"); println!("votings: {:?}", votings); assert!(votings.is_empty()); } -/// Given None as a protxhash, when I fetch protocol version vote_choices for 0 nodes, I get error. +/// Given None as a protxhash, when I fetch protocol version votes for 0 nodes, I get error. #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn test_protocol_version_votes_limit_0() { setup_logs();