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

feat(platform)!: identity update can not disable a key it is also adding #1772

Merged
merged 19 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
10 changes: 8 additions & 2 deletions packages/rs-dpp/src/errors/consensus/basic/basic_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ use crate::consensus::basic::document::{
MissingPositionsInDocumentTypePropertiesError,
};
use crate::consensus::basic::identity::{
DataContractBoundsNotPresentError, DuplicatedIdentityPublicKeyBasicError,
DuplicatedIdentityPublicKeyIdBasicError, IdentityAssetLockProofLockedTransactionMismatchError,
DataContractBoundsNotPresentError, DisablingKeyIdAlsoBeingAddedInSameTransitionError,
DuplicatedIdentityPublicKeyBasicError, DuplicatedIdentityPublicKeyIdBasicError,
IdentityAssetLockProofLockedTransactionMismatchError,
IdentityAssetLockTransactionIsNotFoundError,
IdentityAssetLockTransactionOutPointAlreadyExistsError,
IdentityAssetLockTransactionOutputNotFoundError, IdentityCreditTransferToSelfError,
Expand Down Expand Up @@ -219,6 +220,11 @@ pub enum BasicError {
#[error(transparent)]
DuplicatedIdentityPublicKeyIdBasicError(DuplicatedIdentityPublicKeyIdBasicError),

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

#[error(transparent)]
IdentityAssetLockProofLockedTransactionMismatchError(
IdentityAssetLockProofLockedTransactionMismatchError,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use crate::consensus::basic::BasicError;
use crate::consensus::ConsensusError;
use crate::errors::ProtocolError;
use crate::identity::KeyID;
use bincode::{Decode, Encode};
use platform_serialization_derive::{PlatformDeserialize, PlatformSerialize};
use thiserror::Error;

#[derive(
Error, Debug, Clone, PartialEq, Eq, Encode, Decode, PlatformSerialize, PlatformDeserialize,
)]
#[error("Disabling a key with id {key_id:?} that is being added in same state transition")]
#[platform_serialize(unversioned)]
pub struct DisablingKeyIdAlsoBeingAddedInSameTransitionError {
/*

DO NOT CHANGE ORDER OF FIELDS WITHOUT INTRODUCING OF NEW VERSION

*/
key_id: KeyID,
}

impl DisablingKeyIdAlsoBeingAddedInSameTransitionError {
pub fn new(key_id: KeyID) -> Self {
Self { key_id }
}

pub fn key_id(&self) -> KeyID {
self.key_id
}
}
impl From<DisablingKeyIdAlsoBeingAddedInSameTransitionError> for ConsensusError {
fn from(err: DisablingKeyIdAlsoBeingAddedInSameTransitionError) -> Self {
Self::BasicError(BasicError::DisablingKeyIdAlsoBeingAddedInSameTransitionError(err))
}
}
2 changes: 2 additions & 0 deletions packages/rs-dpp/src/errors/consensus/basic/identity/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub use data_contract_bounds_not_present_error::*;
pub use disabling_key_id_also_being_added_in_same_transition_error::*;
pub use duplicated_identity_public_key_basic_error::*;
pub use duplicated_identity_public_key_id_basic_error::*;
pub use identity_asset_lock_proof_locked_transaction_mismatch_error::*;
Expand Down Expand Up @@ -27,6 +28,7 @@ pub use missing_master_public_key_error::*;
pub use not_implemented_identity_credit_withdrawal_transition_pooling_error::*;

mod data_contract_bounds_not_present_error;
mod disabling_key_id_also_being_added_in_same_transition_error;
mod duplicated_identity_public_key_basic_error;
mod duplicated_identity_public_key_id_basic_error;
mod identity_asset_lock_proof_locked_transaction_mismatch_error;
Expand Down
1 change: 1 addition & 0 deletions packages/rs-dpp/src/errors/consensus/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ impl ErrorWithCode for BasicError {
Self::InvalidInstantAssetLockProofSignatureError(_) => 1042,
Self::InvalidIdentityAssetLockProofChainLockValidationError(_) => 1043,
Self::DataContractBoundsNotPresentError(_) => 1066,
Self::DisablingKeyIdAlsoBeingAddedInSameTransitionError(_) => 1096,

Self::MissingMasterPublicKeyError(_) => 1046,
Self::InvalidIdentityPublicKeySecurityLevelError(_) => 1047,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::error::Error;
use dpp::consensus::basic::identity::{
DuplicatedIdentityPublicKeyIdBasicError, InvalidIdentityUpdateTransitionEmptyError,
DisablingKeyIdAlsoBeingAddedInSameTransitionError, DuplicatedIdentityPublicKeyIdBasicError, InvalidIdentityUpdateTransitionEmptyError,
};
use dpp::consensus::state::identity::max_identity_public_key_limit_reached_error::MaxIdentityPublicKeyLimitReachedError;
use dpp::consensus::ConsensusError;
use dpp::state_transition::identity_update_transition::accessors::IdentityUpdateTransitionAccessorsV0;
use dpp::state_transition::identity_update_transition::IdentityUpdateTransition;
use dpp::state_transition::public_key_in_creation::accessors::IdentityPublicKeyInCreationV0Getters;
use dpp::state_transition::public_key_in_creation::IdentityPublicKeyInCreation;
use dpp::validation::SimpleConsensusValidationResult;
use dpp::version::PlatformVersion;
Expand Down Expand Up @@ -58,6 +59,17 @@ impl IdentityUpdateStateTransitionStructureValidationV0 for IdentityUpdateTransi
break;
}

if self
.public_keys_to_add()
.iter()
.any(|public_key_in_creation| public_key_in_creation.id() == *key_id)
{
result.add_error(ConsensusError::from(
DisablingKeyIdAlsoBeingAddedInSameTransitionError::new(*key_id),
));
break;
}

ids.insert(key_id);
}
}
Expand Down
Loading