Skip to content

Commit

Permalink
Runtimes compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
ntn-x2 committed Jan 16, 2025
1 parent fbf988d commit 7ea029d
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 235 deletions.
4 changes: 1 addition & 3 deletions pallets/did/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use crate::{
DidVerificationKey,
}, mock_utils::{
generate_base_did_creation_details, generate_base_did_details, get_key_agreement_keys, get_service_endpoints,
}, service_endpoints::DidEndpoint, signature::DidSignatureVerify, traits::{DidDeletionHook, DidLifecycleHooks}, AccountIdOf, DidAuthorizedCallOperationOf, DidIdentifierOf, HoldReason
}, service_endpoints::DidEndpoint, signature::DidSignatureVerify, AccountIdOf, DidAuthorizedCallOperationOf, DidIdentifierOf, HoldReason
};

const DEFAULT_ACCOUNT_ID: &str = "tx_submitter";
Expand Down Expand Up @@ -362,7 +362,6 @@ benchmarks! {
Pallet::<T>::try_insert_did(did_subject.clone(), did_details, deposit_owner).expect("DID should be created!");

save_service_endpoints(&did_subject, &service_endpoints);
<<T::DidLifecycleHooks as DidLifecycleHooks<T>>::DeletionHook as DidDeletionHook<T>>::setup(&did_subject);
let origin = RawOrigin::Signed(did_subject.clone());
}: _(origin, c)
verify {
Expand Down Expand Up @@ -400,7 +399,6 @@ benchmarks! {
Pallet::<T>::try_insert_did(did_subject.clone(), did_details.clone(), deposit_owner).expect("DID should be created!");

save_service_endpoints(&did_subject, &service_endpoints);
<<T::DidLifecycleHooks as DidLifecycleHooks<T>>::DeletionHook as DidDeletionHook<T>>::setup(&did_subject);
let origin = RawOrigin::Signed(did_details.deposit.owner);
let subject_clone = did_subject.clone();
}: _(origin, subject_clone, c)
Expand Down
7 changes: 0 additions & 7 deletions pallets/did/src/traits/lifecycle_hooks/deletion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ where
/// error, the consumed weight (less than or equal to `MAX_WEIGHT`) is
/// returned.
fn can_delete(did: &DidIdentifierOf<T>) -> bool;

/// Called when setting up the `delete` extrinsic for benchmarking.
#[cfg(feature = "runtime-benchmarks")]
fn setup(did: &DidIdentifierOf<T>);
}

impl<T> DidDeletionHook<T> for ()
Expand All @@ -40,7 +36,4 @@ where
fn can_delete(_did: &DidIdentifierOf<T>) -> bool {
true
}

#[cfg(feature = "runtime-benchmarks")]
fn setup(_did: &DidIdentifierOf<T>) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,23 @@
// If you feel like getting in touch with us, you can do so at [email protected]

use did::{
traits::deletion::RequireBoth, DeriveDidCallAuthorizationVerificationKeyRelationship,
DeriveDidCallAuthorizationVerificationKeyRelationship,
DeriveDidCallKeyRelationshipResult, DidRawOrigin, DidVerificationKeyRelationship, EnsureDidOrigin,
RelationshipDeriveError,
};
use frame_system::EnsureRoot;
use runtime_common::{
constants, AccountId, DidIdentifier, EnsureNoLinkedAccountDeletionHook, EnsureNoLinkedWeb3NameDeletionHook,
constants,
AccountId, DidIdentifier,
SendDustAndFeesToTreasury,
};
use sp_core::ConstBool;

use crate::{
weights::{self, rocksdb_weights::constants::RocksDbWeight},
weights::{self},
Balances, Migration, Runtime, RuntimeCall, RuntimeEvent, RuntimeHoldReason, RuntimeOrigin,
};

#[cfg(test)]
mod tests;

