Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/contestedDocumentResolution…
Browse files Browse the repository at this point in the history
…WithMasternodeVoting' into feat/contestedDocumentResolutionWithMasternodeVoting
  • Loading branch information
shumkov committed Jun 11, 2024
2 parents f6b572f + 2d30333 commit fbbc8da
Show file tree
Hide file tree
Showing 31 changed files with 148 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,13 @@
"maxLength": 256
}
},
"additionalProperties": false,
"required": [
"field",
"regexPattern"
]
}
},
"minItems": 1
},
"resolution": {
"type": "integer",
Expand All @@ -493,7 +495,9 @@
],
"description": "Resolution. 0 - Masternode Vote"
}
}
},
"required": ["resolution"],
"additionalProperties": false
}
},
"required": [
Expand Down
44 changes: 0 additions & 44 deletions packages/rs-dpp/src/data_contract/document_type/index_level/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-dpp/src/version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
}
6 changes: 3 additions & 3 deletions packages/rs-drive-abci/tests/strategy_tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ mod tests {
.unwrap()
.unwrap()
),
"437e90db3d155d1a2db90d21c2a1996c02ee1853e1da5a1b6805f6ce5260890a".to_string()
"838bf7225bdd30f5ac86d876f879b5e6721d594a9072560b27b9e33614bf5bf3".to_string()
)
}

Expand Down Expand Up @@ -1779,7 +1779,7 @@ mod tests {
.unwrap()
.unwrap()
),
"8bb1546dba61beb571cd289b2f4e872900776d2c73fe698d14e8124de6bf9e57".to_string()
"6e158be6c6752fc5afe2b840627c5a025eaebf10ff4fa1e1a9694ad451e60f99".to_string()
)
}

Expand Down Expand Up @@ -1904,7 +1904,7 @@ mod tests {
.unwrap()
.unwrap()
),
"3e0e25e19ab7f517d0256e53b85bdfecdc1614014fc0ef02b4698c270a47442a".to_string()
"67abea32d6a5c6d39b7d1fb2a2bc58c8d95c32458923669913bcba6b30ab9ae3".to_string()
)
}

Expand Down
121 changes: 32 additions & 89 deletions packages/rs-drive-abci/tests/strategy_tests/voting_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
4 changes: 2 additions & 2 deletions packages/rs-drive-proof-verifier/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ pub type ExtendedEpochInfos = RetrievedObjects<EpochIndex, ExtendedEpochInfo>;

/// 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<ProtocolVersion, ProtocolVersionVoteCount>;

/// Vote of a masternode for a protocol version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-drive/src/drive/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct DriveCache {
/// Genesis time in ms
pub genesis_time_ms: parking_lot::RwLock<Option<TimestampMillis>>,
// 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<ProtocolVersionsCache>,
/// Versioned system data contracts
pub system_data_contracts: SystemDataContracts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ impl Drive {
drive_operations: &mut Vec<LowLevelDriveOperation>,
) -> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ impl Drive {
drive_operations: &mut Vec<LowLevelDriveOperation>,
) -> 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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-drive/src/drive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub enum RootTree {
TokenBalances = 16,
/// Versions desired by proposers
Versions = 120,
/// Registered vote_choices
/// Registered votes
Votes = 112,
}

Expand Down
Loading

0 comments on commit fbbc8da

Please sign in to comment.