Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(drive-abci)!: masternode identities unique keys #1459

Merged
merged 5 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/rs-drive-abci/src/execution/check_tx/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ mod tests {
.drive
.add_new_identity(
identity,
false,
&BlockInfo::default(),
true,
None,
Expand Down Expand Up @@ -296,6 +297,7 @@ mod tests {
.drive
.add_new_identity(
identity,
false,
&BlockInfo::default(),
true,
None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,17 @@ where

drive_operations.push(IdentityOperation(AddNewIdentity {
identity: owner_identity,
is_masternode_identity: true,
}));

drive_operations.push(IdentityOperation(AddNewIdentity {
identity: voter_identity,
is_masternode_identity: true,
}));

drive_operations.push(IdentityOperation(AddNewIdentity {
identity: operator_identity,
is_masternode_identity: true,
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ where
new_platform_node_id,
platform_version,
)?);
drive_operations.push(IdentityOperation(AddNewIdentity { identity }));
drive_operations.push(IdentityOperation(AddNewIdentity {
identity,
is_masternode_identity: true,
}));
}
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ where
// other is that the
drive_operations.push(IdentityOperation(AddNewIdentity {
identity: new_voter_identity,
is_masternode_identity: true,
}));
}
Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ impl<C> Platform<C> {
operations: &mut Vec<DriveOperation>,
) {
operations.push(DriveOperation::IdentityOperation(
IdentityOperationType::AddNewIdentity { identity },
IdentityOperationType::AddNewIdentity {
identity,
is_masternode_identity: false,
},
))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
///! The `dashpay_data_triggers` module contains data triggers specific to the DashPay data contract.

Check warning on line 1 in packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/documents_batch/data_triggers/triggers/dashpay/v0/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this is an outer doc comment and does not apply to the parent module or crate

warning: this is an outer doc comment and does not apply to the parent module or crate --> packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/documents_batch/data_triggers/triggers/dashpay/v0/mod.rs:1:1 | 1 | ///! The `dashpay_data_triggers` module contains data triggers specific to the DashPay data contract. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_doc_comments help: use an inner doc comment to document the parent module or crate | 1 | //! The `dashpay_data_triggers` module contains data triggers specific to the DashPay data contract. |
use crate::error::execution::ExecutionError;
use crate::error::Error;
use crate::platform_types::platform_state::v0::PlatformStateV0Methods;
Expand Down Expand Up @@ -284,6 +284,7 @@
.drive
.add_new_identity(
identity_fixture,
false,
&BlockInfo::default(),
true,
None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
///! The `reward_share_data_triggers` module contains data triggers related to reward sharing.

Check warning on line 1 in packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/documents_batch/data_triggers/triggers/reward_share/v0/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this is an outer doc comment and does not apply to the parent module or crate

warning: this is an outer doc comment and does not apply to the parent module or crate --> packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/documents_batch/data_triggers/triggers/reward_share/v0/mod.rs:1:1 | 1 | ///! The `reward_share_data_triggers` module contains data triggers related to reward sharing. | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_doc_comments help: use an inner doc comment to document the parent module or crate | 1 | //! The `reward_share_data_triggers` module contains data triggers related to reward sharing. |
use dpp::platform_value::btreemap_extensions::BTreeValueMapHelper;
use dpp::platform_value::Value;

Expand Down Expand Up @@ -379,6 +379,7 @@
.drive
.add_new_identity(
identity,
false,
&BlockInfo::default(),
true,
None,
Expand All @@ -399,6 +400,7 @@
.drive
.add_new_identity(
identity,
false,
&BlockInfo::default(),
true,
None,
Expand Down Expand Up @@ -597,6 +599,7 @@
.drive
.add_new_identity(
identity,
false,
&BlockInfo::default(),
true,
None,
Expand Down Expand Up @@ -677,6 +680,7 @@
.drive
.add_new_identity(
main_identity,
false,
&BlockInfo::default(),
true,
None,
Expand Down Expand Up @@ -704,6 +708,7 @@
.drive
.add_new_identity(
identity,
false,
&BlockInfo::default(),
true,
None,
Expand Down
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 @@ -405,7 +405,7 @@ mod tests {
.expect("expected to fetch balances")
.expect("expected to have an identity to get balance from");

assert_eq!(balance, 99865284600)
assert_eq!(balance, 99868433120)
}

#[test]
Expand Down Expand Up @@ -948,7 +948,7 @@ mod tests {
.unwrap()
.unwrap()
),
"c7f24ca8edbf2093b4ee2522cf9503f5d7e8fc7cbc5f414af743d9c606407356".to_string()
"1409ab0c04a73430c1c88cd21b34cc61b51483944cfa2b17ed76a7fc23f08027".to_string()
)
}

Expand Down Expand Up @@ -1520,7 +1520,7 @@ mod tests {
.unwrap()
.unwrap()
),
"413aabf2842e9a057e7420d1f3449c6dd899e07e7a30d5533c423971af185d10".to_string()
"5fbeeffc449c8cea80095ced4debc4b33f2246bfc108c567d07b1a45747fd8df".to_string()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,15 @@ pub(crate) fn verify_state_transitions_were_or_were_not_executed(
DocumentTransitionAction::CreateAction(creation_action) => {
if *was_executed {
let document = document.expect("expected a document");
dbg!(
&document,
Document::try_from_create_transition(
creation_action,
documents_batch_transition.owner_id(),
platform_version,
)
.expect("expected to get document")
);
// dbg!(
// &document,
// Document::try_from_create_transition(
// creation_action,
// documents_batch_transition.owner_id(),
// platform_version,
// )
// .expect("expected to get document")
// );
assert_eq!(
document,
Document::try_from_create_transition(
Expand Down
1 change: 1 addition & 0 deletions packages/rs-drive/src/common/identities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pub fn create_test_identity_with_rng(
drive
.add_new_identity(
identity.clone(),
false,
&BlockInfo::default(),
true,
transaction,
Expand Down
27 changes: 18 additions & 9 deletions packages/rs-drive/src/drive/batch/drive_op_batch/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ use std::collections::HashMap;
#[derive(Clone, Debug)]
pub enum IdentityOperationType {
/// Inserts a new identity to the `Identities` subtree.
/// A masternode identity is an identity, but can not have unique keys.
/// It also will skip testing for unique keys when adding non unique keys, so no one will
/// take a key, then add it to a masternode
AddNewIdentity {
/// The identity we wish to insert
identity: Identity,
/// Is this identity a masternode identity
/// On Masternode identities we do not add lookup key hashes
is_masternode_identity: bool,
},
/// Adds balance to an identity
AddToIdentityBalance {
Expand Down Expand Up @@ -84,15 +90,18 @@ impl DriveLowLevelOperationConverter for IdentityOperationType {
) -> Result<Vec<LowLevelDriveOperation>, Error> {
let _drive_version = &platform_version.drive;
match self {
IdentityOperationType::AddNewIdentity { identity } => drive
.add_new_identity_operations(
identity,
block_info,
&mut None,
estimated_costs_only_with_layer_info,
transaction,
platform_version,
),
IdentityOperationType::AddNewIdentity {
identity,
is_masternode_identity,
} => drive.add_new_identity_operations(
identity,
is_masternode_identity,
block_info,
&mut None,
estimated_costs_only_with_layer_info,
transaction,
platform_version,
),
IdentityOperationType::AddToIdentityBalance {
identity_id,
added_balance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ impl DriveHighLevelOperationConverter for IdentityCreateTransitionAction {
Identity::try_from_identity_create_transition_action(self, platform_version)?;

let drive_operations = vec![
IdentityOperation(IdentityOperationType::AddNewIdentity { identity }),
IdentityOperation(IdentityOperationType::AddNewIdentity {
identity,
is_masternode_identity: false,
}),
SystemOperation(SystemOperationType::AddToSystemCredits {
amount: initial_balance_amount,
}),
Expand Down
2 changes: 2 additions & 0 deletions packages/rs-drive/src/drive/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ mod tests {
drive
.add_new_identity(
identity.clone(),
false,
&BlockInfo::default(),
true,
Some(&db_transaction),
Expand Down Expand Up @@ -440,6 +441,7 @@ mod tests {
drive
.add_new_identity(
identity.clone(),
false,
&BlockInfo::default(),
true,
Some(&db_transaction),
Expand Down
2 changes: 2 additions & 0 deletions packages/rs-drive/src/drive/identity/balance/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ mod tests {
drive
.add_new_identity(
identity.clone(),
false,
&BlockInfo::default(),
true,
None,
Expand Down Expand Up @@ -127,6 +128,7 @@ mod tests {
drive
.add_new_identity(
identity.clone(),
false,
&BlockInfo::default(),
true,
None,
Expand Down
18 changes: 16 additions & 2 deletions packages/rs-drive/src/drive/identity/balance/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ mod tests {
let block_info = BlockInfo::default_with_epoch(Epoch::new(0).unwrap());

drive
.add_new_identity(identity.clone(), &block_info, true, None, platform_version)
.add_new_identity(
identity.clone(),
false,
&block_info,
true,
None,
platform_version,
)
.expect("expected to insert identity");

let db_transaction = drive.grove.start_transaction();
Expand Down Expand Up @@ -342,7 +349,14 @@ mod tests {
let block = BlockInfo::default_with_epoch(Epoch::new(0).unwrap());

drive
.add_new_identity(identity.clone(), &block, true, None, platform_version)
.add_new_identity(
identity.clone(),
false,
&block,
true,
None,
platform_version,
)
.expect("expected to insert identity");

let db_transaction = drive.grove.start_transaction();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
use crate::drive::{identity_tree_path, Drive};
use crate::drive::Drive;

use grovedb::batch::KeyInfoPath;
use grovedb::EstimatedLayerCount::{ApproximateElements, EstimatedLevel, PotentiallyAtMaxElements};
use grovedb::EstimatedLayerCount::ApproximateElements;
use grovedb::EstimatedLayerInformation;
use grovedb::EstimatedLayerSizes::{AllItems, AllReference, AllSubtrees};
use grovedb::EstimatedLayerSizes::AllReference;

use crate::drive::identity::estimation_costs::KEY_REFERENCE_SIZE;
use crate::drive::identity::{
identity_contract_info_group_path_key_purpose_vec, identity_contract_info_group_path_vec,
identity_contract_info_root_path, identity_contract_info_root_path_vec,
};
use crate::drive::identity::identity_contract_info_group_path_key_purpose_vec;
use dpp::identity::Purpose;
use grovedb::EstimatedSumTrees::{NoSumTrees, SomeSumTrees};
use std::collections::HashMap;

impl Drive {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ mod tests {
drive
.add_new_identity(
identity.clone(),
false,
&BlockInfo::default(),
true,
Some(&transaction),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ mod tests {
drive
.add_new_identity(
identity.as_ref().unwrap().clone(),
false,
&BlockInfo::default(),
true,
None,
Expand Down Expand Up @@ -89,6 +90,7 @@ mod tests {
drive
.add_new_identity(
identity.clone(),
false,
&BlockInfo::default(),
true,
None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ mod tests {
drive
.add_new_identity(
identity.as_ref().unwrap().clone(),
false,
&BlockInfo::default(),
true,
None,
Expand Down Expand Up @@ -122,6 +123,7 @@ mod tests {
drive
.add_new_identity(
identity.as_ref().unwrap().clone(),
false,
&BlockInfo::default(),
true,
None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ mod tests {
drive
.add_new_identity(
identity.clone(),
false,
&BlockInfo::default(),
true,
None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ mod tests {
drive
.add_new_identity(
identity.clone(),
false,
&BlockInfo::default(),
true,
None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ mod tests {
drive
.add_new_identity(
identity.clone(),
false,
&BlockInfo::default(),
true,
None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ mod tests {
drive
.add_new_identity(
identity.clone(),
false,
&BlockInfo::default(),
true,
None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ mod tests {
drive
.add_new_identity(
identity.clone(),
false,
&BlockInfo::default(),
true,
None,
Expand Down
Loading
Loading