impl DeriveDidCallAuthorizationVerificationKeyRelationship for RuntimeCall {
fn derive_verification_key_relationship(&self) -> DeriveDidCallKeyRelationshipResult {
/// ensure that all calls have the same VerificationKeyRelationship
Expand Down Expand Up @@ -95,46 +93,34 @@ impl did::traits::DidLifecycleHooks<Runtime> for DidLifecycleHooks {
type DeletionHook = EnsureNoNamesAndNoLinkedAccountsOnDidDeletion;
}

// Read size is given by the `MaxEncodedLen`: https://substrate.stackexchange.com/a/11843/1795.
// Since the trait is not `const`, we have unit tests that make sure the
// `max_encoded_len()` function matches this const.
const WORST_CASE_WEB3_NAME_STORAGE_READ_SIZE: u64 = 33;
/// Ensure there is no Web3Name linked to a DID.
type EnsureNoWeb3NameOnDeletion =
EnsureNoLinkedWeb3NameDeletionHook<{ RocksDbWeight::get().read }, WORST_CASE_WEB3_NAME_STORAGE_READ_SIZE, ()>;
// Read size is given by the `MaxEncodedLen`: https://substrate.stackexchange.com/a/11843/1795.
// Since the trait is not `const`, we have unit tests that make sure the
// `max_encoded_len()` function matches this const.
const WORST_CASE_DOT_NAME_STORAGE_READ_SIZE: u64 = 33;
/// Ensure there is no Dotname linked to a DID.
type EnsureNoDotNameOnDeletion = EnsureNoLinkedWeb3NameDeletionHook<
{ RocksDbWeight::get().read },
WORST_CASE_DOT_NAME_STORAGE_READ_SIZE,
DotNamesDeployment,
>;
/// Ensure there is neither a Web3Name nor a Dotname linked to a DID.
type EnsureNoUsernamesOnDeletion = RequireBoth<EnsureNoWeb3NameOnDeletion, EnsureNoDotNameOnDeletion>;
pub struct EnsureNoNamesAndNoLinkedAccountsOnDidDeletion;

// Read size is given by the `MaxEncodedLen`: https://substrate.stackexchange.com/a/11843/1795.
// Since the trait is not `const`, we have unit tests that make sure the
// `max_encoded_len()` function matches this const.
const WORST_CASE_LINKING_STORAGE_READ_SIZE: u64 = 33;
/// Ensure there is no linked account (for a web3name) to a DID.
type EnsureNoWeb3NameLinkedAccountsOnDeletion =
EnsureNoLinkedAccountDeletionHook<{ RocksDbWeight::get().read }, WORST_CASE_LINKING_STORAGE_READ_SIZE, ()>;
/// Ensure there is no unique linked account (for a dotname) to a DID.
type EnsureNoDotNameLinkedAccountOnDeletion = EnsureNoLinkedWeb3NameDeletionHook<
{ RocksDbWeight::get().read },
WORST_CASE_LINKING_STORAGE_READ_SIZE,
UniqueLinkingDeployment,
>;
/// Ensure there is no account linked for both the DID's Web3Name and DotName.
type EnsureNoLinkedAccountsOnDeletion =
RequireBoth<EnsureNoWeb3NameLinkedAccountsOnDeletion, EnsureNoDotNameLinkedAccountOnDeletion>;
impl did::traits::DidDeletionHook<Runtime> for EnsureNoNamesAndNoLinkedAccountsOnDidDeletion {
fn can_delete(did: &did::DidIdentifierOf<Runtime>) -> bool {
// 1. Check if there's a linked Web3name
if pallet_web3_names::Names::<Runtime>::contains_key(did) {
return false;
}
// 2. Check if there's a linked Dotname
if pallet_web3_names::Names::<Runtime, DotNamesDeployment>::contains_key(did) {
return false;
}
// 3. Check if there's a Web3name linked account
if pallet_did_lookup::ConnectedAccounts::<Runtime>::iter_key_prefix(did)
.next()
.is_some() {
return false;
}
// 4. Check if there's a Dotname linked account
if pallet_did_lookup::ConnectedAccounts::<Runtime, UniqueLinkingDeployment>::iter_key_prefix(did)
.next()
.is_some() {
return false;
}

/// Ensure there is no trace of names nor linked accounts for the DID.
pub type EnsureNoNamesAndNoLinkedAccountsOnDidDeletion =
RequireBoth<EnsureNoUsernamesOnDeletion, EnsureNoLinkedAccountsOnDeletion>;
true
}
}

impl did::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
Expand Down
49 changes: 0 additions & 49 deletions runtimes/peregrine/src/kilt/did/tests/did_hooks.rs

This file was deleted.

19 changes: 0 additions & 19 deletions runtimes/peregrine/src/kilt/did/tests/mod.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,22 @@
// If you feel like getting in touch with us, you can do so at [email protected]

use did::{
traits::deletion::RequireBoth, DeriveDidCallAuthorizationVerificationKeyRelationship,
DeriveDidCallAuthorizationVerificationKeyRelationship,
DeriveDidCallKeyRelationshipResult, DidRawOrigin, DidVerificationKeyRelationship, EnsureDidOrigin,
RelationshipDeriveError,
};
use frame_system::EnsureRoot;
use runtime_common::{
constants, did::EnsureNoLinkedAccountDeletionHook, AccountId, DidIdentifier, EnsureNoLinkedWeb3NameDeletionHook,
SendDustAndFeesToTreasury,
constants,
AccountId, DidIdentifier, SendDustAndFeesToTreasury,
};
use sp_core::ConstBool;

use crate::{
weights::{self, rocksdb_weights::constants::RocksDbWeight},
weights::{self},
Balances, Migration, Runtime, RuntimeCall, RuntimeEvent, RuntimeHoldReason, RuntimeOrigin,
};

#[cfg(test)]
mod tests;

impl DeriveDidCallAuthorizationVerificationKeyRelationship for RuntimeCall {
fn derive_verification_key_relationship(&self) -> DeriveDidCallKeyRelationshipResult {
/// ensure that all calls have the same VerificationKeyRelationship
Expand Down Expand Up @@ -95,46 +92,34 @@ impl did::traits::DidLifecycleHooks<Runtime> for DidLifecycleHooks {
type DeletionHook = EnsureNoNamesAndNoLinkedAccountsOnDidDeletion;
}

// Read size is given by the `MaxEncodedLen`: https://substrate.stackexchange.com/a/11843/1795.
// Since the trait is not `const`, we have unit tests that make sure the
// `max_encoded_len()` function matches this const.
const WORST_CASE_WEB3_NAME_STORAGE_READ_SIZE: u64 = 33;
/// Ensure there is no Web3Name linked to a DID.
type EnsureNoWeb3NameOnDeletion =
EnsureNoLinkedWeb3NameDeletionHook<{ RocksDbWeight::get().read }, WORST_CASE_WEB3_NAME_STORAGE_READ_SIZE, ()>;
// Read size is given by the `MaxEncodedLen`: https://substrate.stackexchange.com/a/11843/1795.
// Since the trait is not `const`, we have unit tests that make sure the
// `max_encoded_len()` function matches this const.
const WORST_CASE_DOT_NAME_STORAGE_READ_SIZE: u64 = 33;
/// Ensure there is no Dotname linked to a DID.
type EnsureNoDotNameOnDeletion = EnsureNoLinkedWeb3NameDeletionHook<
{ RocksDbWeight::get().read },
WORST_CASE_DOT_NAME_STORAGE_READ_SIZE,
DotNamesDeployment,
>;
/// Ensure there is neither a Web3Name nor a Dotname linked to a DID.
type EnsureNoUsernamesOnDeletion = RequireBoth<EnsureNoWeb3NameOnDeletion, EnsureNoDotNameOnDeletion>;
pub struct EnsureNoNamesAndNoLinkedAccountsOnDidDeletion;

// Read size is given by the `MaxEncodedLen`: https://substrate.stackexchange.com/a/11843/1795.
// Since the trait is not `const`, we have unit tests that make sure the
// `max_encoded_len()` function matches this const.
const WORST_CASE_LINKING_STORAGE_READ_SIZE: u64 = 33;
/// Ensure there is no linked account (for a web3name) to a DID.
type EnsureNoWeb3NameLinkedAccountsOnDeletion =
EnsureNoLinkedAccountDeletionHook<{ RocksDbWeight::get().read }, WORST_CASE_LINKING_STORAGE_READ_SIZE, ()>;
/// Ensure there is no unique linked account (for a dotname) to a DID.
type EnsureNoDotNameLinkedAccountOnDeletion = EnsureNoLinkedWeb3NameDeletionHook<
{ RocksDbWeight::get().read },
WORST_CASE_LINKING_STORAGE_READ_SIZE,
UniqueLinkingDeployment,
>;
/// Ensure there is no account linked for both the DID's Web3Name and DotName.
type EnsureNoLinkedAccountsOnDeletion =
RequireBoth<EnsureNoWeb3NameLinkedAccountsOnDeletion, EnsureNoDotNameLinkedAccountOnDeletion>;
impl did::traits::DidDeletionHook<Runtime> for EnsureNoNamesAndNoLinkedAccountsOnDidDeletion {
fn can_delete(did: &did::DidIdentifierOf<Runtime>) -> bool {
// 1. Check if there's a linked Web3name
if pallet_web3_names::Names::<Runtime>::contains_key(did) {
return false;
}
// 2. Check if there's a linked Dotname
if pallet_web3_names::Names::<Runtime, DotNamesDeployment>::contains_key(did) {
return false;
}
// 3. Check if there's a Web3name linked account
if pallet_did_lookup::ConnectedAccounts::<Runtime>::iter_key_prefix(did)
.next()
.is_some() {
return false;
}
// 4. Check if there's a Dotname linked account
if pallet_did_lookup::ConnectedAccounts::<Runtime, UniqueLinkingDeployment>::iter_key_prefix(did)
.next()
.is_some() {
return false;
}

/// Ensure there is no trace of names nor linked accounts for the DID.
pub type EnsureNoNamesAndNoLinkedAccountsOnDidDeletion =
RequireBoth<EnsureNoUsernamesOnDeletion, EnsureNoLinkedAccountsOnDeletion>;
true
}
}

impl did::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
Expand Down
49 changes: 0 additions & 49 deletions runtimes/spiritnet/src/kilt/did/tests/did_hooks.rs

This file was deleted.

19 changes: 0 additions & 19 deletions runtimes/spiritnet/src/kilt/did/tests/mod.rs

This file was deleted.

0 comments on commit 7ea029d

Please sign in to comment.