Skip to content
Closed
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
20 changes: 0 additions & 20 deletions packages/rs-dpp/src/data_contract/group/v0/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::consensus::basic::data_contract::{
GroupExceedsMaxMembersError, GroupMemberHasPowerOfZeroError, GroupMemberHasPowerOverLimitError,
GroupNonUnilateralMemberPowerHasLessThanRequiredPowerError,
GroupTotalPowerLessThanRequiredError,
};
use crate::data_contract::group::accessors::v0::{GroupV0Getters, GroupV0Setters};
Expand Down Expand Up @@ -100,8 +99,6 @@ impl GroupMethodsV0 for GroupV0 {

let mut total_power: GroupMemberPower = 0;

let mut total_power_without_unilateral_members: GroupMemberPower = 0;

// Iterate over members to validate their power and calculate the total power
for (&member, &power) in &self.members {
if power == 0 {
Expand All @@ -123,12 +120,6 @@ impl GroupMethodsV0 for GroupV0 {
total_power = total_power
.checked_add(power)
.ok_or_else(|| ProtocolError::Overflow("Total power overflowed"))?;

if power < self.required_power {
total_power_without_unilateral_members = total_power_without_unilateral_members
.checked_add(power)
.ok_or_else(|| ProtocolError::Overflow("Total power overflowed"))?;
}
}

// Check if the total power meets the required power
Expand All @@ -138,17 +129,6 @@ impl GroupMethodsV0 for GroupV0 {
));
}

// Check if the total power without unilateral members meets the required power
if total_power_without_unilateral_members < self.required_power {
return Ok(SimpleConsensusValidationResult::new_with_error(
GroupNonUnilateralMemberPowerHasLessThanRequiredPowerError::new(
total_power_without_unilateral_members,
self.required_power,
)
.into(),
));
}

// If all validations pass, return an empty validation result
Ok(SimpleConsensusValidationResult::new())
}
Expand Down
13 changes: 4 additions & 9 deletions packages/rs-dpp/src/errors/consensus/basic/basic_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use crate::consensus::basic::data_contract::{
DataContractInvalidIndexDefinitionUpdateError, DataContractTokenConfigurationUpdateError,
DataContractUniqueIndicesChangedError, DuplicateIndexError, DuplicateIndexNameError,
GroupExceedsMaxMembersError, GroupMemberHasPowerOfZeroError, GroupMemberHasPowerOverLimitError,
GroupNonUnilateralMemberPowerHasLessThanRequiredPowerError, GroupPositionDoesNotExistError,
GroupTotalPowerLessThanRequiredError, IncompatibleDataContractSchemaError,
IncompatibleDocumentTypeSchemaError, IncompatibleRe2PatternError, InvalidCompoundIndexError,
InvalidDataContractIdError, InvalidDataContractVersionError, InvalidDocumentTypeNameError,
GroupPositionDoesNotExistError, GroupTotalPowerLessThanRequiredError,
IncompatibleDataContractSchemaError, IncompatibleDocumentTypeSchemaError,
IncompatibleRe2PatternError, InvalidCompoundIndexError, InvalidDataContractIdError,
InvalidDataContractVersionError, InvalidDocumentTypeNameError,
InvalidDocumentTypeRequiredSecurityLevelError, InvalidIndexPropertyTypeError,
InvalidIndexedPropertyConstraintError, InvalidTokenBaseSupplyError,
InvalidTokenDistributionFunctionDivideByZeroError,
Expand Down Expand Up @@ -497,11 +497,6 @@ pub enum BasicError {
#[error(transparent)]
GroupTotalPowerLessThanRequiredError(GroupTotalPowerLessThanRequiredError),

#[error(transparent)]
GroupNonUnilateralMemberPowerHasLessThanRequiredPowerError(
GroupNonUnilateralMemberPowerHasLessThanRequiredPowerError,
),

#[error(transparent)]
MissingDefaultLocalizationError(MissingDefaultLocalizationError),

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ mod duplicate_index_name_error;
mod group_exceeds_max_members_error;
mod group_member_has_power_of_zero_error;
mod group_member_has_power_over_limit_error;
mod group_non_unilateral_member_power_has_less_than_required_power_error;
mod group_position_does_not_exist_error;
mod group_total_power_has_less_than_required_power_error;
mod incompatible_data_contract_schema_error;
Expand Down Expand Up @@ -72,7 +71,6 @@ pub use contested_unique_index_with_unique_index_error::*;
pub use group_exceeds_max_members_error::*;
pub use group_member_has_power_of_zero_error::*;
pub use group_member_has_power_over_limit_error::*;
pub use group_non_unilateral_member_power_has_less_than_required_power_error::*;
pub use group_position_does_not_exist_error::*;
pub use group_total_power_has_less_than_required_power_error::*;
pub use incompatible_document_type_schema_error::*;
Expand Down
1 change: 0 additions & 1 deletion packages/rs-dpp/src/errors/consensus/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ impl ErrorWithCode for BasicError {
Self::GroupPositionDoesNotExistError(_) => 10350,
Self::GroupActionNotAllowedOnTransitionError(_) => 10351,
Self::GroupTotalPowerLessThanRequiredError(_) => 10352,
Self::GroupNonUnilateralMemberPowerHasLessThanRequiredPowerError(_) => 10353,
Self::GroupExceedsMaxMembersError(_) => 10354,
Self::GroupMemberHasPowerOfZeroError(_) => 10355,
Self::GroupMemberHasPowerOverLimitError(_) => 10356,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2315,136 +2315,5 @@ mod tests {
.expect("expected to fetch token balance");
assert_eq!(token_balance, None);
}

#[test]
fn test_dcc_group_with_non_unilateral_member_power_not_reaching_threshold() {
let platform_version = PlatformVersion::latest();
let mut platform = TestPlatformBuilder::new()
.build_with_mock_rpc()
.set_genesis_state();

let platform_state = platform.state.load();

let (identity, signer, key) = setup_identity(&mut platform, 958, dash_to_credits!(0.1));

let (identity_2, _, _) = setup_identity(&mut platform, 234, dash_to_credits!(0.1));

let (identity_3, _, _) = setup_identity(&mut platform, 45, dash_to_credits!(0.1));

let mut data_contract = json_document_to_contract_with_ids(
"tests/supporting_files/contract/basic-token/basic-token.json",
None,
None,
false, //no need to validate the data contracts in tests for drive
platform_version,
)
.expect("expected to get json based contract");

let identity_id = identity.id();

let base_supply_start_amount = 0;

{
let groups = data_contract.groups_mut().expect("expected tokens");
groups.insert(
0,
Group::V0(GroupV0 {
members: [(identity.id(), 1), (identity_2.id(), 1)].into(),
required_power: 2,
}),
);
groups.insert(
1,
Group::V0(GroupV0 {
members: [
(identity.id(), 1),
(identity_3.id(), 5),
(identity_2.id(), 1),
]
.into(),
required_power: 5, // 1 + 1 < 5 so we should error
}),
);
let token_config = data_contract
.tokens_mut()
.expect("expected tokens")
.get_mut(&0)
.expect("expected first token");
token_config.set_main_control_group(Some(1));
token_config.set_base_supply(base_supply_start_amount);
token_config.set_manual_minting_rules(ChangeControlRules::V0(
ChangeControlRulesV0 {
authorized_to_make_change: AuthorizedActionTakers::Group(0),
admin_action_takers: AuthorizedActionTakers::MainGroup,
changing_authorized_action_takers_to_no_one_allowed: false,
changing_admin_action_takers_to_no_one_allowed: false,
self_changing_admin_action_takers_allowed: false,
},
));
}

let data_contract_id = DataContract::generate_data_contract_id_v0(identity_id, 1);

let token_id = calculate_token_id(data_contract_id.as_bytes(), 0);

let data_contract_create_transition =
DataContractCreateTransition::new_from_data_contract(
data_contract,
1,
&identity.into_partial_identity_info(),
key.id(),
&signer,
platform_version,
None,
)
.expect("expect to create documents batch transition");

let data_contract_create_serialized_transition = data_contract_create_transition
.serialize_to_bytes()
.expect("expected documents batch serialized state transition");

let transaction = platform.drive.grove.start_transaction();

let processing_result = platform
.platform
.process_raw_state_transitions(
&vec![data_contract_create_serialized_transition.clone()],
&platform_state,
&BlockInfo::default(),
&transaction,
platform_version,
false,
None,
)
.expect("expected to process state transition");

assert_matches!(
processing_result.execution_results().as_slice(),
[StateTransitionExecutionResult::PaidConsensusError(
ConsensusError::BasicError(
BasicError::GroupNonUnilateralMemberPowerHasLessThanRequiredPowerError(_)
),
_
)]
);

platform
.drive
.grove
.commit_transaction(transaction)
.unwrap()
.expect("expected to commit transaction");

let token_balance = platform
.drive
.fetch_identity_token_balance(
token_id,
identity_id.to_buffer(),
None,
platform_version,
)
.expect("expected to fetch token balance");
assert_eq!(token_balance, None);
}
}
}
9 changes: 1 addition & 8 deletions packages/wasm-dpp/src/errors/consensus/consensus_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use dpp::consensus::state::data_trigger::DataTriggerError::{
DataTriggerConditionError, DataTriggerExecutionError, DataTriggerInvalidResultError,
};
use wasm_bindgen::{JsError, JsValue};
use dpp::consensus::basic::data_contract::{ContestedUniqueIndexOnMutableDocumentTypeError, ContestedUniqueIndexWithUniqueIndexError, DataContractTokenConfigurationUpdateError, GroupExceedsMaxMembersError, GroupMemberHasPowerOfZeroError, GroupMemberHasPowerOverLimitError, GroupNonUnilateralMemberPowerHasLessThanRequiredPowerError, GroupPositionDoesNotExistError, GroupTotalPowerLessThanRequiredError, InvalidDocumentTypeRequiredSecurityLevelError, InvalidTokenBaseSupplyError, InvalidTokenDistributionFunctionDivideByZeroError, InvalidTokenDistributionFunctionIncoherenceError, InvalidTokenDistributionFunctionInvalidParameterError, InvalidTokenDistributionFunctionInvalidParameterTupleError, NonContiguousContractGroupPositionsError, NonContiguousContractTokenPositionsError, TokenPaymentByBurningOnlyAllowedOnInternalTokenError, UnknownDocumentActionTokenEffectError, UnknownDocumentCreationRestrictionModeError, UnknownGasFeesPaidByError, UnknownSecurityLevelError, UnknownStorageKeyRequirementsError, UnknownTradeModeError, UnknownTransferableTypeError};
use dpp::consensus::basic::data_contract::{ContestedUniqueIndexOnMutableDocumentTypeError, ContestedUniqueIndexWithUniqueIndexError, DataContractTokenConfigurationUpdateError, GroupExceedsMaxMembersError, GroupMemberHasPowerOfZeroError, GroupMemberHasPowerOverLimitError, GroupPositionDoesNotExistError, GroupTotalPowerLessThanRequiredError, InvalidDocumentTypeRequiredSecurityLevelError, InvalidTokenBaseSupplyError, InvalidTokenDistributionFunctionDivideByZeroError, InvalidTokenDistributionFunctionIncoherenceError, InvalidTokenDistributionFunctionInvalidParameterError, InvalidTokenDistributionFunctionInvalidParameterTupleError, NonContiguousContractGroupPositionsError, NonContiguousContractTokenPositionsError, TokenPaymentByBurningOnlyAllowedOnInternalTokenError, UnknownDocumentActionTokenEffectError, UnknownDocumentCreationRestrictionModeError, UnknownGasFeesPaidByError, UnknownSecurityLevelError, UnknownStorageKeyRequirementsError, UnknownTradeModeError, UnknownTransferableTypeError};
use dpp::consensus::basic::document::{ContestedDocumentsTemporarilyNotAllowedError, DocumentCreationNotAllowedError, DocumentFieldMaxSizeExceededError, MaxDocumentsTransitionsExceededError, MissingPositionsInDocumentTypePropertiesError};
use dpp::consensus::basic::group::GroupActionNotAllowedOnTransitionError;
use dpp::consensus::basic::identity::{DataContractBoundsNotPresentError, DisablingKeyIdAlsoBeingAddedInSameTransitionError, InvalidIdentityCreditWithdrawalTransitionAmountError, InvalidIdentityUpdateTransitionDisableKeysError, InvalidIdentityUpdateTransitionEmptyError, TooManyMasterPublicKeyError, WithdrawalOutputScriptNotAllowedWhenSigningWithOwnerKeyError};
Expand Down Expand Up @@ -716,13 +716,6 @@ fn from_basic_error(basic_error: &BasicError) -> JsValue {
BasicError::GroupTotalPowerLessThanRequiredError(e) => {
generic_consensus_error!(GroupTotalPowerLessThanRequiredError, e).into()
}
BasicError::GroupNonUnilateralMemberPowerHasLessThanRequiredPowerError(e) => {
generic_consensus_error!(
GroupNonUnilateralMemberPowerHasLessThanRequiredPowerError,
e
)
.into()
}
BasicError::InvalidTokenAmountError(e) => {
generic_consensus_error!(InvalidTokenAmountError, e).into()
}
Expand Down